stryder-dev / flutter_platform_widgets

Target the specific design of Material for Android and Cupertino for iOS widgets through a common set of Platform aware widgets
MIT License
1.58k stars 171 forks source link

All my Icons on Cupertino are blue even though I defined an icon theme #400

Closed ebitogu closed 10 months ago

ebitogu commented 1 year ago

I have my material_light_theme defined as shown below:

ThemeData materialLightTheme = ThemeData.light().copyWith(
    scaffoldBackgroundColor: AppColors.lightThemeBackgroundColor,
    brightness: Brightness.light,
    primaryColor: AppColors.primaryColor,
    primaryColorDark: AppColors.lightThemeBackgroundColor,
    cardColor: AppColors.lightThemeCardColor,
    colorScheme: const ColorScheme.light(
      primary: AppColors.primaryColor,
      secondary: AppColors.secondaryColor,
      background: AppColors.lightThemeBackgroundColor,
    ),
    dialogTheme: DialogTheme(
      titleTextStyle: GoogleFonts.poppins().copyWith(color: Colors.black),
      contentTextStyle: GoogleFonts.poppins().copyWith(
        color: Colors.black45,
      ),
    ),
    appBarTheme: AppBarTheme(
      systemOverlayStyle: const SystemUiOverlayStyle(
        statusBarColor: AppColors.lightThemeStatusBarColor,
        statusBarBrightness: Brightness.dark,
        statusBarIconBrightness: Brightness.dark,
        systemNavigationBarColor: AppColors.lightThemeNavigationBarColor,
        systemNavigationBarIconBrightness: Brightness.dark,
      ),
      elevation: 0,
      backgroundColor: AppColors.lightThemeBackgroundColor,
      toolbarTextStyle: GoogleFonts.poppins().copyWith(
        color: AppColors.gray900,
        fontSize: 18.0,
        fontWeight: FontWeight.w600,
      ),
      titleTextStyle: GoogleFonts.poppins().copyWith(
        color: AppColors.gray900,
        fontSize: 18.0,
        fontWeight: FontWeight.w600,
      ),
      iconTheme: const IconThemeData(color: AppColors.gray900, size: 25),
    ),
    inputDecorationTheme: InputDecorationTheme(
      errorStyle: GoogleFonts.poppins().copyWith(
        color: Colors.red,
      ),
      labelStyle: GoogleFonts.poppins().copyWith(fontSize: 16),
      enabledBorder: UnderlineInputBorder(
        borderSide: BorderSide(color: Colors.blue.shade700, width: 2),
      ),
      focusedBorder: UnderlineInputBorder(
        borderSide: BorderSide(color: Colors.blue.shade400, width: 1),
      ),
      errorBorder: UnderlineInputBorder(
        borderSide: BorderSide(color: Colors.red.shade700, width: 1),
      ),
      focusedErrorBorder: UnderlineInputBorder(
        borderSide: BorderSide(color: Colors.red.shade400, width: 1),
      ),
      disabledBorder: const UnderlineInputBorder(
        borderSide: BorderSide(color: Colors.grey, width: 1),
      ),
    ),
    textTheme: GoogleFonts.poppinsTextTheme()
        .apply(displayColor: Colors.black, bodyColor: AppColors.gray900),
    iconTheme: const IconThemeData(color: AppColors.gray900, size: 25), //Notice the icon theme here
    elevatedButtonTheme: ElevatedButtonThemeData(
      style: ButtonStyle(
        textStyle: MaterialStateProperty.all(
          GoogleFonts.poppinsTextTheme()
              .bodyMedium!
              .copyWith(fontWeight: FontWeight.w600),
        ),
        foregroundColor: MaterialStateProperty.all(Colors.white),
      ),
    ),
    textButtonTheme: TextButtonThemeData(
      style: ButtonStyle(
        textStyle: MaterialStateProperty.all(
          GoogleFonts.poppinsTextTheme()
              .bodyMedium!
              .copyWith(fontWeight: FontWeight.w600),
        ),
      ),
    ),
  );

Then I created my cupertino_light_theme as well and merged it with the material_light_theme above:

const lightDefaultCupertinoTheme =
        CupertinoThemeData(brightness: Brightness.light);
    return MaterialBasedCupertinoThemeData(
        materialTheme: materialLightTheme.copyWith( //Merged here
      cupertinoOverrideTheme: CupertinoThemeData(
        brightness: Brightness.light,
        barBackgroundColor: materialTheme.colorScheme.background,
        textTheme: CupertinoTextThemeData(
          primaryColor: Colors.black,
          navActionTextStyle:
              lightDefaultCupertinoTheme.textTheme.navActionTextStyle.copyWith(
            color: Colors.black,
          ),
          navLargeTitleTextStyle: lightDefaultCupertinoTheme
              .textTheme.navLargeTitleTextStyle
              .copyWith(
            color: Colors.black,
          ),
        ),
      ),
    ));
  }

then I connected them all in my main.dart file as shown below:

 builder: (context) => PlatformTheme(
                themeMode: ThemeMode.light,
                materialLightTheme: materialLightTheme,
                materialDarkTheme: materialDarkTheme,
                cupertinoLightTheme: cupertinoLightTheme,
                cupertinoDarkTheme: cupertinoDarkTheme,
                matchCupertinoSystemChromeBrightness: true
               .....

When I ran my app, the icon theme came out as expected on Android but on ios all my icons are blue. So, it seems the cupertino theme is not picking up my custom defined icon theme above.

Please how do I fix this? Thank you

aqwert commented 1 year ago

If you were to create a Cupertino only app, so using CupertinoApp with CupertinoScaffoldPage etc, and set the theme can you get the icon to be a different color. Most likely it is down to flutter itself but if you can replicate it entirely with cupertino widgets that would be a good point of reference