User interface 如何给AspectRatio尽可能多的空间
我有一个小部件,里面有AspectRatio小部件,当我将其放入扩展时,它的大小不正确(这个大小不满足给定的AspectRatio)。 有没有办法为AspectRatio获得尽可能多的空间并保持给定的AspectRatio 我这样做,得到100个单位的黄色和所有其他地方灰色。而不是比例宽度为2.0的灰色矩形:高度等于2.0User interface 如何给AspectRatio尽可能多的空间,user-interface,dart,flutter,aspect-ratio,User Interface,Dart,Flutter,Aspect Ratio,我有一个小部件,里面有AspectRatio小部件,当我将其放入扩展时,它的大小不正确(这个大小不满足给定的AspectRatio)。 有没有办法为AspectRatio获得尽可能多的空间并保持给定的AspectRatio 我这样做,得到100个单位的黄色和所有其他地方灰色。而不是比例宽度为2.0的灰色矩形:高度等于2.0 @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
children: <Widget>[
Container(
height: 100.0,
color: Colors.yellow,
),
Expanded(
child: AspectRatio(
aspectRatio: 2.0,
child: Container(
color: Colors.grey,
),
),
)
],
),
),
);
}
@覆盖
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(widget.title),
),
正文:中(
子:列(
儿童:[
容器(
高度:100.0,
颜色:颜色,黄色,
),
扩大(
孩子:AspectRatio(
aspectRatio:2.0,
子:容器(
颜色:颜色。灰色,
),
),
)
],
),
),
);
}
您可以将AspectRatio
小部件包装在Align
或Center
小部件中
Expanded(
child: Align(
alignment: Alignment.topLeft,
child: AspectRatio(
aspectRatio: 2.0,
child: Container(
color: Colors.grey,
),
),
),
)
您可以将
AspectRatio
小部件包装在Align
或Center
小部件中
Expanded(
child: Align(
alignment: Alignment.topLeft,
child: AspectRatio(
aspectRatio: 2.0,
child: Container(
color: Colors.grey,
),
),
),
)