我正在尝试将按钮放置在Flutter Web应用程序中的自定义位置,但我不能。这是我的代码:
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context)
.size; // This method will give us the height and width of our device screen
return Container(
height: size.height,
width: size.width,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/687.jpg"), fit: BoxFit.cover)),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
color: Colors.black,
onPressed: () {},
child: Text("Login"),
textColor: Colors.white,
),
],
));
}
}
您可以在容器内使用边距为宽度填满并在容器内放置按钮。
或您可以使用定位的小部件
示例:
new Positioned(
left: MediaQuery.of(context).size.width/2+100,
top: MediaQuery.of(context).size.height/2,
child: new Container(
width: 100.0,
height: 80.0,
decoration: new BoxDecoration(color: Colors.red),
child: new Text('hello'),
)