【发布时间】:2020-02-13 18:05:23
【问题描述】:
是否可以在 Flutter 中指定一种颜色作为单个小部件中的默认颜色?
比如我有这种情况:
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。
【问题讨论】:
-
只使用全局变量,可以指定final Color orangeColor = Colors.orange;对我来说,我总是创建一个名为 globals.dart 的文件,其中包含我需要的所有全局变量,并将其导入到需要使用它的每个文件中
标签: user-interface flutter layout colors flutter-layout