Home > OS >  Can I use two ThemeData types?
Can I use two ThemeData types?

Time:03-13

I am trying to use these two ThemeData types in my MaterialApp. Check it out:

return GetMaterialApp(
  debugShowCheckedModeBanner: false,
  title: 'DISH Connect',
  home: SiteLayout(),
  theme: ThemeData.light(),
  darkTheme: ThemeData.dark(),
  darkTheme: ThemeData(
    pageTransitionsTheme: PageTransitionsTheme(
      builders: {
        TargetPlatform.iOS: FadeUpwardsPageTransitionsBuilder(),
        TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
      },
    ),
  ),
  themeMode: provider.themeMode,
);

You can see that for my normal theme option, I have ThemeData.light(). I want to do the same for dark (which means I have to do 'ThemeData.dark()'). But I also want to be able to declare my pageTransitionTheme for these.

How can I make this possible?

CodePudding user response:

You can use copyWith() method:

darkTheme: ThemeData.dark().copyWith(
  pageTransitionsTheme: PageTransitionsTheme(
    builders: {
      TargetPlatform.iOS: FadeUpwardsPageTransitionsBuilder(),
      TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
    },
  ),
),

CodePudding user response:

You can change theme by state management for example Provider, so if attribute is light take lightTheme otherwise use darkTheme.

theme: appProvider.isLight? ThemeData.light() : ThemeData.dark(), 
  • Related