【问题标题】:How can we start writing text from center [closed]我们如何从中心开始写文本[关闭]
【发布时间】:2021-05-05 18:24:11
【问题描述】:

我想实现屏幕截图中显示的布局。我的目标是从中心开始写文本。 (一般来说,在颤动中,我们可以从左到右或从右到左书写,我们也可以将文本居中,但是当换行符时,它会从左开始书写,而不是手动将文本居中,我想知道在中心书写的方法,即就像我们在文本居中时输入 MS word)

【问题讨论】:

    标签: flutter dart flutter-layout


    【解决方案1】:

    您需要使用 RichText 小部件。这是一个例子:

    RichText(
    textAlign: TextAlign.center,
      text: TextSpan(
        text:  "By signing up you're agreeing to our\n",
        style: TextStyle(
          color: Colors.black,
        ),
        children: <TextSpan>[
          TextSpan(
            text:'Terms of Service',
            style: TextStyle(
              color: Colors.black,
              decoration: TextDecoration.underline,
            ),
            recognizer: TapGestureRecognizer()
              ..onTap = () {
                showDialog<void>(
                  context: context,
                  builder: (context) {
                    return TermsOfServicePage();
                  },
                );
              },
          ),
          TextSpan(
              text:  '  and  ',
              style: TextStyle(
              )),
          TextSpan(
            text: "Privacy Policy",
            style: TextStyle(
              color: Colors.black,
              decoration: TextDecoration.underline,
            ),
            recognizer: TapGestureRecognizer()
              ..onTap = () {
                showDialog<void>(
                  context: context,
                  builder: (context) {
                    return PrivacyPolicyPage();
                  },
                );
                },
            )
          ],
      ),
      );
    

    【讨论】:

      【解决方案2】:

      您可以创建一个小容器,在该容器内您可以添加一列,在该列中添加一行,在第一行中您可以添加 Text('By signing...'), TextButton('Terms & cond. ..') 你的文本颜色为蓝色,背景颜色为白色,保持最小填充。

      在您的列中添加第二行并执行您在第一行中所做的完全相同的事情

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-02
        • 1970-01-01
        • 2013-05-25
        相关资源
        最近更新 更多