我创建了一个名为 dart 的文件theme.dart
,其中我将所有 mycolors
和 my font sizes
and放在那里text styles
。
我的theme.dart
样子是这样的:
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
//COLORS
const colorPrimary = Color(0xFF913f91);
const colorPrimaryLight = Color(0xFFed74ed);
const colorSecondary = Color(0xFF1fb4ac);
const colorSecondaryLight = Color(0xFF3ee6dc);
const colorTertiary = Color(0xFFff8519);
const colorTertiaryLight = Color(0xFFf7a963);
const colorPositive = Color(0xFF00d96f);
const colorNegative = Color(0xFFFF4464);
const colorNegativeDark = Color(0xFFff8095);
const colorDisabled = Color(0xFFC1C1C1);
const colorOffWhite = Color(0xFFf2f2f2);
const colorOffBlack = Color(0xFF222222);
const colorText = Color(0xFF222222);
const colorAqua = Color(0xFF19c4fc);
const colorAquaDark = Color(0xFF09a7db);
const colorDarkBlue = Color(0xFF00649e);
const colorBlue = Color(0xFF1fadff);
const colorYellow = Color(0xFFfff021);
const colorYellowLight = Color(0xFFfff354);
const gradientTop = Color(0xFFFFD560);
const gradientBottom = Color(0xFFFF8519);
const colorShadowDark = Color(0xFF090909);
//FONT SIZE
const fontSizeRegular = 18.0;
const fontSizeSmall = 12.0;
const fontSizeMedium = 15.0;
const fontSizeSmallest = 10.0;
const fontSizeLarge = 22.0;
const fontExtraLarge = 30.0;
//TEXT STYLES
textHeaderStyle(Color _color, FontStyle _fontStyle, FontWeight _fontWeight) {
return TextStyle(
fontSize: ScreenUtil().setSp(fontSizeLarge),
color: _color,
fontStyle: _fontStyle,
fontWeight: _fontWeight);
}
例如,我switch
在“设置”菜单中有一个可以在暗模式和亮模式之间切换的假设。
最好的方法是什么?
如果我在颜色上添加条件,例如:
const colorPrimary = mode == "light" ? Color(0xFF913f91) : Color(0xFFed74ed);
其中“模式”是一个全局变量,每次在“设置”菜单中setState()
切换时我都会添加一个,它会起作用吗?switch
我很乐意尝试您的所有建议。
感谢那些可以提供帮助的人!