@@ -7,16 +7,18 @@ import '../main.dart';
77import '../models/benchmark_item.dart' ;
88import '../powersync.dart' ;
99
10+ var itemIndex = 1 ;
11+
1012class BenchmarkItemsPage extends StatelessWidget {
1113 const BenchmarkItemsPage ({super .key});
1214
1315 @override
1416 Widget build (BuildContext context) {
1517 const content = BenchmarkItemsWidget ();
1618
17- final button = FloatingActionButton (
19+ final addButton = FloatingActionButton (
1820 onPressed: () {
19- BenchmarkItem .create ('Benchmarks ' );
21+ BenchmarkItem .create ('Latency test ${ itemIndex ++} ' );
2022 },
2123 tooltip: 'Create Item' ,
2224 child: const Icon (Icons .add),
@@ -25,7 +27,7 @@ class BenchmarkItemsPage extends StatelessWidget {
2527 final page = MyHomePage (
2628 title: 'Benchmarks' ,
2729 content: content,
28- floatingActionButton: button ,
30+ floatingActionButton: addButton ,
2931 );
3032 return page;
3133 }
@@ -44,7 +46,9 @@ class _BenchmarkItemsWidgetState extends State<BenchmarkItemsWidget> {
4446 List <BenchmarkItem > _data = [];
4547 bool hasSynced = false ;
4648 StreamSubscription ? _subscription;
49+ StreamSubscription ? _countSubscription;
4750 StreamSubscription ? _syncStatusSubscription;
51+ int ? count;
4852
4953 _BenchmarkItemsWidgetState ();
5054
@@ -60,6 +64,15 @@ class _BenchmarkItemsWidgetState extends State<BenchmarkItemsWidget> {
6064 _data = data;
6165 });
6266 });
67+ _countSubscription =
68+ db.watch ('select count() as count from ps_oplog' ).listen ((data) {
69+ if (! context.mounted) {
70+ return ;
71+ }
72+ setState (() {
73+ count = data.first['count' ];
74+ });
75+ });
6376 _syncStatusSubscription = db.statusStream.listen ((status) {
6477 if (! context.mounted) {
6578 return ;
@@ -75,17 +88,55 @@ class _BenchmarkItemsWidgetState extends State<BenchmarkItemsWidget> {
7588 super .dispose ();
7689 _subscription? .cancel ();
7790 _syncStatusSubscription? .cancel ();
91+ _countSubscription? .cancel ();
7892 }
7993
8094 @override
8195 Widget build (BuildContext context) {
82- return ! hasSynced
83- ? const Text ("Busy with sync..." )
84- : ListView (
96+ Duration ? syncDuration = timer.syncTime ?? timer.elapsed;
97+ if (! hasSynced) {
98+ return Center (
99+ child: Text (
100+ "Busy with sync... ${syncDuration .inMilliseconds }ms / $count operations" ));
101+ }
102+
103+ final clearButton = TextButton .icon (
104+ label: const Text ('Delete all' ),
105+ onPressed: () {
106+ BenchmarkItem .deleteAll ();
107+ },
108+ icon: const Icon (Icons .delete));
109+
110+ final resyncButton = TextButton .icon (
111+ label: const Text ('Resync' ),
112+ onPressed: () async {
113+ await resync ();
114+ },
115+ icon: const Icon (Icons .sync ));
116+
117+ var buttons = Padding (
118+ padding: const EdgeInsets .all (8.0 ),
119+ child: OverflowBar (
120+ alignment: MainAxisAlignment .end,
121+ spacing: 8.0 ,
122+ overflowSpacing: 8.0 ,
123+ children: < Widget > [
124+ Text (
125+ 'First sync duration: ${syncDuration .inMilliseconds }ms / $count operations' ),
126+ resyncButton,
127+ clearButton,
128+ ],
129+ ),
130+ );
131+ return Column (children: [
132+ buttons,
133+ Expanded (
134+ child: ListView (
85135 padding: const EdgeInsets .symmetric (vertical: 8.0 ),
86136 children: _data.map ((list) {
87137 return ListItemWidget (item: list);
88- }).toList (),
89- );
138+ }).toList ()),
139+ )
140+ ]);
90141 }
91142}
0 commit comments