flutter - 如何在颤动中定位文本?
问题描述
我是新来的。我想在按钮上方设置一个文本/标签。我没有在颤振中找到任何简单的文本或标签小部件。
文字应该很大(图片)并且在屏幕的右侧,我想保持按钮的位置。如何使用 Flutter 实现这一目标?
感谢您的帮助。
@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(
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("/"),
),
)
],
),
],
),
),
);
}
推荐阅读
- r - 使用 R 中的行名创建公式
- c# - 如何根据条件告诉 JsonWriter 什么都不做?
- python - 如何构建自定义 lxml 解析器?
- ruby-on-rails - 更快地使用数据表和嵌套模型?
- python - Python ElementTree find() 使用命名空间
- android - Metro Bundler 和 Expo 需要证书,两者都出现错误,无法找到请求目标的有效证书路径
- java - 提示 HINT_PASS_DISTINCT_THROUGH 将 PageRequest 的每页返回的实体数量减少到配置的页面大小以下 (PostgreSQL)
- html - 我的 github 页面没有默认加载 index.html
- java - 我正在尝试在 java 中打印一个数组,我需要同时使用 public void intArray() 作为方法
- aem - 响应式网格不起作用 - 预告片组件