mirror of https://github.com/AMT-Cheif/drift.git
Fix moor_flutter example
This commit is contained in:
parent
eb39738460
commit
0692182829
|
@ -19,14 +19,14 @@ class TodoAppBloc {
|
||||||
final BehaviorSubject<Category> _activeCategory =
|
final BehaviorSubject<Category> _activeCategory =
|
||||||
BehaviorSubject.seeded(null);
|
BehaviorSubject.seeded(null);
|
||||||
|
|
||||||
Observable<List<EntryWithCategory>> _currentEntries;
|
Stream<List<EntryWithCategory>> _currentEntries;
|
||||||
|
|
||||||
/// A stream of entries that should be displayed on the home screen.
|
/// 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 =
|
final BehaviorSubject<List<CategoryWithActiveInfo>> _allCategories =
|
||||||
BehaviorSubject();
|
BehaviorSubject();
|
||||||
Observable<List<CategoryWithActiveInfo>> get categories => _allCategories;
|
Stream<List<CategoryWithActiveInfo>> get categories => _allCategories;
|
||||||
|
|
||||||
TodoAppBloc() : db = Database() {
|
TodoAppBloc() : db = Database() {
|
||||||
// listen for the category to change. Then display all entries that are in
|
// 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
|
// also watch all categories so that they can be displayed in the navigation
|
||||||
// drawer.
|
// drawer.
|
||||||
Observable.combineLatest2<List<CategoryWithCount>, Category,
|
Rx.combineLatest2<List<CategoryWithCount>, Category,
|
||||||
List<CategoryWithActiveInfo>>(
|
List<CategoryWithActiveInfo>>(
|
||||||
db.categoriesWithCount(),
|
db.categoriesWithCount(),
|
||||||
_activeCategory,
|
_activeCategory,
|
||||||
|
|
|
@ -126,7 +126,7 @@ class Database extends _$Database {
|
||||||
return rows.map((row) {
|
return rows.map((row) {
|
||||||
return EntryWithCategory(
|
return EntryWithCategory(
|
||||||
row.readTable(todos),
|
row.readTable(todos),
|
||||||
row.readTable(categories),
|
row.readTableOrNull(categories),
|
||||||
);
|
);
|
||||||
}).toList();
|
}).toList();
|
||||||
});
|
});
|
||||||
|
|
|
@ -503,9 +503,9 @@ abstract class _$Database extends GeneratedDatabase {
|
||||||
variables: [],
|
variables: [],
|
||||||
readsFrom: {categories, todos}).map((QueryRow row) {
|
readsFrom: {categories, todos}).map((QueryRow row) {
|
||||||
return CategoriesWithCountResult(
|
return CategoriesWithCountResult(
|
||||||
id: row.readInt('id'),
|
id: row.read<int>('id'),
|
||||||
desc: row.readString('desc'),
|
desc: row.read<String>('desc'),
|
||||||
amount: row.readInt('amount'),
|
amount: row.read<int>('amount'),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,8 @@ class _AddCategoryDialogState extends State<AddCategoryDialog> {
|
||||||
|
|
||||||
void _addEntry() {
|
void _addEntry() {
|
||||||
if (_controller.text.isNotEmpty) {
|
if (_controller.text.isNotEmpty) {
|
||||||
Provider.of<TodoAppBloc>(context).addCategory(_controller.text);
|
Provider.of<TodoAppBloc>(context, listen: false)
|
||||||
|
.addCategory(_controller.text);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@ class _CategoryDrawerEntry extends StatelessWidget {
|
||||||
title: const Text('Delete'),
|
title: const Text('Delete'),
|
||||||
content: Text('Really delete category $title?'),
|
content: Text('Really delete category $title?'),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
FlatButton(
|
TextButton(
|
||||||
child: const Text('Cancel'),
|
child: const Text('Cancel'),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context, false);
|
Navigator.pop(context, false);
|
||||||
|
|
|
@ -21,7 +21,7 @@ class HomeScreenState extends State<HomeScreen> {
|
||||||
// been added
|
// been added
|
||||||
final TextEditingController controller = TextEditingController();
|
final TextEditingController controller = TextEditingController();
|
||||||
|
|
||||||
TodoAppBloc get bloc => Provider.of<TodoAppBloc>(context);
|
TodoAppBloc get bloc => Provider.of<TodoAppBloc>(context, listen: false);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -33,6 +33,8 @@ class HomeScreenState extends State<HomeScreen> {
|
||||||
body: StreamBuilder<List<EntryWithCategory>>(
|
body: StreamBuilder<List<EntryWithCategory>>(
|
||||||
stream: bloc.homeScreenEntries,
|
stream: bloc.homeScreenEntries,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
|
print(snapshot);
|
||||||
|
|
||||||
if (!snapshot.hasData) {
|
if (!snapshot.hasData) {
|
||||||
return const Align(
|
return const Align(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
|
|
|
@ -10,14 +10,14 @@ environment:
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
provider: ^3.2.0
|
provider: ^5.0.0
|
||||||
intl: ^0.16.0
|
intl: ^0.17.0
|
||||||
rxdart: 0.21.0
|
rxdart: ^0.26.0
|
||||||
moor_flutter: ^3.0.0
|
moor_flutter: ^4.0.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
build_runner:
|
build_runner:
|
||||||
moor_generator: ^3.2.0
|
moor_generator: ^4.0.0
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue