Skip to content

Commit

Permalink
Save last assessment
Browse files Browse the repository at this point in the history
  • Loading branch information
ferndot committed Mar 21, 2020
1 parent 4a811a1 commit 2d170ad
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 28 deletions.
17 changes: 13 additions & 4 deletions lib/src/data/models/preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@ import 'package:json_annotation/json_annotation.dart';
import 'package:uuid/uuid.dart';
import 'package:uuid/uuid_util.dart';

import 'assessments.dart';

part 'preferences.g.dart';

@JsonSerializable()
class Preferences {
final String userId;
final Assessment lastAssessment;

Preferences({
userId,
this.lastAssessment,
}) : userId = userId ??
Uuid().v4(options: {
'grng': UuidUtil.cryptoRNG,
});

Preferences.clone(Preferences preferences)
: this(
userId: preferences.userId,
);
Preferences cloneWith({
Preferences preferences,
Assessment lastAssessment,
}) {
return Preferences(
userId: preferences.userId,
lastAssessment: lastAssessment ?? preferences.lastAssessment,
);
}

factory Preferences.fromJson(Map<String, dynamic> json) =>
_$PreferencesFromJson(json);
Expand Down
4 changes: 4 additions & 0 deletions lib/src/data/models/preferences.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 39 additions & 24 deletions lib/src/ui/screens/assessment/assessment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,53 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_hud/flutter_hud.dart';

import 'package:coronavirus_diary/src/blocs/checkup/checkup.dart';
import 'package:coronavirus_diary/src/blocs/preferences/preferences.dart';
import 'assessments/index.dart';
import 'share.dart';

class AssessmentScreen extends StatelessWidget {
static const routeName = '/assessment';

@override
Widget build(BuildContext context) {
return BlocBuilder<CheckupBloc, CheckupState>(
return BlocBuilder<PreferencesBloc, PreferencesState>(
builder: (context, state) {
Widget body;
if (state is CheckupStateInProgress) {
context.bloc<CheckupBloc>().add(CompleteCheckup());
} else if (state is CheckupStateCompleted) {
switch (state.assessment.matchesPuiSymptoms) {
case true:
body = PositiveAssessment();
break;
case false:
body = NegativeAssessment();
break;
}
}
return WidgetHUD(
showHUD: state is CheckupStateCompleting,
hud: HUD(label: 'Loading your assessment'),
builder: (context) {
return Scaffold(
appBar: AppBar(
title: Text('Your Personalized Assessment'),
),
body: body,
final PreferencesState preferencesState = state;

return BlocBuilder<CheckupBloc, CheckupState>(
builder: (context, state) {
Widget body;
if (state is CheckupStateInProgress) {
context.bloc<CheckupBloc>().add(CompleteCheckup());
} else if (state is CheckupStateCompleted) {
// Remember assessment
Preferences newPreferences =
preferencesState.preferences.cloneWith(
lastAssessment: state.assessment,
);
context
.bloc<PreferencesBloc>()
.add(UpdatePreferences(newPreferences));

switch (state.assessment.matchesPuiSymptoms) {
case true:
body = PositiveAssessment();
break;
case false:
body = NegativeAssessment();
break;
}
}
return WidgetHUD(
showHUD: state is CheckupStateCompleting,
hud: HUD(label: 'Loading your assessment'),
builder: (context) {
return Scaffold(
appBar: AppBar(
title: Text('Your Personalized Assessment'),
),
body: body,
);
},
);
},
);
Expand Down

0 comments on commit 2d170ad

Please sign in to comment.