DynamicTheme constructor

const DynamicTheme({
  1. Key? key,
  2. required ThemedWidgetBuilder builder,
  3. required ThemeCollection themeCollection,
  4. int defaultThemeId = 0,
})

Creates a new DynamicTheme to handle dynamic themes.

builder returns a Widget themed according to the current theme passed as a parameter. themeCollection is the ThemeCollection mapping theme IDs to ThemeData themes. defaultThemeId is the ID of the theme to choose, if there is no theme ID saved in the preferences yet. Default is 0.

Example:

Widget build(BuildContext context) {
  final themeCollection = ThemeCollection(
    themes: {
      0: ThemeData(primarySwatch: Colors.blue),
      1: ThemeData(primarySwatch: Colors.red),
      2: ThemeData.dark()
    }
  );
  
  return DynamicTheme(
    themeCollection: themeCollection,
    defaultThemeId: 0,
    builder: (context, theme) {
      return MaterialApp(
        title: 'dynamic_themes example',
        theme: theme,
        home: HomePage(title: 'dynamic_themes example app'),
      );
    }
  );
}

Implementation

const DynamicTheme(
    {Key? key,
    required this.builder,
    required this.themeCollection,
    this.defaultThemeId = 0}) :
      super(key: key);