mirrored_repositories/flutter_bloc_theming_example
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_bloc_theming_example/presentation/home_screen.dart';

import 'domain/cubit/theme/theme_cubit.dart';

void main() {
  runApp(const BaseApp());
}

class BaseApp extends StatelessWidget {
  const BaseApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MultiBlocProvider(providers: [
      BlocProvider<ThemeCubit>(
        create: (context) => ThemeCubit(),
      )
    ], child: const MyApp());
  }
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    ThemeCubit themeCubit = BlocProvider.of<ThemeCubit>(context, listen: true);
    bool isDark = themeCubit.isDark;
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: isDark
          ? ThemeData.dark().copyWith(
              appBarTheme: AppBarTheme(
              backgroundColor: ThemeData.dark().canvasColor,
            ))
          : ThemeData.light().copyWith(
              appBarTheme: AppBarTheme(
              backgroundColor: ThemeData.light().canvasColor,
            )),
      home: const HomeScreen(),
    );
  }
}
