【发布时间】:2023-01-29 04:24:45
【问题描述】:
我的项目中使用的颜色有两种颜色需要更改。这些颜色将根据主题而变化,主题数据将从 API 中获取。现在的问题是我手动把theme给了test变量而不是api,但是我给int的值之后并没有改变。无论我在开始时给 int 什么,它都会保留。 常量飞镖:
import 'package:flutter/material.dart';
int koyuMor = 0xff410657;
int acikMor = 0xff5B336A;
int lacivert = 0xff0D1665;
int mavi = 0xff009DA4;
int koyuYesil = 0xff055511;
int acikYesil = 0xff8DA637;
int koyuTuruncu = 0xffC83232;
int acikTuruncu = 0xffDB7439;
var theme = 'ocean - theme';
int _color1 = 0;
int _color2 = 0;
void main() {
if (theme == 'thinker-theme') {
_color1 = koyuMor;
_color2 = acikMor;
}
if (theme == 'ocean-theme') {
_color1 = lacivert;
_color2 = mavi;
}
if (theme == 'forest-theme') {
_color1 = koyuYesil;
_color2 = acikYesil;
}
if (theme == 'sand-theme') {
_color1 = koyuTuruncu;
_color2 = acikYesil;
}
}
class Constant {
/// [Colors]
static Color color1 = Color(_color1);
static final Color color2 = Color(_color2);
static const Color koyuMor = Color(0x00410657);
static const Color acikMor = Color(0xff5B336A);
static const Color mavi = Color(0xff009DA4);
static const Color lacivert = Color(0xff0D1665);
static const Color koyuYesil = Color(0xff055511);
static const Color acikYesil = Color(0xff8DA637);
static const Color koyuTuruncu = Color(0xffC83232);
static const Color acikTuruncu = Color(0xffDB7439);
}
我也尝试过 ThemeData,以后似乎无法更改它。
我在其他页面中使用的代码:
color: Constant.color2,
【问题讨论】:
标签: flutter