是否有可能在单个窗口小部件中指定一种将用作默认颜色的颜色?
例如,我有这种情况:
Widget _widget1 = Scaffold(
body: Center(
child: new Container(
width: 300.0,
height: 300.0,
decoration: new BoxDecoration(
color: Colors.orange, //TODO set orange as default for BoxDecoration
shape: BoxShape.circle,
)
)
)
);
Widget _widget2 = Scaffold(
body: Center(
child: new Container(
width: 120.0,
height: 150.0,
decoration: new BoxDecoration(
color: Colors.orange, //TODO set orange as default for BoxDecoration
shape: BoxShape.rectangle,
)
)
)
);
而且我不想每次都指定BoxDecoration需要具有color: Colors.orange
。
您可以用许多不同的方法来做。在某个地方设置一个const BoxDecoration,然后将其用于装饰某些小部件,并使用copyWith()复制其颜色,同时覆盖您添加的任何其他内容。或者,您可以使用主题继承的小部件。