diff --git a/README.md b/README.md index 685a536..bacb6c4 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,10 @@ ``` a1@toly ~ % flutter --version -Flutter 1.20.1 • channel stable • https://github.com/flutter/flutter.git -Framework • revision 2ae34518b8 (2 days ago) • 2020-08-05 19:53:19 -0700 -Engine • revision c8e3b94853 -Tools • Dart 2.9.0 +Flutter 1.20.3 • channel stable • https://github.com/flutter/flutter.git +Framework • revision 216dee60c0 (10 days ago) • 2020-09-01 12:24:47 -0700 +Engine • revision d1bc06f032 +Tools • Dart 2.9.2 ``` --- diff --git a/lib/views/app/bloc_wrapper.dart b/lib/views/app/bloc_wrapper.dart index a397143..fa01af6 100644 --- a/lib/views/app/bloc_wrapper.dart +++ b/lib/views/app/bloc_wrapper.dart @@ -14,14 +14,20 @@ import 'package:flutter_unit/storage/app_storage.dart'; final storage = AppStorage(); -class BlocWrapper extends StatelessWidget { +class BlocWrapper extends StatefulWidget { final Widget child; BlocWrapper({this.child}); - final repository = WidgetDbRepository(storage); - final categoryRepo = CategoryDbRepository(storage); + @override + _BlocWrapperState createState() => _BlocWrapperState(); +} +class _BlocWrapperState extends State { + final repository = WidgetDbRepository(storage); + + final categoryBloc = CategoryBloc(repository: CategoryDbRepository(storage)); + @override Widget build(BuildContext context) { return MultiBlocProvider(//使用MultiBlocProvider包裹 @@ -38,17 +44,26 @@ class BlocWrapper extends StatelessWidget { create: (_) => DetailBloc(repository: repository)), BlocProvider( - create: (_) => - CategoryBloc(repository: categoryRepo)..add(EventLoadCategory())), + create: (_) => categoryBloc..add(EventLoadCategory())), BlocProvider( create: (_) => CollectBloc(repository: repository)..add(EventSetCollectData())), + BlocProvider( + create: (_) => + CategoryWidgetBloc(categoryBloc: categoryBloc)), + BlocProvider( create: (_) => SearchBloc(repository: repository)), BlocProvider(create: (_) => PointBloc()), BlocProvider(create: (_) => PointCommentBloc()), - ], child: child); + ], child: widget.child); + } + + @override + void dispose() { + categoryBloc.close(); + super.dispose(); } } diff --git a/lib/views/app/flutter_unit.dart b/lib/views/app/flutter_unit.dart index e897d16..e831bb9 100644 --- a/lib/views/app/flutter_unit.dart +++ b/lib/views/app/flutter_unit.dart @@ -12,10 +12,7 @@ class FlutterUnit extends StatelessWidget { @override Widget build(BuildContext context) { return BlocBuilder(builder: (_, state) { - return BlocProvider( - create: (_) => CategoryWidgetBloc( - categoryBloc: BlocProvider.of(context)), - child: MaterialApp( + return MaterialApp( // debugShowMaterialGrid: true, showPerformanceOverlay: state.showPerformanceOverlay, // showSemanticsDebugger: true, @@ -28,7 +25,7 @@ class FlutterUnit extends StatelessWidget { primarySwatch: state.themeColor, fontFamily: state.fontFamily, ), - home: UnitSplash()), + home: UnitSplash(), ); }); } diff --git a/lib/views/common/loading_page.dart b/lib/views/common/loading_page.dart index f092842..df0662e 100644 --- a/lib/views/common/loading_page.dart +++ b/lib/views/common/loading_page.dart @@ -1,15 +1,15 @@ import 'package:flutter/material.dart'; class LoadingPage extends StatelessWidget { - - - @override Widget build(BuildContext context) { - return Container( + return Container( height: 300, alignment: Alignment.center, - child: CircularProgressIndicator(backgroundColor: Colors.blue,valueColor:AlwaysStoppedAnimation(Colors.orangeAccent) ,), + child: CircularProgressIndicator( + backgroundColor: Colors.blue, + valueColor: AlwaysStoppedAnimation(Colors.orangeAccent), + ), ); } }