-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathlists_page.dart
70 lines (61 loc) · 1.73 KB
/
lists_page.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import 'package:flutter/material.dart';
import 'package:powersync/powersync.dart';
import 'package:powersync_flutter_demo/widgets/guard_by_sync.dart';
import './list_item.dart';
import './list_item_dialog.dart';
import '../main.dart';
import '../models/todo_list.dart';
void _showAddDialog(BuildContext context) async {
return showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return const ListItemDialog();
},
);
}
class ListsPage extends StatelessWidget {
const ListsPage({super.key});
@override
Widget build(BuildContext context) {
const content = ListsWidget();
final button = FloatingActionButton(
onPressed: () {
_showAddDialog(context);
},
tooltip: 'Create List',
child: const Icon(Icons.add),
);
final page = MyHomePage(
title: 'Todo Lists',
content: content,
floatingActionButton: button,
);
return page;
}
}
final class ListsWidget extends StatelessWidget {
const ListsWidget({super.key});
@override
Widget build(BuildContext context) {
return GuardBySync(
priority: _listsPriority,
child: StreamBuilder(
stream: TodoList.watchListsWithStats(),
builder: (context, snapshot) {
if (snapshot.data case final todoLists?) {
return ListView(
padding: const EdgeInsets.symmetric(vertical: 8.0),
children: todoLists.map((list) {
return ListItemWidget(list: list);
}).toList(),
);
} else {
return const CircularProgressIndicator();
}
},
),
);
}
static final _listsPriority = BucketPriority(1);
}