【问题标题】:Align center in flutter在颤动中对齐中心
【发布时间】:2020-12-28 10:48:53
【问题描述】:

我想将文本居中对齐,但如果文本占用两行,则无法正常工作。看图片。白色的文字可以正常工作,但蓝色的文字不起作用。

Container(
        decoration: new BoxDecoration(color: Color(int.parse(bgColor.replaceAll('#', '0xff')))),
        alignment: Alignment.center,
        padding: EdgeInsets.fromLTRB(0, 100, 0, 100),
        child: ParsedText(
        text: text,
        style: part == "big" ? TextStyle(
            fontWeight: FontWeight.bold,
            fontSize: 30,
            color: color
        ):
        TextStyle(
          color: Colors.black
        ),
        parse: <MatchText>[
          MatchText(
            type: ParsedType.URL,
            style: TextStyle(color: Colors.blue,),
            onTap: (url) async{
              url = "http://"+url.replaceAll("https://", "");
              if (await canLaunch(url)) await launch(url);
            }
          )
        ]
    ),
)

【问题讨论】:

  • 如果您使用简单的字符串而不是 ParsedTextMatchedText 等内容,会容易得多。
  • 我必须使用ParsedTextMatchedText 因为我想测试我的文本是否包含用于创建可点击链接的url
  • textAlign: TextAlign.center
  • 我不使用Text() 所以textAlign: TextAlign.center 不起作用
  • 检查下面的答案

标签: flutter


【解决方案1】:

试试这个

ParsedText(
   alignment: TextAlign.center,
   // ...
),

【讨论】:

    猜你喜欢
    • 2019-11-26
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 2022-08-17
    • 2020-03-17
    • 2020-11-22
    • 2022-12-06
    • 1970-01-01
    相关资源
    最近更新 更多