Under which circumstances textAlign property works in Flutter?

前端 未结 8 1805
花落未央
花落未央 2020-12-07 18:19

In the code below, textAlign property doesn\'t work. If you remove DefaultTextStyle wrapper which is several levels above, textAlign s

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 18:57

    textAlign property only works when there is a more space left for the Text's content. Below are 2 examples which shows when textAlign has impact and when not.


    No impact

    For instance, in this example, it won't have any impact because there is no extra space for the content of the Text.

    Text(
      "Hello",
      textAlign: TextAlign.end, // no impact
    ),
    


    Has impact

    If you wrap it in a Container and provide extra width such that it has more extra space.

    Container(
      width: 200,
      color: Colors.orange,
      child: Text(
        "Hello",
        textAlign: TextAlign.end, // has impact
      ),
    )
    

提交回复
热议问题