0

I'm trying to center both texts, and for the T text to take as much height as possible from the parent so the only space remaining will be the container's paddings.

The code:

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(TestApp());
}

class TestApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // Remove status bar
    SystemChrome.setEnabledSystemUIOverlays([]);
    return MaterialApp(
      home: Scaffold(
        body: _body(),
      ),
    );
  }

  Widget _body() => Container(
        width: 200,
        height: 200,
        padding: EdgeInsets.all(16),
        color: Colors.lightBlueAccent,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Expanded(
              child: Container(
                color: Colors.lightGreen,
                child: FittedBox(
                  fit: BoxFit.contain,
                  child: Text("T"),
                ),
              ),
            ),
            Flexible(
              child: Text("subtitle"),
            )
          ],
        ),
      );
}

As you can see in the screenshot there are undesired paddings in the T text:

Text Widget undesired paddings

JSB
  • 95
  • 1
  • 8
  • https://stackoverflow.com/questions/57008822/flutter-how-do-i-remove-unwanted-padding-from-text-widget – Fatima ayaa May 18 '21 at 16:46
  • 1
    @Fatimaayaa I've already tried all the answers in there before posting the question, the checked one didn't worked for me since it requires magic numbers and a `Stack` which is not what I want, the custom `BaselineText`widget didn't work either, and the style and containers height try/error don't seem like a nice solution at all, also couldn't make it work in this example with the default font. – JSB May 19 '21 at 07:07

0 Answers0