Commit 7eb298a

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2024-04-02 08:46:38
provide repositories
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent 8312250
app/lib/main.dart
@@ -12,8 +12,10 @@ import 'package:blood_pressure_app/model/storage/update_legacy_settings.dart';
 import 'package:blood_pressure_app/screens/home_screen.dart';
 import 'package:blood_pressure_app/screens/loading_screen.dart';
 import 'package:flutter/material.dart';
+import 'package:flutter_bloc/flutter_bloc.dart';
 import 'package:flutter_gen/gen_l10n/app_localizations.dart';
 import 'package:fluttertoast/fluttertoast.dart';
+import 'package:health_data_store/health_data_store.dart';
 import 'package:package_info_plus/package_info_plus.dart';
 import 'package:path/path.dart';
 import 'package:provider/provider.dart';
@@ -24,9 +26,9 @@ late final BloodPressureModel _bloodPressureModel;
 
 void main() async {
   runApp(ConsistentFutureBuilder(
-      future: _loadApp(),
-      onWaiting: const LoadingScreen(),
-      onData: (context, widget) => widget,
+    future: _loadApp(),
+    onWaiting: const LoadingScreen(),
+    onData: (context, widget) => widget,
   ),);
 }
 
@@ -63,6 +65,11 @@ Future<Widget> _loadApp() async {
     File(join(await getDatabasesPath(), 'medicine.intakes')).writeAsStringSync(intakeHistory.serialize());
   });
 
+  final db = await HealthDataStore.load(await openDatabase(
+    join(await getDatabasesPath(), 'bp.db'),
+  ),);
+  // TODO: document
+
   // update logic
   if (settings.lastVersion == 0) {
     await updateLegacySettings(settings, exportSettings, csvExportSettings, pdfExportSettings, intervalStorageManager);
@@ -88,7 +95,8 @@ Future<Widget> _loadApp() async {
   // Reset the step size intervall to current on startup
   intervalStorageManager.mainPage.setToMostRecentIntervall();
 
-  print(AppLocalizations.delegate);
+  // TODO: migrate old data and remove add methods
+  // TODO: fix navigation test failures
 
   return MultiProvider(providers: [
     ChangeNotifierProvider(create: (context) => _bloodPressureModel),
@@ -99,7 +107,15 @@ Future<Widget> _loadApp() async {
     ChangeNotifierProvider(create: (context) => intervalStorageManager),
     ChangeNotifierProvider(create: (context) => exportColumnsManager),
     ChangeNotifierProvider(create: (context) => intakeHistory),
-  ], child: const AppRoot(),);
+  ],
+  child: MultiRepositoryProvider(
+    providers: [
+      RepositoryProvider<BloodPressureRepository>(create: (_) => db.bpRepo),
+      RepositoryProvider<MedicineRepository>(create: (_) => db.medRepo),
+      RepositoryProvider<MedicineIntakeRepository>(create:(_) => db.intakeRepo),
+    ],
+    child: const AppRoot(),
+  ),);
 }
 
 /// Central [MaterialApp] widget of the app that sets the uniform style options.
