TextBaseline's alphabetic and ideographic enums do not work in Flutter

949

Solution 1

Screenshot:

enter image description here


You don't need baseline.

Row(
  mainAxisAlignment: MainAxisAlignment.center,
  crossAxisAlignment: CrossAxisAlignment.end,
  children: <Widget>[
    Text(
      'abcdefg',
      style: TextStyle(fontSize: 50.0, fontWeight: FontWeight.w900),
    ),
    Text(
      'hi',
      style: TextStyle(fontSize: 15.0),
    ),
  ],
)

Solution 2

I don't completely know your problem, but I think your problem's solved by adding the following parameter:

mainAxisSize: MainAxisSize.min,

so we have:

Row(
  mainAxisAlignment: MainAxisAlignment.center,
  crossAxisAlignment: CrossAxisAlignment.baseline,
  mainAxisSize: MainAxisSize.min,
  textBaseline: TextBaseline.ideographic,
  children: <Widget>[
    Text(
      'abcdefg',
      style: TextStyle(
          fontSize: 50.0, fontWeight: FontWeight.w900),
    ),
    Text(
      'hi',
      style: TextStyle(fontSize: 15.0),
    ),
  ],
),
Share:
949
user1506104
Author by

user1506104

Updated on December 21, 2022

Comments

  • user1506104
    user1506104 over 1 year

    I thought I understand how these enums work based on this post. When I tried it using the following code, it does not seem to work.

    Row(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.baseline,
      textBaseline: TextBaseline.ideographic,
      children: <Widget>[
        Text(
          'abcdefg',
          style: TextStyle(
              fontSize: 50.0, fontWeight: FontWeight.w900),
        ),
        Text(
          'hi',
          style: TextStyle(fontSize: 15.0),
        ),
      ],
    ),
    

    However, whatever I choose to use as text baseline (ideographic or aphabetic), the result is always the same:

    enter image description here

    I expect that "hi" aligns to the ideographic baseline of "abcdefg", not to its alphabetic baseline like so:

    enter image description here

    What am I doing wrong?

    EDIT:

    There should be a difference between the two in the context of Row widget. I tried removing the line textBaseline: TextBaseline.ideographic, I got this error:

    'package:flutter/src/widgets/basic.dart': Failed assertion: line 3791 pos 15: 'crossAxisAlignment != CrossAxisAlignment.baseline || textBaseline != null': is not true.
    

    Requiring which baseline to use must be Flutter's way of knowing which baseline to align against.