acme_theme 0.8.0 copy "acme_theme: ^0.8.0" to clipboard
acme_theme: ^0.8.0 copied to clipboard

A package to use the themes and components extracted from Acme Theme Builder.

example/lib/main.dart

import 'package:acme_theme/acme_theme.dart';
import 'package:clean_framework/clean_framework.dart';
import 'package:clean_framework_router/clean_framework_router.dart';
import 'package:acme_theme_example/brand_colors.dart';
import 'package:acme_theme_example/providers.dart';
import 'package:acme_theme_example/routes.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(
    SampleThemeApp(
      themeMode: ThemeMode.light,
      themeData: ThemeData.light(useMaterial3: true),
      darkThemeData: ThemeData.dark(useMaterial3: true),
      onIconPressed: () {},
      isOnThemeBuilder: false,
    ),
  );
}

class SampleThemeApp extends StatelessWidget {
  final ThemeMode themeMode;
  final ThemeData? themeData;
  final ThemeData? darkThemeData;
  final VoidCallback onIconPressed;
  final bool isOnThemeBuilder;

  const SampleThemeApp({
    super.key,
    required this.themeMode,
    required this.themeData,
    required this.darkThemeData,
    required this.onIconPressed,
    required this.isOnThemeBuilder,
  });

  @override
  Widget build(BuildContext context) {
    return SampleAppListenerScope(
      onIconPressed: onIconPressed,
      isOnThemeBuilder: isOnThemeBuilder,
      child: AppProviderScope(
        externalInterfaceProviders: [
          getRandomUserExternalInterfaceProvider,
          notesStoreExternalInterfaceProvider,
          imageUtilExternalInterfaceProvider,
        ],
        child: ThemeScope(
          notifier: ThemeNotifier(),
          child: Builder(
            builder: (context) {
              return AcmeThemeScope<BrandColors>.asset(
                path: ThemeScope.of(context).assetPath,
                customColorsConverterCreator: BrandColorsConverter.new,
                builder: (context, theme) {
                  return AppRouterScope(
                    create: NoteRouter.new,
                    builder: (context) {
                      return MaterialApp.router(
                        debugShowCheckedModeBanner: false,
                        title: 'Twitter Clone App',
                        theme: isOnThemeBuilder ? themeData : theme.lightTheme,
                        darkTheme:
                            isOnThemeBuilder ? darkThemeData : theme.darkTheme,
                        themeMode:
                            isOnThemeBuilder ? themeMode : theme.themeMode,
                        routerConfig: context.router.config,
                      );
                    },
                  );
                },
              );
            },
          ),
        ),
      ),
    );
  }
}

class ThemeNotifier extends ChangeNotifier {
  String _assetPath = 'assets/example-theme.acme';

  String get assetPath => _assetPath;

  void changeAsset(String assetPath) {
    if (_assetPath != assetPath) {
      _assetPath = assetPath;
      notifyListeners();
    }
  }
}

class ThemeScope extends InheritedNotifier<ThemeNotifier> {
  const ThemeScope({
    super.key,
    required super.notifier,
    required super.child,
  });

  static ThemeNotifier of(BuildContext context) {
    final scope = context.dependOnInheritedWidgetOfExactType<ThemeScope>();
    assert(scope != null);
    return scope!.notifier!;
  }
}

class SampleAppListenerScope extends InheritedWidget {
  const SampleAppListenerScope({
    super.key,
    required super.child,
    required this.onIconPressed,
    required this.isOnThemeBuilder,
  });

  final VoidCallback onIconPressed;
  final bool isOnThemeBuilder;

  static SampleAppListenerScope of(BuildContext context) {
    final SampleAppListenerScope? result =
        context.dependOnInheritedWidgetOfExactType<SampleAppListenerScope>();
    assert(result != null, 'No SettingsListner found in context');
    return result!;
  }

  @override
  bool updateShouldNotify(SampleAppListenerScope oldWidget) {
    return false;
  }
}
3
likes
0
points
188
downloads

Publisher

verified publisheracmesoftware.com

Weekly Downloads

A package to use the themes and components extracted from Acme Theme Builder.

Homepage

License

unknown (license)

Dependencies

flutter, google_fonts, http, json_class, json_theme, meta, nsd, path, path_provider, shared_preferences, web_socket_channel

More

Packages that depend on acme_theme