-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,477 additions
and
1,147 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
kitchenowl/lib/cubits/household_add_update/household_settings_items_cubit.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:kitchenowl/models/category.dart'; | ||
import 'package:kitchenowl/models/household.dart'; | ||
import 'package:kitchenowl/models/item.dart'; | ||
import 'package:kitchenowl/services/api/api_service.dart'; | ||
import 'package:kitchenowl/services/transaction_handler.dart'; | ||
import 'package:kitchenowl/services/transactions/category.dart'; | ||
|
||
class HouseholdSettingsItemsCubit extends Cubit<HouseholdSettingsItemsState> { | ||
final Household household; | ||
|
||
HouseholdSettingsItemsCubit(this.household) | ||
: super(const LoadingHouseholdSettingsItemsState()) { | ||
refresh(); | ||
} | ||
|
||
Future<void> refresh() async { | ||
final items = ApiService.getInstance().getAllItems(household); | ||
final categories = TransactionHandler.getInstance().runTransaction( | ||
TransactionCategoriesGet(household: household), | ||
); | ||
if (await items != null) { | ||
emit(HouseholdSettingsItemsState( | ||
items: (await items)!, | ||
categories: await categories, | ||
)); | ||
} | ||
} | ||
} | ||
|
||
class HouseholdSettingsItemsState extends Equatable { | ||
final List<Item> items; | ||
final List<Category> categories; | ||
|
||
const HouseholdSettingsItemsState({ | ||
this.items = const [], | ||
this.categories = const [], | ||
}); | ||
|
||
@override | ||
List<Object?> get props => [items, categories]; | ||
} | ||
|
||
class LoadingHouseholdSettingsItemsState extends HouseholdSettingsItemsState { | ||
const LoadingHouseholdSettingsItemsState(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
extension ReadOrNull on BuildContext { | ||
T? readOrNull<T>() { | ||
try { | ||
return read<T>(); | ||
} on ProviderNotFoundException catch (_) { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.