Skip to content

Commit

Permalink
Apply automatic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
baylessj authored and actions-user committed Jan 26, 2020
1 parent 471bc8c commit 0a6e227
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
23 changes: 13 additions & 10 deletions lib/blocs/src/repeating/bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ class RepeatsBloc extends Bloc<RepeatsEvent, RepeatsState> {
];

RepeatsBloc({@required DatabaseBloc dbBloc, @required CarsBloc carsBloc})
: assert(dbBloc != null), assert(carsBloc != null),
_dbBloc = dbBloc, _carsBloc = carsBloc {
: assert(dbBloc != null),
assert(carsBloc != null),
_dbBloc = dbBloc,
_carsBloc = carsBloc {
_dbSubscription = _dbBloc.listen((state) {
if (state is DbLoaded) {
// if (state.newUser ?? false) {
// add(AddDefaultRepeats());
// } else {
add(LoadRepeats());
add(LoadRepeats());
// }
}
});
Expand Down Expand Up @@ -218,23 +220,24 @@ class RepeatsBloc extends Bloc<RepeatsEvent, RepeatsState> {
for (var r in defaults) {
batch.setData(r.toEntity().toDocument());
}
// need to wait on this, otherwise the "currentRepeats" call will return the
// need to wait on this, otherwise the "currentRepeats" call will return the
// old state
await batch.commit();
final updatedRepeats = await repo.getCurrentRepeats();
yield RepeatsLoaded(updatedRepeats);
}

Stream<RepeatsState> _mapRepeatCarsUpdatedToState(RepeatCarsUpdated event) async* {

Stream<RepeatsState> _mapRepeatCarsUpdatedToState(
RepeatCarsUpdated event) async* {
if (repo == null) {
print('Error: trying to update repeats for cars update but repo is null');
return;
}
final curRepeats = (state as RepeatsLoaded).repeats;
// gets the list of cars that do not yet have a repeat associated with them
List<Car> newCars = event.cars
.map((c) => (curRepeats.any((r) => r.cars.contains(c.name)) ? null : c))
.toList();
.map((c) => (curRepeats.any((r) => r.cars.contains(c.name)) ? null : c))
.toList();
if (newCars.length == 0) {
print('all cars have repeats, not adding defaults');
return;
Expand All @@ -245,8 +248,8 @@ class RepeatsBloc extends Bloc<RepeatsEvent, RepeatsState> {
batch.setData(r.copyWith(cars: [c.name]).toEntity().toDocument());
});
});
// need to wait on this, otherwise the "currentRepeats" call will return the

// need to wait on this, otherwise the "currentRepeats" call will return the
// old state
await batch.commit();
final updatedRepeats = await repo.getCurrentRepeats();
Expand Down
4 changes: 2 additions & 2 deletions lib/blocs/src/repeating/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class RepeatCarsUpdated extends RepeatsEvent {

const RepeatCarsUpdated(this.cars);

@override
@override
List<Object> get props => [cars];

@override
@override
String toString() => 'Repeat Cars Updated { cars: $cars }';
}
12 changes: 6 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ void run(bool integrationTest) async {
)..add(LoadRepeats()),
child: BlocProvider<TodosBloc>(
create: (context) => TodosBloc(
dbBloc: BlocProvider.of<DatabaseBloc>(context),
notificationsBloc:
BlocProvider.of<NotificationsBloc>(context),
carsBloc: BlocProvider.of<CarsBloc>(context),
repeatsBloc: BlocProvider.of<RepeatsBloc>(context))
..add(LoadTodos()),
dbBloc: BlocProvider.of<DatabaseBloc>(context),
notificationsBloc:
BlocProvider.of<NotificationsBloc>(context),
carsBloc: BlocProvider.of<CarsBloc>(context),
repeatsBloc: BlocProvider.of<RepeatsBloc>(context))
..add(LoadTodos()),
child: App(
theme: theme,
authRepository: authRepository,
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/home/widgets/repeat_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class RepeatCard extends StatelessWidget {
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
_RepeatTitle(repeat),
Row(
children: [
Row(
children: [
CarTag(text: repeat.cars.first, color: Color(0xffffffff)),
Row(
mainAxisAlignment: MainAxisAlignment.end,
Expand Down

0 comments on commit 0a6e227

Please sign in to comment.