flutter - 如何在颤动中为自定义背景颜色创建一个全局类
问题描述
我有这样的 LinearBackground 颜色
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Colors.red, Colors.blue])));
就我而言,我有 3 个屏幕,我想将我的自定义背景应用到我拥有的所有屏幕上,有没有办法将上面的代码声明为一个类,以便我可以在我的屏幕上调用它需要它
解决方案
像这样创建一个带有类的 dart 文件
class AppConstants {
static const BoxDecoration myBoxDecoration = BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Colors.red, Colors.blue]));
}
并像这样使用它
child: Container(decoration: AppConstants.myBoxDecoration),
推荐阅读
- python - 如何使用 Stripe Checkout 实施双面推荐计划?
- sql - 如何计算以月为单位的差异 SQL DB2
- android - Android studio在导航组件中构建错误,动作不是抽象的并且没有实现抽象成员actionID
- c++ - SDL 2 中带有不透明元素的完全透明窗口
- javascript - JavaScript,HTML 搜索引擎 - 如何获取元素的父级?
- cuda - CUDA 驱动 API 等效于 cudaDeviceSetCacheConfig
- jmeter - 代理和 mqttclient 未收到传入消息,但存在于 Wireshark 中
- asp.net - IIS 上部署的应用程序的空白 ASP.NET 网页
- angular - 不应该否定异步管道
- mapbox - Mapbox - MapSnapshotter:导航层未出现