drift/moor_flutter/example/lib/main.dart

59 lines
1.4 KiB
Dart
Raw Normal View History

2019-02-17 02:32:54 -08:00
import 'package:flutter/material.dart';
2019-03-09 07:37:22 -08:00
import 'package:moor_example/bloc.dart';
import 'widgets/homescreen.dart';
2019-02-17 02:32:54 -08:00
void main() => runApp(MyApp());
2019-02-17 04:07:27 -08:00
class MyApp extends StatefulWidget {
2019-02-17 02:32:54 -08:00
@override
2019-02-17 04:07:27 -08:00
MyAppState createState() {
return MyAppState();
2019-02-17 02:32:54 -08:00
}
}
// We use this widget to set up the material app and provide an InheritedWidget that
// the rest of this simple app can then use to access the database
2019-02-17 04:07:27 -08:00
class MyAppState extends State<MyApp> {
2019-03-03 13:03:11 -08:00
TodoAppBloc bloc;
2019-02-17 02:32:54 -08:00
@override
2019-02-17 04:07:27 -08:00
void initState() {
2019-03-03 13:03:11 -08:00
bloc = TodoAppBloc();
2019-02-17 04:07:27 -08:00
super.initState();
}
2019-02-17 02:32:54 -08:00
@override
Widget build(BuildContext context) {
2019-03-03 13:03:11 -08:00
return BlocProvider(
bloc: bloc,
2019-02-17 04:07:27 -08:00
child: MaterialApp(
2019-03-09 07:37:22 -08:00
title: 'moor Demo',
2019-02-17 04:07:27 -08:00
theme: ThemeData(
primarySwatch: Colors.orange,
// use the good-looking updated material text style
typography: Typography(
englishLike: Typography.englishLike2018,
dense: Typography.dense2018,
tall: Typography.tall2018,
),
2019-02-17 02:32:54 -08:00
),
2019-02-17 04:07:27 -08:00
home: HomeScreen(),
2019-02-17 02:32:54 -08:00
),
);
}
}
2019-02-17 04:07:27 -08:00
2019-03-03 13:03:11 -08:00
class BlocProvider extends InheritedWidget {
final TodoAppBloc bloc;
2019-02-17 04:07:27 -08:00
2019-03-03 13:03:11 -08:00
BlocProvider({@required this.bloc, Widget child}) : super(child: child);
2019-02-17 04:07:27 -08:00
@override
2019-03-03 13:03:11 -08:00
bool updateShouldNotify(BlocProvider oldWidget) {
return oldWidget.bloc != bloc;
2019-02-17 04:07:27 -08:00
}
2019-03-03 13:03:11 -08:00
static TodoAppBloc provideBloc(BuildContext ctx) =>
(ctx.inheritFromWidgetOfExactType(BlocProvider) as BlocProvider).bloc;
}