Commit 0611ee5

derdilla <derdilla06@gmail.com>
2023-05-19 10:49:47
add model test and cleanup
1 parent de5623e
Changed files (3)
lib/components/measurement_list.dart
@@ -9,8 +9,8 @@ import 'package:intl/intl.dart';
 import '../screens/add_measurement.dart';
 
 class MeasurementList extends StatelessWidget {
-  late final _tableElementsSizes;
-  late final _sideFlex;
+  late final List<int> _tableElementsSizes;
+  late final int _sideFlex;
 
   MeasurementList(BuildContext context, {super.key}) {
     if (MediaQuery.of(context).size.width < 1000) {
@@ -35,16 +35,16 @@ class MeasurementList extends StatelessWidget {
               final items = model.getLastX(30);
               return FutureBuilder<UnmodifiableListView<BloodPressureRecord>>(
                 future: items,
-                builder: (BuildContext context, AsyncSnapshot<UnmodifiableListView<BloodPressureRecord>> recordsSnapsot) {
-                  assert(recordsSnapsot.connectionState != ConnectionState.none);
+                builder: (BuildContext context, AsyncSnapshot<UnmodifiableListView<BloodPressureRecord>> recordsSnapshot) {
+                  assert(recordsSnapshot.connectionState != ConnectionState.none);
 
-                  if (recordsSnapsot.connectionState == ConnectionState.waiting) {
+                  if (recordsSnapshot.connectionState == ConnectionState.waiting) {
                     return const Text('loading...');
                   } else {
-                    if (recordsSnapsot.hasError) {
-                      return Text('Error loading data:\n${recordsSnapsot.error}');
+                    if (recordsSnapshot.hasError) {
+                      return Text('Error loading data:\n${recordsSnapshot.error}');
                     } else {
-                      final data = recordsSnapsot.data ?? [];
+                      final data = recordsSnapshot.data ?? [];
                       if (data.isNotEmpty && data.first.diastolic > 0) {
                         return ListView.builder(
                             itemCount: data.length,
@@ -131,52 +131,50 @@ class MeasurementList extends StatelessWidget {
   Widget buildTableHeader(BuildContext context) {
     return Consumer<Settings>(
         builder: (context, settings, child) {
-          return Container(
-            child: Column (
-                children: [
-                  const SizedBox(height: 15 ),
-                  Row(
-                    children: [
-                      Expanded(
-                        flex: _sideFlex,
-                        child: SizedBox(),
-                      ),
-                      Expanded(
-                          flex: _tableElementsSizes[0],
-                          child: const Text("time", style: TextStyle(fontWeight: FontWeight.bold))
-                      ),
-                      Expanded(
-                          flex: _tableElementsSizes[1],
-                          child: Text("sys",
-                              style: TextStyle(fontWeight: FontWeight.bold, color: settings.sysColor))
-                      ),
-                      Expanded(
-                          flex: _tableElementsSizes[2],
-                          child: Text("dia",
-                              style: TextStyle(fontWeight: FontWeight.bold, color: settings.diaColor))
-                      ),
-                      Expanded(
-                          flex: _tableElementsSizes[3],
-                          child: Text("pul",
-                              style: TextStyle(fontWeight: FontWeight.bold, color: settings.pulColor))
-                      ),
-                      Expanded(
-                          flex: _tableElementsSizes[4],
-                          child: const Text("notes", style: TextStyle(fontWeight: FontWeight.bold))
-                      ),
-                      Expanded(
-                        flex: _sideFlex,
-                        child: SizedBox(),
-                      ),
-                    ],
-                  ),
-                  Divider(
-                    height: 20,
-                    thickness: 2,
-                    color: Theme.of(context).primaryColor,
-                  )
-                ]
-            ),
+          return Column (
+              children: [
+                const SizedBox(height: 15 ),
+                Row(
+                  children: [
+                    Expanded(
+                      flex: _sideFlex,
+                      child: const SizedBox(),
+                    ),
+                    Expanded(
+                        flex: _tableElementsSizes[0],
+                        child: const Text("time", style: TextStyle(fontWeight: FontWeight.bold))
+                    ),
+                    Expanded(
+                        flex: _tableElementsSizes[1],
+                        child: Text("sys",
+                            style: TextStyle(fontWeight: FontWeight.bold, color: settings.sysColor))
+                    ),
+                    Expanded(
+                        flex: _tableElementsSizes[2],
+                        child: Text("dia",
+                            style: TextStyle(fontWeight: FontWeight.bold, color: settings.diaColor))
+                    ),
+                    Expanded(
+                        flex: _tableElementsSizes[3],
+                        child: Text("pul",
+                            style: TextStyle(fontWeight: FontWeight.bold, color: settings.pulColor))
+                    ),
+                    Expanded(
+                        flex: _tableElementsSizes[4],
+                        child: const Text("notes", style: TextStyle(fontWeight: FontWeight.bold))
+                    ),
+                    Expanded(
+                      flex: _sideFlex,
+                      child: const SizedBox(),
+                    ),
+                  ],
+                ),
+                Divider(
+                  height: 20,
+                  thickness: 2,
+                  color: Theme.of(context).primaryColor,
+                )
+              ]
           );
         });
   }
lib/main.dart
@@ -28,7 +28,7 @@ class AppRoot extends StatelessWidget {
   Widget build(BuildContext context) {
     return Consumer<Settings>(
         builder: (context, settings, child) {
-          late var mode;
+          late final ThemeMode mode;
           if (settings.followSystemDarkMode) {
             mode = ThemeMode.system;
           } else if (settings.darkMode) {
test/model/bood_pressure_test.dart
@@ -103,5 +103,19 @@ void main() {
         expect(success, true);
       });
     });
+
+    test('should delete', () async {
+      var m = await BloodPressureModel.create(dbPath: '/tmp/bp_test/should_delete');
+
+      await m.add(BloodPressureRecord(DateTime.fromMillisecondsSinceEpoch(758934), 123, 87, 65, ';)'));
+      expect((await m.getLastX(100)).length, 1);
+      expect((await m.getInTimeRange(DateTime.fromMillisecondsSinceEpoch(0), DateTime.now())).length, 1);
+
+      await m.delete(DateTime.fromMillisecondsSinceEpoch(758934));
+
+      expect((await m.getLastX(100)).length, 0);
+      expect((await m.getInTimeRange(DateTime.fromMillisecondsSinceEpoch(0), DateTime.now())).length, 0);
+
+    });
   });
 }
\ No newline at end of file