diff --git a/lib/src/app.dart b/lib/src/app.dart index 430b3ed..3377f94 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -23,7 +23,7 @@ class DiaryApp extends StatelessWidget { create: (context) { return QuestionsBloc( questionsRepository: QuestionsRepository(), - ); + )..add(LoadQuestions()); }, ), ], diff --git a/lib/src/ui/screens/checkup/checkup.dart b/lib/src/ui/screens/checkup/checkup.dart index 7d93a2c..e90a490 100644 --- a/lib/src/ui/screens/checkup/checkup.dart +++ b/lib/src/ui/screens/checkup/checkup.dart @@ -3,7 +3,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:provider/provider.dart'; import 'package:coronavirus_diary/src/blocs/checkup/checkup.dart'; -import 'package:coronavirus_diary/src/blocs/questions/questions.dart'; import 'package:coronavirus_diary/src/ui/widgets/loading_indicator.dart'; import 'checkup_loaded_body.dart'; @@ -33,52 +32,33 @@ class _CheckupScreenState extends State { Widget _getUnloadedBody( CheckupState checkupState, - QuestionsState questionsState, ) { - if (questionsState is QuestionsStateNotLoaded) { - context.bloc().add(LoadQuestions()); - } if (checkupState is CheckupStateNotCreated) { context.bloc().add(StartCheckup()); } return LoadingIndicator('Loading your health checkup'); } - Widget _getErrorBody(QuestionsState state) { - Widget errorBody; - - if (state is QuestionsStateLoaded && state.questions.length == 0) { - errorBody = Text( - 'The checkup experience is not currently available. Please try again later.', - textAlign: TextAlign.center, - ); - } else { - errorBody = Text( - 'There was an error retrieving the checkup experience. Please try again later.', - textAlign: TextAlign.center, - ); - } - + Widget _getErrorBody() { return Center( child: Padding( padding: EdgeInsets.all(20), - child: errorBody, + child: Text( + 'There was an error retrieving the checkup experience. Please try again later.', + textAlign: TextAlign.center, + ), ), ); } - Widget _getBody(CheckupState checkupState, QuestionsState questionsState) { - if (questionsState is QuestionsStateNotLoaded || - questionsState is QuestionsStateLoading || - checkupState is CheckupStateNotCreated || + Widget _getBody(CheckupState checkupState) { + if (checkupState is CheckupStateNotCreated || checkupState is CheckupStateCreating) { - return _getUnloadedBody(checkupState, questionsState); - } else if (questionsState is QuestionsStateLoaded && - questionsState.questions.length > 0 && - checkupState is CheckupStateInProgress) { + return _getUnloadedBody(checkupState); + } else if (checkupState is CheckupStateInProgress) { return CheckupLoadedBody(); } else { - return _getErrorBody(questionsState); + return _getErrorBody(); } } @@ -88,24 +68,15 @@ class _CheckupScreenState extends State { builder: (context, state) { final CheckupState checkupState = state; - return BlocBuilder( - builder: (context, state) { - final QuestionsState questionsState = state; - - return ChangeNotifierProvider( - create: (context) => _pageController, - child: Scaffold( - appBar: AppBar( - title: Text('Your Health Checkup'), - ), - backgroundColor: Theme.of(context).primaryColor, - body: _getBody( - checkupState, - questionsState, - ), - ), - ); - }, + return ChangeNotifierProvider( + create: (context) => _pageController, + child: Scaffold( + appBar: AppBar( + title: Text('Your Health Checkup'), + ), + backgroundColor: Theme.of(context).primaryColor, + body: _getBody(checkupState), + ), ); }, );