Skip to content

Commit

Permalink
Add user ID
Browse files Browse the repository at this point in the history
  • Loading branch information
ferndot committed Mar 20, 2020
1 parent 1af7f1c commit 6e5567c
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 9 deletions.
9 changes: 7 additions & 2 deletions lib/src/blocs/checkup/checkup_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import 'dart:async';

import 'package:flutter_bloc/flutter_bloc.dart';

import 'package:coronavirus_diary/src/blocs/preferences/preferences.dart';
import 'package:coronavirus_diary/src/data/models/checkups.dart';
import 'checkup.dart';

export 'package:coronavirus_diary/src/data/models/checkups.dart';

class CheckupBloc extends Bloc<CheckupEvent, CheckupState> {
CheckupBloc();
final PreferencesState preferencesState;

CheckupBloc({this.preferencesState});

@override
CheckupState get initialState => CheckupStateNotCreated();
Expand All @@ -35,7 +38,9 @@ class CheckupBloc extends Bloc<CheckupEvent, CheckupState> {
// Create checkup using API
yield CheckupStateCreating();
yield CheckupStateInProgress(
checkup: Checkup(),
checkup: Checkup(
userId: preferencesState.preferences.userId,
),
);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/src/data/models/checkups.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ part 'checkups.g.dart';
@JsonSerializable()
class Checkup {
String id;
String userId;
DateTime created;
bool dataContributionPreference;
CheckupLocation location;
Expand All @@ -13,6 +14,7 @@ class Checkup {

Checkup({
this.id,
this.userId,
this.created,
dataContributionPreference,
this.location,
Expand Down
2 changes: 2 additions & 0 deletions lib/src/data/models/checkups.g.dart

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

16 changes: 14 additions & 2 deletions lib/src/data/models/preferences.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:uuid/uuid.dart';
import 'package:uuid/uuid_util.dart';

part 'preferences.g.dart';

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

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

Preferences.clone(Preferences preferences)
: this(
userId: preferences.userId,
);

factory Preferences.fromJson(Map<String, dynamic> json) =>
_$PreferencesFromJson(json);
Expand Down
8 changes: 6 additions & 2 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.

11 changes: 8 additions & 3 deletions lib/src/ui/screens/checkup/checkup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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/preferences/preferences.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';
Expand All @@ -14,9 +15,13 @@ class CheckupScreen extends StatelessWidget {
Widget build(BuildContext context) {
// Initializing the bloc provider here so that the bloc is
// accessible to all functions in the checkup screen body
return BlocProvider<CheckupBloc>(
create: (context) => CheckupBloc(),
child: CheckupScreenBody(),
return BlocBuilder<PreferencesBloc, PreferencesState>(
builder: (context, state) {
return BlocProvider<CheckupBloc>(
create: (context) => CheckupBloc(preferencesState: state),
child: CheckupScreenBody(),
);
},
);
}
}
Expand Down
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
uuid:
dependency: "direct main"
description:
name: uuid
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.4"
vector_math:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies:
path_provider: ^1.6.5
path: ^1.6.4
provider: ^4.0.4
uuid: ^2.0.4

dev_dependencies:
build_runner: ^1.8.0
Expand Down

0 comments on commit 6e5567c

Please sign in to comment.