如何使用软件包Shared_Preferences保存主题



帮助我找出在代码中写入内容的位置,以便在重新启动应用程序后保存主题。。。安装了animated_theme_switcher包,我不知道在哪里指定,这样主题就可以保留

我的代码:

@override
Widget build(BuildContext context) {
final isPlatformDark = WidgetsBinding.instance!.window.platformBrightness == Brightness.dark;
final theme = isPlatformDark ? darkTheme : lightTheme;
child: ThemeProvider(
initTheme: theme,
builder: (context, theme) {
return MaterialApp(
theme: theme,
home: MyApp1(),
debugShowCheckedModeBanner: false,
);
},
),

按钮上的动作

onPressed: () async {
var brightness =
ThemeProvider.of(context)!.brightness;
ThemeSwitcher.of(context)!.changeTheme(
theme: brightness == Brightness.light
? darkTheme
: lightTheme,
reverseAnimation:
brightness == Brightness.dark
? true
: false,
);
setState(() {
toggle = !toggle;
});
},

尝试使用adaptive_theme,自适应主题(_T(:https://pub.dev/packages/adaptive_theme

相关内容

  • 没有找到相关文章

最新更新