@@ -109,24 +125,25 @@ class AppRoot extends StatelessWidget {
 
   @override
   Widget build(BuildContext context) =>
-    Consumer<Settings>(builder: (context, settings, child) => MaterialApp(
-      title: 'Blood Pressure App',
-      onGenerateTitle: (context) => AppLocalizations.of(context)!.title,
-      theme: _buildTheme(ColorScheme.fromSeed(
-        seedColor: settings.accentColor,
-      ),),
-      darkTheme: _buildTheme(ColorScheme.fromSeed(
-        seedColor: settings.accentColor,
-        brightness: Brightness.dark,
-        background: Colors.black,
-      ),),
-      themeMode: settings.themeMode,
-      localizationsDelegates: AppLocalizations.localizationsDelegates,
-      supportedLocales: AppLocalizations.supportedLocales,
-      locale: settings.language,
-      home: const AppHome(),
-    ),
-  );
+      Consumer<Settings>(builder: (context, settings, child) =>
+          MaterialApp(
+            title: 'Blood Pressure App',
+            onGenerateTitle: (context) => AppLocalizations.of(context)!.title,
+            theme: _buildTheme(ColorScheme.fromSeed(
+              seedColor: settings.accentColor,
+            ),),
+            darkTheme: _buildTheme(ColorScheme.fromSeed(
+              seedColor: settings.accentColor,
+              brightness: Brightness.dark,
+              background: Colors.black,
+            ),),
+            themeMode: settings.themeMode,
+            localizationsDelegates: AppLocalizations.localizationsDelegates,
+            supportedLocales: AppLocalizations.supportedLocales,
+            locale: settings.language,
+            home: const AppHome(),
+          ),
+      );
 
   ThemeData _buildTheme(ColorScheme colorScheme) {
     final inputBorder = OutlineInputBorder(
@@ -167,6 +184,7 @@ class AppRoot extends StatelessWidget {
 }
 
 bool _isDatabaseClosed = false;
+
 /// Close all connections to the databases and remove all listeners from provided objects.
 ///
 /// The app will most likely stop working after invoking this.
app/windows/flutter/generated_plugin_registrant.cc
@@ -6,9 +6,12 @@
 
 #include "generated_plugin_registrant.h"
 
+#include <permission_handler_windows/permission_handler_windows_plugin.h>
 #include <url_launcher_windows/url_launcher_windows.h>
 
 void RegisterPlugins(flutter::PluginRegistry* registry) {
+  PermissionHandlerWindowsPluginRegisterWithRegistrar(
+      registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
   UrlLauncherWindowsRegisterWithRegistrar(
       registry->GetRegistrarForPlugin("UrlLauncherWindows"));
 }
app/windows/flutter/generated_plugins.cmake
@@ -3,6 +3,7 @@
 #
 
 list(APPEND FLUTTER_PLUGIN_LIST
+  permission_handler_windows
   url_launcher_windows
 )
 
app/pubspec.lock
@@ -57,6 +57,14 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "2.0.10"
+  bloc:
+    dependency: transitive
+    description:
+      name: bloc
+      sha256: "106842ad6569f0b60297619e9e0b1885c2fb9bf84812935490e6c5275777804e"
+      url: "https://pub.dev"
+    source: hosted
+    version: "8.1.4"
   boolean_selector:
     dependency: transitive
     description:
@@ -222,6 +230,14 @@ packages:
     description: flutter
     source: sdk
     version: "0.0.0"
+  flutter_bloc:
+    dependency: "direct main"
+    description:
+      name: flutter_bloc
+      sha256: f0ecf6e6eb955193ca60af2d5ca39565a86b8a142452c5b24d96fb477428f4d2
+      url: "https://pub.dev"
+    source: hosted
+    version: "8.1.5"
   flutter_lints:
     dependency: "direct dev"
     description:
@@ -251,6 +267,14 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "2.0.17"
+  flutter_reactive_ble:
+    dependency: "direct main"
+    description:
+      name: flutter_reactive_ble
+      sha256: "247e2efa76de203d1ba11335c13754b5b9d0504b5423e5b0c93a600f016b24e0"
+      url: "https://pub.dev"
+    source: hosted
+    version: "5.3.1"
   flutter_test:
     dependency: "direct dev"
     description: flutter
@@ -269,6 +293,14 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "8.2.4"
+  freezed_annotation:
+    dependency: transitive
+    description:
+      name: freezed_annotation
+      sha256: c3fd9336eb55a38cc1bbd79ab17573113a8deccd0ecbbf926cca3c62803b5c2d
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.4.1"
   function_tree:
     dependency: "direct main"
     description:
@@ -277,6 +309,14 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "0.9.1"
+  functional_data:
+    dependency: transitive
+    description:
+      name: functional_data
+      sha256: aefdec4365452283b2a7cf420a3169654d51d3e9553069a22d76680d7a9d7c3d
+      url: "https://pub.dev"
+    source: hosted
+    version: "1.1.1"
   glob:
     dependency: transitive
     description:
@@ -285,6 +325,13 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "2.1.2"
+  health_data_store:
+    dependency: "direct main"
+    description:
+      path: "../health_data_store"
+      relative: true
+    source: path
+    version: "0.1.0+1"
   http:
     dependency: transitive
     description:
@@ -333,6 +380,14 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "1.3.0"
+  json_annotation:
+    dependency: transitive
+    description:
+      name: json_annotation
+      sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467
+      url: "https://pub.dev"
+    source: hosted
+    version: "4.8.1"
   leak_tracker:
     dependency: transitive
     description:
@@ -493,6 +548,54 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "3.10.8"
+  permission_handler:
+    dependency: "direct main"
+    description:
+      name: permission_handler
+      sha256: "18bf33f7fefbd812f37e72091a15575e72d5318854877e0e4035a24ac1113ecb"
+      url: "https://pub.dev"
+    source: hosted
+    version: "11.3.1"
+  permission_handler_android:
+    dependency: transitive
+    description:
+      name: permission_handler_android
+      sha256: "1acac6bae58144b442f11e66621c062aead9c99841093c38f5bcdcc24c1c3474"
+      url: "https://pub.dev"
+    source: hosted
+    version: "12.0.5"
+  permission_handler_apple:
+    dependency: transitive
+    description:
+      name: permission_handler_apple
+      sha256: e9ad66020b89ff1b63908f247c2c6f931c6e62699b756ef8b3c4569350cd8662
+      url: "https://pub.dev"
+    source: hosted
+    version: "9.4.4"
+  permission_handler_html:
+    dependency: transitive
+    description:
+      name: permission_handler_html
+      sha256: "54bf176b90f6eddd4ece307e2c06cf977fb3973719c35a93b85cc7093eb6070d"
+      url: "https://pub.dev"
+    source: hosted
+    version: "0.1.1"
+  permission_handler_platform_interface:
+    dependency: transitive
+    description:
+      name: permission_handler_platform_interface
+      sha256: "48d4fcf201a1dad93ee869ab0d4101d084f49136ec82a8a06ed9cfeacab9fd20"
+      url: "https://pub.dev"
+    source: hosted
+    version: "4.2.1"
+  permission_handler_windows:
+    dependency: transitive
+    description:
+      name: permission_handler_windows
+      sha256: "1a790728016f79a41216d88672dbc5df30e686e811ad4e698bfc51f76ad91f1e"
+      url: "https://pub.dev"
+    source: hosted
+    version: "0.2.1"
   petitparser:
     dependency: transitive
     description:
@@ -525,6 +628,14 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "3.7.4"
+  protobuf:
+    dependency: transitive
+    description:
+      name: protobuf
+      sha256: "01dd9bd0fa02548bf2ceee13545d4a0ec6046459d847b6b061d8a27237108a08"
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.1.0"
   provider:
     dependency: "direct main"
     description:
@@ -549,6 +660,22 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "3.0.1"
+  reactive_ble_mobile:
+    dependency: transitive
+    description:
+      name: reactive_ble_mobile
+      sha256: "9ec2b4c9c725e439950838d551579750060258fbccd5536d0543b4d07d225798"
+      url: "https://pub.dev"
+    source: hosted
+    version: "5.3.1"
+  reactive_ble_platform_interface:
+    dependency: transitive
+    description:
+      name: reactive_ble_platform_interface
+      sha256: "632c92401a2d69c9b94bd48f8fd47488a7013f3d1f9b291884350291a4a81813"
+      url: "https://pub.dev"
+    source: hosted
+    version: "5.3.1"
   restart_app:
     dependency: "direct main"
     description:
app/pubspec.yaml
@@ -28,6 +28,9 @@ dependencies:
   health_data_store:
     path: ../health_data_store/
   sqlparser: ^0.34.1
+  flutter_bloc: ^8.1.4
+  flutter_reactive_ble: ^5.3.1
+  permission_handler: ^11.3.1
 
   # can become one custom dependency
   file_picker: ^5.2.11  # MIT
health_data_store/lib/src/health_data_store.dart
@@ -30,8 +30,8 @@ class HealthDataStore {
   /// decrease database performance in the first milliseconds after being
   /// returned. This is done to improve performance while interacting with the
   /// database.
-  static Future<HealthDataStore?> load(Database db) async {
-    if (!db.isOpen) return null;
+  static Future<HealthDataStore> load(Database db) async {
+    assert(db.isOpen);
     final mngr = await DatabaseManager.load(db);
     unawaited(mngr.performCleanup());
     return HealthDataStore._create(mngr);