我的Flutter布局有问题.
我有一个简单的容器,右边和左边的边距为20.0.在这个容器内,我有另一个容器.
但是这个容器只适合左侧的父容器.我不知道为什么会这样.
这是我的代码:
@override
Widget build(BuildContext context) {
return new Scaffold(
backgroundColor: Colors.white,
body: new Container(
margin: new EdgeInsets.symmetric(horizontal: 20.0),
child: new Container(
)
),
);
}
Run Code Online (Sandbox Code Playgroud)
我用 BackButton 和 TextWidget 创建了一行。我想将文本居中到屏幕中间。实际上 flutter 将文本居中到容器宽度,但容器宽度与屏幕宽度不同,因为有后退按钮。我该如何解决?
Expanded getTitle() {
return new Expanded(
child: new Text("Einloggen", style: new TextStyle(fontSize: 18.0), textAlign: TextAlign.center)
);
}
BackButton getBackButton() {
return new BackButton(
);
}
Row getHeader() {
return new Row(
children: <Widget>[
getBackButton(),
getTitle()
],
);
}
@override
Widget build(BuildContext context) {
final double statusBarHeight = MediaQuery.of(context).padding.top;
return new Material(
child: new Container(
padding: new EdgeInsets.fromLTRB(0.0, statusBarHeight, 0.0, 0.0),
child: new Column(
children: <Widget>[
getHeader()
],
),
),
);
}
Run Code Online (Sandbox Code Playgroud)