为Flutter中的特定小部件设置默认颜色

问题描述 投票:0回答:1

是否有可能在单个窗口小部件中指定一种将用作默认颜色的颜色?

例如,我有这种情况:

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

user-interface flutter layout colors flutter-layout
1个回答
0
投票

您可以用许多不同的方法来做。在某个地方设置一个const BoxDecoration,然后将其用于装饰某些小部件,并使用copyWith()复制其颜色,同时覆盖您添加的任何其他内容。或者,您可以使用主题继承的小部件。

© www.soinside.com 2019 - 2024. All rights reserved.