Fix moor_flutter example

This commit is contained in:
Simon Binder 2021-03-31 10:05:11 +02:00
parent eb39738460
commit 0692182829
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
7 changed files with 19 additions and 16 deletions

View File

@ -19,14 +19,14 @@ class TodoAppBloc {
final BehaviorSubject<Category> _activeCategory =
BehaviorSubject.seeded(null);
Observable<List<EntryWithCategory>> _currentEntries;
Stream<List<EntryWithCategory>> _currentEntries;
/// A stream of entries that should be displayed on the home screen.
Observable<List<EntryWithCategory>> get homeScreenEntries => _currentEntries;
Stream<List<EntryWithCategory>> get homeScreenEntries => _currentEntries;
final BehaviorSubject<List<CategoryWithActiveInfo>> _allCategories =
BehaviorSubject();
Observable<List<CategoryWithActiveInfo>> get categories => _allCategories;
Stream<List<CategoryWithActiveInfo>> get categories => _allCategories;
TodoAppBloc() : db = Database() {
// listen for the category to change. Then display all entries that are in
@ -35,7 +35,7 @@ class TodoAppBloc {
// also watch all categories so that they can be displayed in the navigation
// drawer.
Observable.combineLatest2<List<CategoryWithCount>, Category,
Rx.combineLatest2<List<CategoryWithCount>, Category,
List<CategoryWithActiveInfo>>(
db.categoriesWithCount(),
_activeCategory,

View File

@ -126,7 +126,7 @@ class Database extends _$Database {
return rows.map((row) {
return EntryWithCategory(
row.readTable(todos),
row.readTable(categories),
row.readTableOrNull(categories),
);
}).toList();
});

View File

@ -503,9 +503,9 @@ abstract class _$Database extends GeneratedDatabase {
variables: [],
readsFrom: {categories, todos}).map((QueryRow row) {
return CategoriesWithCountResult(
id: row.readInt('id'),
desc: row.readString('desc'),
amount: row.readInt('amount'),
id: row.read<int>('id'),
desc: row.read<String>('desc'),
amount: row.read<int>('amount'),
);
});
}

View File

@ -50,7 +50,8 @@ class _AddCategoryDialogState extends State<AddCategoryDialog> {
void _addEntry() {
if (_controller.text.isNotEmpty) {
Provider.of<TodoAppBloc>(context).addCategory(_controller.text);
Provider.of<TodoAppBloc>(context, listen: false)
.addCategory(_controller.text);
Navigator.of(context).pop();
}
}

View File

@ -101,7 +101,7 @@ class _CategoryDrawerEntry extends StatelessWidget {
title: const Text('Delete'),
content: Text('Really delete category $title?'),
actions: <Widget>[
FlatButton(
TextButton(
child: const Text('Cancel'),
onPressed: () {
Navigator.pop(context, false);

View File

@ -21,7 +21,7 @@ class HomeScreenState extends State<HomeScreen> {
// been added
final TextEditingController controller = TextEditingController();
TodoAppBloc get bloc => Provider.of<TodoAppBloc>(context);
TodoAppBloc get bloc => Provider.of<TodoAppBloc>(context, listen: false);
@override
Widget build(BuildContext context) {
@ -33,6 +33,8 @@ class HomeScreenState extends State<HomeScreen> {
body: StreamBuilder<List<EntryWithCategory>>(
stream: bloc.homeScreenEntries,
builder: (context, snapshot) {
print(snapshot);
if (!snapshot.hasData) {
return const Align(
alignment: Alignment.center,

View File

@ -10,14 +10,14 @@ environment:
dependencies:
flutter:
sdk: flutter
provider: ^3.2.0
intl: ^0.16.0
rxdart: 0.21.0
moor_flutter: ^3.0.0
provider: ^5.0.0
intl: ^0.17.0
rxdart: ^0.26.0
moor_flutter: ^4.0.0
dev_dependencies:
build_runner:
moor_generator: ^3.2.0
moor_generator: ^4.0.0
flutter_test:
sdk: flutter