|
1 |
| -// Copyright 2018 The Flutter Architecture Sample Authors. All rights reserved. |
2 |
| -// Use of this source code is governed by the MIT license that can be found |
3 |
| -// in the LICENSE file. |
4 |
| - |
5 |
| -import 'package:bloc/bloc.dart'; |
6 |
| -import 'package:bloc_library/blocs/blocs.dart'; |
7 |
| -import 'package:bloc_library/localization.dart'; |
8 |
| -import 'package:bloc_library/models/models.dart'; |
9 |
| -import 'package:bloc_library/screens/screens.dart'; |
10 |
| -import 'package:flutter/material.dart'; |
11 |
| -import 'package:flutter_bloc/flutter_bloc.dart'; |
12 |
| -import 'package:path_provider/path_provider.dart'; |
13 |
| -import 'package:todos_app_core/todos_app_core.dart'; |
| 1 | +import 'package:bloc_library/run_app.dart'; |
| 2 | +import 'package:flutter/cupertino.dart'; |
| 3 | +import 'package:key_value_store_flutter/key_value_store_flutter.dart'; |
| 4 | +import 'package:shared_preferences/shared_preferences.dart'; |
14 | 5 | import 'package:todos_repository_simple/todos_repository_simple.dart';
|
15 | 6 |
|
16 |
| -void main() { |
17 |
| - // BlocSupervisor oversees Blocs and delegates to BlocDelegate. |
18 |
| - // We can set the BlocSupervisor's delegate to an instance of `SimpleBlocDelegate`. |
19 |
| - // This will allow us to handle all transitions and errors in SimpleBlocDelegate. |
20 |
| - BlocSupervisor.delegate = SimpleBlocDelegate(); |
21 |
| - runApp( |
22 |
| - BlocProvider( |
23 |
| - create: (context) { |
24 |
| - return TodosBloc( |
25 |
| - todosRepository: const TodosRepositoryFlutter( |
26 |
| - fileStorage: FileStorage( |
27 |
| - '__flutter_bloc_app__', |
28 |
| - getApplicationDocumentsDirectory, |
29 |
| - ), |
30 |
| - ), |
31 |
| - )..add(LoadTodos()); |
32 |
| - }, |
33 |
| - child: TodosApp(), |
34 |
| - ), |
35 |
| - ); |
36 |
| -} |
| 7 | +Future<void> main() async { |
| 8 | + WidgetsFlutterBinding.ensureInitialized(); |
37 | 9 |
|
38 |
| -class TodosApp extends StatelessWidget { |
39 |
| - @override |
40 |
| - Widget build(BuildContext context) { |
41 |
| - final todosBloc = BlocProvider.of<TodosBloc>(context); |
42 |
| - return MaterialApp( |
43 |
| - onGenerateTitle: (context) => |
44 |
| - FlutterBlocLocalizations.of(context).appTitle, |
45 |
| - theme: ArchSampleTheme.theme, |
46 |
| - localizationsDelegates: [ |
47 |
| - ArchSampleLocalizationsDelegate(), |
48 |
| - FlutterBlocLocalizationsDelegate(), |
49 |
| - ], |
50 |
| - routes: { |
51 |
| - ArchSampleRoutes.home: (context) { |
52 |
| - return MultiBlocProvider( |
53 |
| - providers: [ |
54 |
| - BlocProvider<TabBloc>( |
55 |
| - create: (context) => TabBloc(), |
56 |
| - ), |
57 |
| - BlocProvider<FilteredTodosBloc>( |
58 |
| - create: (context) => FilteredTodosBloc(todosBloc: todosBloc), |
59 |
| - ), |
60 |
| - BlocProvider<StatsBloc>( |
61 |
| - create: (context) => StatsBloc(todosBloc: todosBloc), |
62 |
| - ), |
63 |
| - ], |
64 |
| - child: HomeScreen(), |
65 |
| - ); |
66 |
| - }, |
67 |
| - ArchSampleRoutes.addTodo: (context) { |
68 |
| - return AddEditScreen( |
69 |
| - key: ArchSampleKeys.addTodoScreen, |
70 |
| - onSave: (task, note) { |
71 |
| - todosBloc.add( |
72 |
| - AddTodo(Todo(task, note: note)), |
73 |
| - ); |
74 |
| - }, |
75 |
| - isEditing: false, |
76 |
| - ); |
77 |
| - }, |
78 |
| - }, |
79 |
| - ); |
80 |
| - } |
| 10 | + runBlocLibraryApp(LocalStorageRepository( |
| 11 | + localStorage: LocalStorage( |
| 12 | + 'bloc_library', |
| 13 | + FlutterKeyValueStore(await SharedPreferences.getInstance()), |
| 14 | + ), |
| 15 | + )); |
81 | 16 | }
|
0 commit comments