vox_flex_theme 0.0.33 copy "vox_flex_theme: ^0.0.33" to clipboard
vox_flex_theme: ^0.0.33 copied to clipboard

The necessary methods to easily add a theme_controller for the flex_color_scheme, we do this so we can more easily introduce color themes and switch between them.

When integrating the flex_color_scheme package into flutter you may want to more easily attach controllers and be able to switch between many different type of themes quickly, this allows this seemlessly.

Features #

  • Built in ThemeController, that we can attach at the top of our application

Getting started && Usage #

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  final themeService = ThemeServiceHive('color_theme_hive');
  // Initialize the theme service.
  await themeService.init();
  // Create a ThemeController that uses the ThemeService.
  final ThemeController themeController = ThemeController(themeService);
  // Load preferred theme settings, while the app is loading, before MaterialApp
  // is created, this prevents a theme change when the app is first displayed.
  await themeController.loadAll();

  runApp(
    ChangeNotifierProvider(
      create: (_) => themeController,
      /// your app here!
      child: ModularApp(
        module: MainModule(),
        child: MainPage(
          controller: themeController,
        ),
      ),
    ),
  );
}

now when we need to switch themes we can use the bellow very easily

final themeController = context.watch<ThemeController>();
bool isLight = themeController.themeMode == ThemeMode.light;

 // Set theme-mode light/dark
  if (isLight) {
    themeController.setThemeMode(ThemeMode.dark);
  } else {
    themeController.setThemeMode(ThemeMode.light);
  }

get the currently selected theme index

var current_theme_index =  themeController.schemeIndex

get all theme built out from flex_color_scheme

final themes = [...AppColor.customSchemes];
/// lets iterate over these and show them!
ListView.builder(
padding: const EdgeInsets.only(
  right: kPad,
  left: kPad / 4,
  bottom: kPad * kPad,
),
itemCount: themes.length,
itemBuilder: (context, index) {
  /// the bellow will call a method like
  /// themeController.setThemeMode(isLight //
  ///     ? ThemeMode.light
  ///     : ThemeMode.dark);
  /// themeController.setSchemeIndex(index);


  return ColorThemeListTile(
    index: index,
    themeData: themes[index],
  );


},
),

Additional information #

we are using many different packages here! so this could cause some version issues, however for the time being this is simpela enough and adds a lot of functionality to our app. so a necessary evil.

1
likes
120
points
70
downloads

Publisher

unverified uploader

Weekly Downloads

The necessary methods to easily add a theme_controller for the flex_color_scheme, we do this so we can more easily introduce color themes and switch between them.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flex_color_scheme, flutter, google_fonts, hive, path_provider, shared_preferences, url_launcher, vox_widgets

More

Packages that depend on vox_flex_theme