【发布时间】:2018-02-27 22:52:43
【问题描述】:
我正在创建一个日历小部件。 我们在星期几的 Row 标题中添加了一个以 Expanded 包裹的 DecoratedBox。 为什么使用 Expanded 时会显示红色图层?
当排除 Expanded 时,DecoratedBox 不展开...
class CalenderPage extends StatefulWidget {
@override
_CalenderPageState createState() => new _CalenderPageState();
}
class _CalenderPageState extends State<CalenderPage> {
DateTime now = new DateTime.now();
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Calender'),
),
body: new Center(
child: new Column(children: <Widget>[
new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: _createWeekOfDays()),
]),
),
);
}
List<Widget> _createWeekOfDays() {
List<Widget> _weekOfDays = new List<Widget>();
for (final weekOfDay in ['Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun',]) {
_weekOfDays.add(
new Expanded(
child: new DecoratedBox(
position: DecorationPosition.background,
decoration: new BoxDecoration(
border: new Border.all(
color: Theme.of(context).dividerColor, width: 1.0),
),
child: new Padding(
padding: new EdgeInsets.only(top: 8.0, bottom: 8.0),
child: new Text(
weekOfDay,
style: new TextStyle(fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
),
),
),
);
}
return _weekOfDays;
}
}
【问题讨论】:
标签: flutter