如何在颤振中实现暗模式 [英] how to implement dark mode in flutter
本文介绍了如何在颤振中实现暗模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个 Flutter 应用程序,它具有 2 个明暗模式主题,这些主题通过应用程序内的切换而改变,并且默认主题是默认的 android 主题.
我需要将一些自定义颜色传递给其他小部件,我不想只配置材质主题.
I want to create a flutter app that has 2 light and dark mode themes that change by a switch in-app and the default theme is default android theme.
I need to pass some custom color to the fellow widget and I don't want to just config material theme.
- 如何检测用户设备的默认主题?
- 第二个问题是如何为整个应用程序提供一个主题?
- 第三个是如何通过简单的运行时间切换来改变主题?
推荐答案
MaterialApp(
title: 'App Title',
theme: ThemeData(
brightness: Brightness.light,
/* light theme settings */
),
darkTheme: ThemeData(
brightness: Brightness.dark,
/* dark theme settings */
),
themeMode: ThemeMode.dark,
/* ThemeMode.system to follow system theme,
ThemeMode.light for light theme,
ThemeMode.dark for dark theme
*/
debugShowCheckedModeBanner: false,
home: YourAppHomepage(),
);
您可以使用 scoped_model 或 provider 以获得无缝体验.
You can use scoped_model or provider for seamless experience.
这篇关于如何在颤振中实现暗模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文