selectThemeAtIndex method

Future selectThemeAtIndex(
  1. int themeIndex
)

Sets the theme for the application equal to the theme at the index in the list of themes supplied to the ThemeBuilder

Implementation

Future selectThemeAtIndex(int themeIndex) async {
  if (themes == null || themes!.isEmpty) {
    throw Exception(
        'You cannot select the theme if you have no themes supplied. Supply a list of themes to the constructor of the ThemeManager if you want to use this function.');
  }

  var theme = themes![themeIndex];
  await updateOverlayColors(theme);

  _themesController.add(ThemeModel(
    selectedTheme: theme,
    darkTheme: darkTheme,
    themeMode: _selectedThemeMode,
  ));

  _sharedPreferences.themeIndex = themeIndex;
}