Flutter Getx主题更改textColor不工作

gblwokeq  于 2023-05-19  发布在  Flutter
关注(0)|答案(1)|浏览(141)

我想在我的应用程序中使用亮模式和暗模式。我决定使用getx主题。当我切换到深色模式时,脚手架颜色和应用程序栏颜色会更改,但文本颜色不会更改。注:热重新加载时颜色会发生变化
我正在写代码切换到黑暗模式下面

Get.changeThemeMode(ThemeMode.dark);

我正在使用的主题在下面的代码中

getDarkTheme(context) => ThemeData.dark().copyWith(
      splashColor: Colors.transparent,
      highlightColor: Colors.transparent,
      hoverColor: Colors.transparent,
      scaffoldBackgroundColor: const Color(0xff181A20),
      appBarTheme: const AppBarTheme(
          backgroundColor: Color(0xff181A20),
          elevation: 0,
          iconTheme: IconThemeData(color: Colors.white)),
      textTheme: Theme.of(context).textTheme.apply(
          displayColor: Colors.white,
          fontFamily: GoogleFonts.urbanist().fontFamily),
      primaryColor: const Color(0xff181A20));

注意:我使用下面的代码来更改文本颜色主题,但它也不会立即更改。

textTheme: TextTheme(
   displayMedium: TextStyle(
      color: Colors.white,
      fontFamily: GoogleFonts.urbanist().fontFamily)),

我使用的文本小部件在下面;

Text(
    text,
    style: Theme.of(Get.context!).textTheme.displayLarge!.copyWith(
        fontSize: fontSize,
        fontWeight: fontWeight),
    textAlign: isCenter ? TextAlign.center : TextAlign.start,
  );

这就是我如何使用主题;

GetMaterialApp(
initialRoute: AppPages.initialRoute,
debugShowCheckedModeBanner: false,
theme: Themes().getLightTheme(context),
darkTheme: Themes().getDarkTheme(context),
themeMode: ThemeService().getThemeMode(),
getPages: AppPages.routes);

当我想在我的应用程序中更改主题时,我希望文本颜色立即更改。

syqv5f0l

syqv5f0l1#

我把一个加载屏幕,这是我如何解决了错误,现在

相关问题