Flutter 当文本使用非默认大小时,浮动按钮中的文本居中 import'包装:flift/cupertino.dart'; 进口“包装:颤振/材料.省道”; 导入“package:font_awesome_flatter/font_awesome_flatter.dart”; 类MainScreen扩展StatefulWidget{ @凌驾 _State createState()=>_State(); } 枚举性别{男性,女性} 类_状态扩展状态{ 性别=性别。男性; 双倍高度=180; int _权重=74; 年龄=25岁; @凌驾 小部件构建(构建上下文){ 返回脚手架( appBar:appBar(标题:新文本(“BMI计算器”), 正文:安全区( 子:容器( 填充:边缘设置。全部(24), 孩子:排( 儿童:[ 扩大( 孩子:卡片( 子:列( mainAxisAlignment:mainAxisAlignment.center, 儿童:[ 正文( “重量”, 样式:TextStyle(fontSize:20,fontWeight:fontWeight.bold,颜色:Colors.grey), ), 正文( _weight.toString(), 样式:TextStyle(fontSize:60,fontWeight:fontWeight.bold), ), 划船( mainAxisAlignment:mainAxisAlignment.space, 儿童:[ 浮动操作按钮( 子项:文本(“-”,样式:TextStyle(fontSize:50),), 按下:()=>{}, ), 浮动操作按钮( 子项:文本(“+”,样式:TextStyle(fontSize:50),), 按下:()=>{}, ) ], ) ])))]) ), ), ); } }
Flutter 当文本使用非默认大小时,浮动按钮中的文本居中 import'包装:flift/cupertino.dart'; 进口“包装:颤振/材料.省道”; 导入“package:font_awesome_flatter/font_awesome_flatter.dart”; 类MainScreen扩展StatefulWidget{ @凌驾 _State createState()=>_State(); } 枚举性别{男性,女性} 类_状态扩展状态{ 性别=性别。男性; 双倍高度=180; int _权重=74; 年龄=25岁; @凌驾 小部件构建(构建上下文){ 返回脚手架( appBar:appBar(标题:新文本(“BMI计算器”), 正文:安全区( 子:容器( 填充:边缘设置。全部(24), 孩子:排( 儿童:[ 扩大( 孩子:卡片( 子:列( mainAxisAlignment:mainAxisAlignment.center, 儿童:[ 正文( “重量”, 样式:TextStyle(fontSize:20,fontWeight:fontWeight.bold,颜色:Colors.grey), ), 正文( _weight.toString(), 样式:TextStyle(fontSize:60,fontWeight:fontWeight.bold), ), 划船( mainAxisAlignment:mainAxisAlignment.space, 儿童:[ 浮动操作按钮( 子项:文本(“-”,样式:TextStyle(fontSize:50),), 按下:()=>{}, ), 浮动操作按钮( 子项:文本(“+”,样式:TextStyle(fontSize:50),), 按下:()=>{}, ) ], ) ])))]) ), ), ); } },flutter,flutter-layout,Flutter,Flutter Layout,如何将“-”和“+”文本符号居中?我已经尝试使用居中小部件和对齐小部件,但运气不佳。您应该用图标替换文本 import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; class MainScreen extends StatefulWidget { @overr
如何将“-”和“+”文本符号居中?我已经尝试使用居中小部件和对齐小部件,但运气不佳。您应该用图标替换文本
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
class MainScreen extends StatefulWidget {
@override
_State createState() => _State();
}
enum Sex { Male, Female }
class _State extends State<MainScreen> {
Sex _sex = Sex.Male;
double _height = 180;
int _weight = 74;
int _age = 25;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: new Text("BMI CALCULATOR")),
body: SafeArea(
child: Container(
padding: EdgeInsets.all(24),
child: Row(
children: [
Expanded(
child: Card(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"WEIGHT",
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.grey),
),
Text(
_weight.toString(),
style: TextStyle(fontSize: 60, fontWeight: FontWeight.bold),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
FloatingActionButton(
child: Text("-", style: TextStyle(fontSize: 50),),
onPressed: () => {},
),
FloatingActionButton(
child: Text("+", style: TextStyle(fontSize: 50),),
onPressed: () => {},
)
],
)
])))])
),
),
);
}
}
如果它不居中,您可以使用中心小部件包装图标您应该用图标替换文本
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
class MainScreen extends StatefulWidget {
@override
_State createState() => _State();
}
enum Sex { Male, Female }
class _State extends State<MainScreen> {
Sex _sex = Sex.Male;
double _height = 180;
int _weight = 74;
int _age = 25;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: new Text("BMI CALCULATOR")),
body: SafeArea(
child: Container(
padding: EdgeInsets.all(24),
child: Row(
children: [
Expanded(
child: Card(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"WEIGHT",
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.grey),
),
Text(
_weight.toString(),
style: TextStyle(fontSize: 60, fontWeight: FontWeight.bold),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
FloatingActionButton(
child: Text("-", style: TextStyle(fontSize: 50),),
onPressed: () => {},
),
FloatingActionButton(
child: Text("+", style: TextStyle(fontSize: 50),),
onPressed: () => {},
)
],
)
])))])
),
),
);
}
}
如果它不居中,您可以使用中心小部件包装您的图标试试这个代码
,我做了一些更改和一些细节,它对我很有用
试试这个code
,我对一些细节做了一些更改,效果不错
试试这个
试试这个也不行的。按钮中的文本也存在同样的问题。不居中。@Notbad你在开玩笑吗?。我已经创建了一个新项目,并复制粘贴了整个代码,效果很好。@Notbad请在dartpad中粘贴相同的代码,你会看到结果。问题标题是:当文本使用非默认大小时,以浮动按钮居中文本。您看到浮动按钮内的-和+文本如何不居中了吗?它们略低于浮动按钮的垂直中心。这就是问题所在。@Notbad代替文本,你可以在文本的位置使用一个图标或图像,它可以完美地工作并作为一个完整的小部件居中。这也不起作用。按钮中的文本也存在同样的问题。不居中。@Notbad你在开玩笑吗?。我已经创建了一个新项目,并复制粘贴了整个代码,效果很好。@Notbad请在dartpad中粘贴相同的代码,你会看到结果。问题标题是:当文本使用非默认大小时,以浮动按钮居中文本。您看到浮动按钮内的-和+文本如何不居中了吗?它们略低于浮动按钮的垂直中心。这就是问题所在。@Notbad您可以在文本位置使用图标或图像来代替文本,这样可以完美地工作,并将其作为一个完整的小部件居中。这并不能回答问题。这是关于文本而不是我的。这并不能回答问题。这是关于文本而不是我的。这并不能回答问题。这是关于文本而不是我的。这并不能回答问题。它是关于文本而不是图标
class MainScreen extends StatefulWidget {
@override
_State createState() => _State();
}
enum Sex { Male, Female }
class _State extends State<MainScreen> {
Sex _sex = Sex.Male;
double _height = 180;
int _weight = 74;
int _age = 25;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: new Text("BMI CALCULATOR")),
body: SafeArea(
child: Container(
padding: EdgeInsets.all(24),
child: Row(children: [
Expanded(
child: Card(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
//Minus Sybmol button
FloatingActionButton(
child: Text(
"-",
style: TextStyle(fontSize: 50),
),
onPressed: () => {},
),
// As our text widget Weight is in the center of the - and +,
//So it should be added in the row between the - and + symbols button.
new Column(
children: [
Text(
"WEIGHT",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.grey),
),
Text(
_weight.toString(),
style: TextStyle(
fontSize: 60, fontWeight: FontWeight.bold),
),
],
),
//Plus Symbol button
FloatingActionButton(
child: Text(
"+",
style: TextStyle(fontSize: 50),
),
onPressed: () => {},
)
],
)
])))
])),
),
);
}
}
FloatingActionButton(
child:new Icon(Icons.remove,size:55),
onPressed: () => {},
),
SafeArea(
child: Container(
padding: EdgeInsets.all(24),
child: Row(children: [
Expanded(
child: Card(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"WEIGHT",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.grey),
),
Text(
_weight.toString(),
style:
TextStyle(fontSize: 60, fontWeight: FontWeight.bold),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
FloatingActionButton(
child: Icon(
Icons.remove,
size: 50,
),
onPressed: () => {},
),
FloatingActionButton(
child: Icon(
Icons.add,
size: 50,
),
onPressed: () => {},
)
],
)
])))
])),
)