### 主题
```
// 1.main主文件
import 'package:flutter_smart_park/config/theme.dart' show AppTheme; Provide.value<ConfigModel>(context).$getTheme();Provide<ConfigModel>(builder: (context, child, configModel) {return MaterialApp(title: '智慧xx区',debugShowCheckedModeBanner: false,onGenerateRoute: Routes.router.generator,theme: AppTheme.getThemeData(configModel.theme),home: WillPopScope(onWillPop: () async {timerCountDown = TimerUtil(mInterval: 1000, mTotalTime: 1 * 1000);timerCountDown.setOnTimerTickCallback((int value) {if (value == 0) {AndroidBackTop.cancelBackDeskTop();}});timerCountDown.startCountDown();AndroidBackTop.backDeskTop();return false;},child: Pages(),),);},
);
// 2.theme 主题文件
import 'package:flutter/material.dart';Map materialColor = {'purple': {"primaryColor": 0xFF7B1FA2,"primaryColorLight": 0xFF9C27B0,},'pink':{"primaryColor": 0xFFc2185b,"primaryColorLight": 0xFFd81b60,},'deeppink':{"primaryColor": 0xFFf50057,"primaryColorLight": 0xFFe91e63,},'blue':{"primaryColor": 0xFF1976D2,"primaryColorLight": 0xFF2196F3,},
};class AppTheme {static Map mainColor = materialColor['purple'];static getThemeData(String theme) {mainColor = materialColor[theme];ThemeData themData = ThemeData(// scaffoldBackgroundColor: Colors.red, // 页面的背景颜色primaryColor: Color(mainColor["primaryColor"]), // 主颜色primaryColorLight: Color(mainColor["primaryColorLight"]),// 按钮颜色buttonTheme: ButtonThemeData(textTheme: ButtonTextTheme.primary,buttonColor: Color(mainColor["primaryColor"]),),// appbar样式appBarTheme: AppBarTheme(iconTheme: IconThemeData(color: Colors.white),textTheme: TextTheme(title: TextStyle(color: Colors.white,fontSize: 20.0,),),),// 图标样式iconTheme: IconThemeData(color: Color(mainColor["primaryColor"]),),);return themData;}
}// 3.provide 状态管理文件
import 'package:flutter_smart_park/untils/local_storage.dart';
class ConfigInfo {String theme = 'purple';   // 默认主题颜色
}class ConfigModel extends ConfigInfo with ChangeNotifier {  // 将主题颜色保存至本地存储,持久化Future $getTheme() async {String _theme = await LocalStorage.get('theme');if (_theme != null) {$setTheme(_theme);}}Future $setTheme(payload) async {theme = payload;LocalStorage.set('theme', payload);notifyListeners();}
}
//  4.local_storage文件
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';class LocalStorage {static Future get(String key) async {SharedPreferences prefs = await SharedPreferences.getInstance();return prefs.getString(key);}static Future set(String key, String value) async {SharedPreferences prefs = await SharedPreferences.getInstance();prefs.setString(key, value);}static Future setJSON(String key, value) async {SharedPreferences prefs = await SharedPreferences.getInstance();value = json.encode(value);prefs.setString(key, value);}static Future remove(String key) async {SharedPreferences prefs = await SharedPreferences.getInstance();prefs.remove(key);}
}// 使用
Theme.of(context).primaryColor,``````
(new) ThemeData({Brightness brightness, MaterialColor primarySwatch, Color primaryColor, Brightness primaryColorBrightness, Color primaryColorLight, Color primaryColorDark, Color accentColor, Brightness accentColorBrightness, Color canvasColor, Color scaffoldBackgroundColor, Color bottomAppBarColor, Color cardColor, Color dividerColor, Color highlightColor, Color splashColor, InteractiveInkFeatureFactory splashFactory, Color selectedRowColor, Color unselectedWidgetColor, Color disabledColor, Color buttonColor, ButtonThemeData buttonTheme, Color secondaryHeaderColor, Color textSelectionColor, Color cursorColor, Color textSelectionHandleColor, Color backgroundColor, Color dialogBackgroundColor, Color indicatorColor, Color hintColor, Color errorColor, Color toggleableActiveColor, String fontFamily, TextTheme textTheme, TextTheme primaryTextTheme, TextTheme accentTextTheme, InputDecorationTheme inputDecorationTheme, IconThemeData iconTheme, IconThemeData primaryIconTheme, IconThemeData accentIconTheme, SliderThemeData sliderTheme, TabBarTheme tabBarTheme, CardTheme cardTheme, ChipThemeData chipTheme, TargetPlatform platform, MaterialTapTargetSize materialTapTargetSize, PageTransitionsTheme pageTransitionsTheme, AppBarTheme appBarTheme, BottomAppBarTheme bottomAppBarTheme, ColorScheme colorScheme, DialogTheme dialogTheme, Typography typography, CupertinoThemeData cupertinoOverrideTheme}) → ThemeData
package:flutterCreate a [ThemeData] given a set of preferred values.Default values will be derived for arguments that are omitted.The most useful values to give are, in order of importance:The desired theme [brightness].The primary color palette (the [primarySwatch]), chosen from one of the swatches defined by the material design spec. This should be one of the maps from the [Colors] class that do not have "accent" in their name.The [accentColor], sometimes called the secondary color, and, if the accent color is specified, its brightness ([accentColorBrightness]), so that the right contrasting text color will be used over the accent color.See https://material.io/design/color/ for more discussion on how to pick the right colors.``````
(new) ButtonThemeData({ButtonTextTheme textTheme: ButtonTextTheme.normal, double minWidth: 88.0, double height: 36.0, EdgeInsetsGeometry padding, ShapeBorder shape, ButtonBarLayoutBehavior layoutBehavior: ButtonBarLayoutBehavior.padded, bool alignedDropdown: false, Color buttonColor, Color disabledColor, Color highlightColor, Color splashColor, ColorScheme colorScheme, MaterialTapTargetSize materialTapTargetSize}) → ButtonThemeData
package:flutterCreate a button theme object that can be used with [ButtonTheme] or [ThemeData].The [textTheme], [minWidth], [height], [alignedDropDown], and [layoutBehavior] parameters must not be null. The [minWidth] and [height] parameters must greater than or equal to zero.The ButtonTheme's methods that have a [MaterialButton] parameter and have a name with a get prefix are used by [RaisedButton], [OutlineButton], and [FlatButton] to configure a [RawMaterialButton].```

  

