flutter - 如何将文字摆放整齐?

标签 flutter dart

我是新来的 flutter 。我想在按钮上方设置文本/标签。我在flutter中找不到任何简单的文本或标签小部件。
文本应该很大(图片)并且在屏幕右侧,我想保持按钮的位置。如何用Flutter实现这一目标?
谢谢您的帮助。
enter image description here

 @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Padding(
          padding: const EdgeInsets.only(top: 375.0),
          child: Column(
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {},
                      child: Text("1"),
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {},
                      child: Text("2"),
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {},
                      child: Text("3"),
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {},
                      child: Text("+"),
                    ),
                  ),
                ],
              ),
              SizedBox(
                height: 20,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {},
                      child: Text("4"),
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {},
                      child: Text("5"),
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {},
                      child: Text("6"),
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {},
                      child: Text("-"),
                    ),
                  ),
                ],
              ),
              SizedBox(
                height: 20,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {},
                      child: Text("7"),
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {},
                      child: Text("8"),
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {},
                      child: Text("9"),
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {},
                      child: Text("*"),
                    ),
                  ),
                ],
              ),
              SizedBox(
                height: 20,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  SizedBox(
                    height: 80,
                    width: 290,
                    child: FloatingActionButton.extended(
                      elevation: 0.2,
                      onPressed: () {},
                      label: Text("="),
                      isExtended: true,
                    ),
                  ),
                  SizedBox(
                    height: 100,
                    width: 90,
                    child: FloatingActionButton(
                      elevation: 0.2,
                      onPressed: () {},
                      child: Text("/"),
                    ),
                  )
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

最佳答案

Expanded in flutter
使用扩展:

Expanded(
          child: Align(
            alignment: Alignment.centerRight,
            child: Text(
              "My Text",
              textAlign: TextAlign.right,
              style: TextStyle(fontSize: 68),
            ),
          ),
        ),
完整代码:
      @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Column(
          children: <Widget>[
            SizedBox(height: 24,),
            Expanded(
              child: Align(
                alignment: Alignment.centerRight,
                child: Text(
                  "My Text",
                  textAlign: TextAlign.right,
                  style: TextStyle(fontSize: 68),
                ),
              ),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                SizedBox(
                  height: 100,
                  width: 90,
                  child: FloatingActionButton(
                    elevation: 0.2,
                    onPressed: () {},
                    child: Text("1"),
                  ),
                ),
                SizedBox(
                  height: 100,
                  width: 90,
                  child: FloatingActionButton(
                    elevation: 0.2,
                    onPressed: () {},
                    child: Text("2"),
                  ),
                ),
                SizedBox(
                  height: 100,
                  width: 90,
                  child: FloatingActionButton(
                    elevation: 0.2,
                    onPressed: () {},
                    child: Text("3"),
                  ),
                ),
                SizedBox(
                  height: 100,
                  width: 90,
                  child: FloatingActionButton(
                    elevation: 0.2,
                    onPressed: () {},
                    child: Text("+"),
                  ),
                ),
              ],
            ),
            SizedBox(
              height: 20,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                SizedBox(
                  height: 100,
                  width: 90,
                  child: FloatingActionButton(
                    elevation: 0.2,
                    onPressed: () {},
                    child: Text("4"),
                  ),
                ),
                SizedBox(
                  height: 100,
                  width: 90,
                  child: FloatingActionButton(
                    elevation: 0.2,
                    onPressed: () {},
                    child: Text("5"),
                  ),
                ),
                SizedBox(
                  height: 100,
                  width: 90,
                  child: FloatingActionButton(
                    elevation: 0.2,
                    onPressed: () {},
                    child: Text("6"),
                  ),
                ),
                SizedBox(
                  height: 100,
                  width: 90,
                  child: FloatingActionButton(
                    elevation: 0.2,
                    onPressed: () {},
                    child: Text("-"),
                  ),
                ),
              ],
            ),
            SizedBox(
              height: 20,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                SizedBox(
                  height: 100,
                  width: 90,
                  child: FloatingActionButton(
                    elevation: 0.2,
                    onPressed: () {},
                    child: Text("7"),
                  ),
                ),
                SizedBox(
                  height: 100,
                  width: 90,
                  child: FloatingActionButton(
                    elevation: 0.2,
                    onPressed: () {},
                    child: Text("8"),
                  ),
                ),
                SizedBox(
                  height: 100,
                  width: 90,
                  child: FloatingActionButton(
                    elevation: 0.2,
                    onPressed: () {},
                    child: Text("9"),
                  ),
                ),
                SizedBox(
                  height: 100,
                  width: 90,
                  child: FloatingActionButton(
                    elevation: 0.2,
                    onPressed: () {},
                    child: Text("*"),
                  ),
                ),
              ],
            ),
            SizedBox(
              height: 20,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                SizedBox(
                  height: 80,
                  width: 290,
                  child: FloatingActionButton.extended(
                    elevation: 0.2,
                    onPressed: () {},
                    label: Text("="),
                    isExtended: true,
                  ),
                ),
                SizedBox(
                  height: 100,
                  width: 90,
                  child: FloatingActionButton(
                    elevation: 0.2,
                    onPressed: () {},
                    child: Text("/"),
                  ),
                )
              ],
            ),
          ],
        ),
      ),
    );
  }

关于flutter - 如何将文字摆放整齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64101295/

相关文章:

json - Flutter:JSON数据,列表在列表下

flutter - Dart - 无法从连接流中捕获异常

dart - 是否可以使用.where()将 'assert'类型化?

routing - 如何从 Angular Dart 2 中的子组件导航?

dart - Polymer.dart <property>更改的功能不适用于 map

firebase - Flutter:当 TextView 聚焦时,屏幕键盘不打开

flutter - 我想为我所有的屏幕创建一个固定的 Appbar

java - flutter 错误 : Could not resolve all artifacts for configuration ':image_picker_android:debugUnitTestRuntimeClasspath'

flutter - Flutter:ReorderableListView更改项目宽度,并忽略圆角边框

unit-testing - drone.io headless Dart 测试