child: const Text('Change Theme Color'), ), 读取配置 Future<void> main() async { WidgetsFlutterBinding.ensureInitialized(); final savedThemeMode = await AdaptiveTheme.getThemeMode(); runApp(MyApp(savedThemeMode: savedThemeMode)); } class MyApp extends StatelessWidget { final AdaptiveThemeMode?
void changeThemeData(int colorIndex,ThemeData themeData){ _themeData = themeData; _colorIndex = colorIndex; notifyListeners(); } ThemeData get themeData => _themeData; //获取主题 int get colorIndex => _colorIndex; //获取数字 } 1.2- 顶上包裹 状态管理库的套路基本一致,将需要管理的部分包裹起来,...
我们可以通过Get.bottomSheet()来显示BottomSheet,通过Get.back()实现路由返回,通过Get.changeTheme(ThemeData.dark())切换皮肤主题,通过Get.isDarkMode判断主题样式。 ElevatedButton(onPressed:(){Get.bottomSheet(Container(color:Get.isDarkMode?Colors.black12:Colors.white,height:200,child:Column(children:[ListTile...
复制 import'package:get/get.dart';classMyHomeControllerextendsGetxController{varcurrentIndex=0.obs;voidchangeIndex(int index){currentIndex.value=index;}} 这里面就是对于当前切换页面的记录和更新,下面在my_home文件夹下创建一个my_home.dart,里面装载我们前面写好的两个页面,完成切换的工作,代码如下...
("主题"),),body:Center(child:TextButton(onPressed:(){//直接设置ThemeGet.changeTheme(Get.isDarkMode?appLightThemeData:appDarkThemeData);//设置ThemeMode// Get.changeThemeMode(ThemeMode.dark);},child:Text("更换主题",style:Get.textTheme.headline1,//这里有个问题,就是主题切换,这里的Text并不会...
(SPName.themeMode);switch(themeModel){case"Dark":_themeMode=ThemeMode.dark;break;case"System":_themeMode=ThemeMode.system;break;default:_themeMode=ThemeMode.light;break;}return_themeMode!;}//获取保存的主题颜色ColorgetThemColor(){String?color=CacheUtil().get<String>(SPName.themeColor);return...
Adaptive Theme 这个组件通过包裹 MaterialApp 的方式整体管理 theme 主题,实现如下功能: 切换light、dark、system 三种模式 自定义色彩 保存主题选择 开启调试按钮 参考 https://pub.dev/packages/adaptive_theme https://flutter.ducafecat.com/pubs/adaptive_theme-package-info ...
--->[provider/theme_state.dart]---classThemeStateextendsChangeNotifier{ThemeData _themeData;//主题int _colorIndex;//主题ThemeState(this._colorIndex,this._themeData,);voidchangeThemeData(int colorIndex,ThemeData themeData){_themeData=themeData;_colorIndex=colorIndex;notifyListeners();}ThemeDatagetthemeData...
_changeColorWid()=>Container(color:Colors.white,child:Column(children:[ListTile(title:Text('切换 ThemeColor:')),Row(mainAxisAlignment:MainAxisAlignment.spaceAround,children:[_itemColorWid(Colors.deepOrange),_itemColorWid(Colors.teal),_itemColorWid(Colors.blue),_itemColorWid(Colors.pink),_itemColor...
theme: FlexThemeData.light( colors: const FlexSchemeColor( primary: Color(0xff065808), primaryContainer: Color(0xff9ee29f), secondary: Color(0xff365b37), secondaryContainer: Color(0xffaebdaf), tertiary: Color(0xff2c7e2e), tertiaryContainer: Color(0xffb8e6b9), ...