转载于:https://www.cnblogs.com/john-hwd/p/10760376.html

flutter 主题切换相关推荐

  1. Compose主题切换——让你的APP也能一键换肤

    开端 应用换肤,这真的是一个老生常谈的问题,从原生安卓开始.到后来的 Flutter ,再到现在的 Compose ,虽说老生常谈,但其实还是新瓶装旧酒. 安卓原生的主题切换这里不再说了,这不是本文的 ...

  2. Compose主题切换,让你的APP也能一键换肤

    /   今日科技快讯   / 近日,据外媒援引知情人士消息,推特已经聘请并购法领域的重量级律师事务所Wachtell, Lipton, Rosen & Katz LLP组建专门的律师团队,以起 ...

  3. 英语阅读推荐:主题切换控件 ExpressionBuilder

    这里是Cat in dotNET的Random Clippings系列,专门向大家推荐.NET相关的英文技术文章,每期推荐两篇文章,第一篇适合于英语技术文章阅读的入门者练习阅读能力,而第二篇则适合于进 ...

  4. CI框架主题切换的功能

    CI框架主题切换的功能 本人接触到这个框架不就,属于菜鸟 , 公司现在用CI框架做项目 ,老大要做一个主题切换的功能,说明功能的要求我的脑子里瞬间有几个想法. 脑子里最简单的就是设置全局变量 如 : ...

  5. 主题切换时如何主动去刷新一些资源?

    近来不少同学在修改主题时遇到,切换主题,部分页面不更新的问题,下面来介绍一种切换主题时,主动刷新的方法:1.监听主题切换的广播private static final String DATA_TYPE ...

  6. 仿知乎客户端的白天黑夜主题切换

    仿知乎客户端的白天黑夜主题切换 转载请注明出处 作者:AboutJoke ( http://blog.csdn.net/u013200308 ) 原文链接:http://blog.csdn.net/u ...

  7. SpringMVC实现i18n和主题切换

    一.什么是i18n i18n(其来源是英文单词 internationalization的首末字符i和n,18为中间的字符数)是"国际化"的简称.对于程序开发来说,i18n就是能够 ...

  8. 关于给hexo博客增加节日气氛主题切换(包括中国春节和圣诞节)

    前言: 有段时间没折腾过博客页面样式了,偶然间看到了一个春节红灯笼的小demo,感觉很棒,所以拿过来了,并且自己新增了一些小挂件,加上了关键帧动画,圣诞树等元素.主题切换按钮原理和以前教程里面提到的暗 ...

  9. 【Web技术】1431- 总结前端主题切换的思考和现代前端样式的解决方案落地

    关于本文 来自:codercao https://juejin.cn/post/7106702604024938503 demo在线体验地址:https://hongqingcao.github.io ...

最新文章

  1. svn中提示”Files 的值 .mine 无效” 的解决方案
  2. 【 MATLAB 】MATLAB帮助文档中对 MP 算法以及 OMP 算法的讲解(英文版)
  3. 制作生成静态页面的新闻系统
  4. 浅谈压缩感知(二十一):压缩感知重构算法之正交匹配追踪(OMP)
  5. .net core EPPlus npoi_微软官方上线免费C#、.NET在线教程视频
  6. 计算机视觉招聘_INDEMIND|SLAM、计算机视觉、深度学习算法招聘(社招实习)
  7. UITableView 性能优化
  8. 前端学习(1818):前端面试题之封装函数之进行字符串驼峰的命名
  9. mpvue 从零开始 女友的收纳盒 6 mpvue-entry入口管理
  10. hadoop使用combiner合并操作
  11. nginx开机自启动
  12. java设置类的字符格式_java类---与格式化相关的类
  13. go语言mongdb管道使用
  14. 解决办法:dpkg: 错误: 无法打开软件包的 info 文件 /var/lib/dpkg/available 以便读取: 没有那个文件或目录
  15. 办公技巧分享:如何编辑PDF文件内容
  16. 遭遇Trojan.PSW.ZhengTu,Trojan.PSW.OnlineGames,Trojan.PSW.ZhuXian.b等
  17. 如何将自己的电脑变成WiFi热点
  18. ncs java 成都 面试_成都java工程师面试一般都是哪些问题,基础难不难!
  19. discuz X3.2 DB:类数据库操作
  20. 单通道和多通道图像相关概念

热门文章

  1. Python字符串基础操作
  2. ajax传递数组后台接收不到值的问题
  3. 《Cocos2d 跨平台游戏开发指南(第2版)》一1.9 添加动作到精灵
  4. C# WinForm 自定义控件,DataGridView背景透明,TabControl背景透明
  5. 实例详细讲解ASP生成静态页面方法
  6. GD项目回顾之JWT
  7. android控件的对齐方式(转)
  8. java ReentrantLock 实现原理
  9. Redis:redis入门
  10. 超键、候选键、主键、外键、联合主键、复合主键