Commit 74ef9ce

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2024-01-13 10:08:44
fix issues indicated by tests
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent 2577acb
lib/components/dialoges/add_measurement_dialoge.dart
@@ -3,6 +3,7 @@ import 'dart:math';
 import 'package:blood_pressure_app/components/date_time_picker.dart';
 import 'package:blood_pressure_app/components/dialoges/fullscreen_dialoge.dart';
 import 'package:blood_pressure_app/components/settings/settings_widgets.dart';
+import 'package:blood_pressure_app/model/blood_pressure/medicine/medicine.dart';
 import 'package:blood_pressure_app/model/blood_pressure/medicine/medicine_intake.dart';
 import 'package:blood_pressure_app/model/blood_pressure/needle_pin.dart';
 import 'package:blood_pressure_app/model/blood_pressure/record.dart';
@@ -314,7 +315,7 @@ class _AddEntryDialogeState extends State<AddEntryDialoge> {
                   child: Row(
                     children: [
                       Expanded(
-                        child: DropdownButtonFormField(
+                        child: DropdownButtonFormField<Medicine?>(
                           isExpanded: true,
                           value: widget.settings.medications
                               .where((e) => e.id == medicineId).firstOrNull,
lib/components/consistent_future_builder.dart
@@ -82,20 +82,24 @@ class _ConsistentFutureBuilderState<T>
   Widget build(BuildContext context) => FutureBuilder<T>(
     future: _future ?? widget.future,
     builder: (BuildContext context, AsyncSnapshot<T> snapshot) {
-      final localizations = AppLocalizations.of(context)!;
+      // Might get called before localizations initialize.
+      final localizations = AppLocalizations.of(context);
       if (snapshot.hasError) {
-        return Text(localizations.error(snapshot.error.toString()));
+        return Text(localizations?.error(snapshot.error.toString())
+            ?? snapshot.error.toString(),);
       }
       switch (snapshot.connectionState) {
         case ConnectionState.none:
           assert(false);
-          return widget.onNotStarted ?? Text(localizations.errNotStarted);
+          return widget.onNotStarted ?? Text(localizations?.errNotStarted
+              ?? 'NO_LOC_NO_START: please report this error.',);
         case ConnectionState.waiting:
         case ConnectionState.active:
           if (widget.lastChildWhileWaiting && _lastChild != null) {
             return _lastChild!;
           }
-          return widget.onWaiting ?? Text(localizations.loading);
+          return widget.onWaiting ?? Text(localizations?.loading
+              ?? 'loading...',);
         case ConnectionState.done:
           _lastChild = widget.onData(context, snapshot.data as T);
           return _lastChild!;
lib/main.dart
@@ -13,7 +13,6 @@ 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_gen/gen_l10n/app_localizations.dart';
-import 'package:flutter_localizations/flutter_localizations.dart';
 import 'package:fluttertoast/fluttertoast.dart';
 import 'package:package_info_plus/package_info_plus.dart';
 import 'package:path/path.dart';
@@ -89,6 +88,8 @@ Future<Widget> _loadApp() async {
   // Reset the step size intervall to current on startup
   intervalStorageManager.mainPage.setToMostRecentIntervall();
 
+  print(AppLocalizations.delegate);
+
   return MultiProvider(providers: [
     ChangeNotifierProvider(create: (context) => _bloodPressureModel),
     ChangeNotifierProvider(create: (context) => settings),
@@ -120,12 +121,7 @@ class AppRoot extends StatelessWidget {
         background: Colors.black,
       ),),
       themeMode: settings.themeMode,
-      localizationsDelegates: const [
-        AppLocalizations.delegate,
-        GlobalMaterialLocalizations.delegate,
-        GlobalCupertinoLocalizations.delegate,
-        GlobalWidgetsLocalizations.delegate,
-      ],
+      localizationsDelegates: AppLocalizations.localizationsDelegates,
       supportedLocales: AppLocalizations.supportedLocales,
       locale: settings.language,
       home: const AppHome(),
pubspec.yaml
@@ -10,7 +10,7 @@ environment:
 dependencies:
   csv: ^5.0.2
   collection: ^1.17.1
-  intl: ^0.18.0
+  intl: any
   flutter:
     sdk: flutter
   flutter_localizations: