// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
import 'package:bloc_helper_example/counter/counter_bloc_page.dart';
import 'package:bloc_helper_example/counter/counter_consumer_page.dart';
import 'package:bloc_helper_example/counter/counter_cubit_page.dart';
import 'package:bloc_helper_example/counter/counter_provider_page.dart';
import 'package:bloc_helper_example/counter/cubit/counter_cubit.dart';
import 'package:bloc_helper_example/counter_observer.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
void main() {
BlocOverrides.runZoned(() => runApp(const MyApp()),
blocObserver: CounterObserver());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MainPage(),
);
}
}
class MainPage extends StatelessWidget {
const MainPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Main Page'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
child: const Text('Counter with BlocScreen'),
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(builder: (_) => const CounterBlocPage())),
),
ElevatedButton(
child: const Text('Counter with CubitScreen'),
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(builder: (_) => const CounterCubitPage())),
),
ElevatedButton(
child: const Text('Counter with BlocProviderScreen'),
onPressed: () => Navigator.of(context).push(MaterialPageRoute(
builder: (_) => const CounterProviderPage())),
),
ElevatedButton(
child: const Text('Counter with BlocConsumerScreen'),
onPressed: () => Navigator.of(context)
.push(MaterialPageRoute(builder: (context) {
return BlocProvider(
create: (context) => CounterCubit(),
child: const CounterConsumerPage(),
);
})),
),
],
),
),
);
}
}