smart_lib_theme 1.0.4 copy "smart_lib_theme: ^1.0.4" to clipboard
smart_lib_theme: ^1.0.4 copied to clipboard

A Flutter theme management library for dynamic theme switching with BLoC and ThemeExtension.

example/lib/main.dart

// smart_lib_theme.dart
import 'package:flutter/material.dart';
import 'package:smart_lib_theme/core/theme/default/themes.dart';
import 'package:smart_lib_theme/core/theme/extensions/theme_ext.dart';
import 'package:smart_lib_theme/features/theme/domain/entity/app_theme.dart';
import 'package:smart_lib_theme/features/theme/presentation/app_theme_manager.dart';
import 'package:smart_lib_theme/features/theme/presentation/widgets/app_theme_builder.dart';

/// Main entry point for the application
Future<void> main() async {
  // Initialize theme manager with supported themes
  await AppThemeManager.init(themes: [
    AppTheme(key: 'light', themeData: AppDefaultThemesData().light),
    AppTheme(key: 'dark', themeData: AppDefaultThemesData().dark)
  ]);
  runApp(const MyApp());
}

/// Root widget of the application
class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return AppThemeBuilder(
        builder: (theme) {
          return MaterialApp(
            title: 'Flutter Demo',
            theme: theme,
            home: HomePage(),
          );
        }
    );
  }
}

/// Home screen demonstrating theme switching
class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: context.appColors().surface,
      body: Column(
        children: [
          SizedBox(height: 300),
          Center(
            child: GestureDetector(
              onTap: () {
                // Switch to light theme
                AppThemeManager.changeTheme(
                    context: context,
                    themeKey:  'light'
                );
              },
              child: Text('light'),
            ),
          ),
          SizedBox(height: 100),
          Center(
            child: GestureDetector(
              onTap: () {
                // Switch to dark theme
                AppThemeManager.changeTheme(
                    context: context,
                    themeKey: "dark"
                );
              },
              child: Text('dark', style: context.textTheme().bodyMedium),
            ),
          ),
        ],
      ),
    );
  }
}
7
likes
150
points
41
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter theme management library for dynamic theme switching with BLoC and ThemeExtension.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

bloc, cupertino_icons, flutter, flutter_bloc, get_it, shared_preferences

More

Packages that depend on smart_lib_theme