Commit f7c75ec

derdilla <82763757+derdilla@users.noreply.github.com>
2025-03-17 14:09:42
Update deprecated `.value` selectors to `.toARG32()` (#543)
* update deprecated .value usages to .toARGB32 * remove outdated lint * Manually remove remaining .value occurences * Fix health_data_store doc updates
1 parent 11ef5df
app/integration_test/add_measurement_test.dart
@@ -87,7 +87,7 @@ void main() {
     expect(submittedRecord.sys?.mmHg, 123);
     expect(submittedRecord.dia?.mmHg, 67);
     expect(submittedRecord.pul, 56);
-    expect(submittedRecord.color, Colors.red.value);
+    expect(submittedRecord.color, Colors.red.toARGB32());
     expect(submittedRecord.note, 'some test sample note');
 
     expect(find.text('some test sample note'), findsNothing);
app/lib/features/export_import/add_export_column_dialoge.dart
@@ -168,7 +168,7 @@ class _AddExportColumnDialogeState extends State<AddExportColumnDialoge>
                     final note = Note(
                       time: record.time,
                       note: 'test note',
-                      color: Colors.red.value,
+                      color: Colors.red.toARGB32(),
                     );
                     final formatter = (type == _FormatterType.record)
                       ? ScriptedFormatter(recordPattern ?? '')
app/lib/features/export_import/import_button.dart
@@ -115,7 +115,7 @@ class ImportButton extends StatelessWidget {
                 notes.add(Note(
                   time: oldR.creationTime,
                   note: oldR.notes.isEmpty ? null : oldR.notes,
-                  color: oldR.needlePin?.color.value,
+                  color: oldR.needlePin?.color.toARGB32(),
                 ));
               }
             }
app/lib/features/input/forms/add_entry_form.dart
@@ -116,7 +116,7 @@ class AddEntryFormState extends FormStateBase<AddEntryFormValue, AddEntryForm> {
 
     final noteFormValue = _noteForm.currentState?.save();
     if (noteFormValue != null) {
-      note = Note(time: time, note: noteFormValue.$1, color: noteFormValue.$2?.value);
+      note = Note(time: time, note: noteFormValue.$1, color: noteFormValue.$2?.toARGB32());
     }
     final recordFormValue = _bpForm.currentState?.save();
     if (recordFormValue != null) {
app/lib/features/settings/add_medication_dialoge.dart
@@ -41,7 +41,7 @@ class _AddMedicationDialogeState extends State<AddMedicationDialoge> {
         formKey.currentState?.save();
         Navigator.pop(context, Medicine(
           designation: _designation ?? '',
-          color: _color.value,
+          color: _color.toARGB32(),
           dosis: _defaultDosis == null ? null : Weight.mg(_defaultDosis!),
         ),);
       },
app/lib/features/settings/medicine_manager_screen.dart
@@ -16,7 +16,7 @@ class MedicineManagerScreen extends StatelessWidget {
   const MedicineManagerScreen({super.key});
 
   Widget _buildMedicine(BuildContext context, Medicine med) => ListTile(
-    leading: med.color == Colors.transparent.value
+    leading: med.color == Colors.transparent.toARGB32()
         || med.color == null
         ? null
         : Container(
@@ -34,7 +34,7 @@ class MedicineManagerScreen extends StatelessWidget {
     trailing: IconButton(
       icon: const Icon(Icons.delete),
       onPressed: () async {
-        if (await showConfirmDeletionDialoge(context)) {
+        if (await showConfirmDeletionDialoge(context) && context.mounted) {
           await RepositoryProvider.of<MedicineRepository>(context).remove(med);
         }
       },
@@ -54,29 +54,26 @@ class MedicineManagerScreen extends StatelessWidget {
   );
 
  @override
-  Widget build(BuildContext context) {
-    final localizations = AppLocalizations.of(context)!;
-    return Scaffold(
-      appBar: AppBar(
-        forceMaterialTransparency: true,
-      ),
-      body: Center(
-        child: StreamBuilder(
-          stream: RepositoryProvider.of<MedicineRepository>(context).subscribe(),
-          builder: (context, _) => ConsistentFutureBuilder(
-            future: RepositoryProvider.of<MedicineRepository>(context).getAll(),
-            onData: (context, medicines) => ListView.builder(
-              itemCount: medicines.length + 1,
-              itemBuilder: (context, i) {
-                if (i == medicines.length) { // last row
-                  return _buildAddMed(context);
-                }
-                return _buildMedicine(context, medicines[i]);
-              },
-            ),
+  Widget build(BuildContext context) => Scaffold(
+    appBar: AppBar(
+      forceMaterialTransparency: true,
+    ),
+    body: Center(
+      child: StreamBuilder(
+        stream: RepositoryProvider.of<MedicineRepository>(context).subscribe(),
+        builder: (context, _) => ConsistentFutureBuilder(
+          future: RepositoryProvider.of<MedicineRepository>(context).getAll(),
+          onData: (context, medicines) => ListView.builder(
+            itemCount: medicines.length + 1,
+            itemBuilder: (context, i) {
+              if (i == medicines.length) { // last row
+                return _buildAddMed(context);
+              }
+              return _buildMedicine(context, medicines[i]);
+            },
           ),
         ),
       ),
-    );
-  }
+    ),
+  );
 }
app/lib/model/blood_pressure/medicine/medicine.dart
@@ -52,7 +52,7 @@ class Medicine {
           runtimeType == other.runtimeType &&
           id == other.id &&
           designation == other.designation &&
-          color.value == other.color.value &&
+          color.toARGB32() == other.color.toARGB32() &&
           defaultDosis == other.defaultDosis &&
           hidden == other.hidden;
 
app/lib/model/blood_pressure/update_legacy_entries.dart
@@ -35,7 +35,7 @@ Future<void> updateLegacyEntries(
         if (med == null) {
           med = hds.Medicine(
             designation: i.medicine.designation,
-            color: i.medicine.color.value,
+            color: i.medicine.color.toARGB32(),
             dosis: i.medicine.defaultDosis == null ? null : hds.Weight.mg(i.medicine.defaultDosis!),
           );
           addedMeds[i.medicine] = med;
@@ -74,7 +74,7 @@ Future<void> updateLegacyEntries(
         await noteRepo.add(hds.Note(
           time: r.creationTime,
           note: r.notes.isEmpty ? null : r.notes,
-          color: r.needlePin?.color.value,
+          color: r.needlePin?.color.toARGB32(),
         ));
       }
     }
app/lib/model/export_import/import_field_type.dart
@@ -16,7 +16,7 @@ enum RowDataFieldType {
   pul,
   /// Guarantees [String] is returned.
   notes,
-  /// Guarantees that a [int] containing a [Color.value] is returned.
+  /// Guarantees that a [int] containing a [Color.toARGB32()] is returned.
   ///
   /// Backwards compatability with [MeasurementNeedlePin] json is maintained.
   color,
app/lib/model/export_import/record_formatter.dart
@@ -53,7 +53,7 @@ class ScriptedFormatter implements Formatter {
       RowDataFieldType.notes => text,
       RowDataFieldType.color => (){
         try {
-          return int.tryParse(text) ?? MeasurementNeedlePin.fromMap(jsonDecode(text)).color.value;
+          return int.tryParse(text) ?? MeasurementNeedlePin.fromMap(jsonDecode(text)).color.toARGB32();
         } on FormatException { return null; } on TypeError { return null; }
       }(),
       RowDataFieldType.intakes => NativeColumn.intakes.decode(text),
app/lib/model/storage/settings_store.dart
@@ -139,10 +139,10 @@ class Settings extends ChangeNotifier {
 
   /// Serialize the object to a restoreable map.
   Map<String, dynamic> toMap() => <String, dynamic>{
-    'accentColor': accentColor.value,
-    'sysColor': sysColor.value,
-    'diaColor': diaColor.value,
-    'pulColor': pulColor.value,
+    'accentColor': accentColor.toARGB32(),
+    'sysColor': sysColor.toARGB32(),
+    'diaColor': diaColor.toARGB32(),
+    'pulColor': pulColor.toARGB32(),
     'dateFormatString': dateFormatString,
     'graphLineThickness': graphLineThickness,
     'animationSpeed': animationSpeed,
app/lib/model/storage/update_legacy_settings.dart
@@ -249,7 +249,7 @@ Future<void> migrateDatabaseSettings(
   settings.copyFrom(oldSettings);
   final oldMeds = settings.medications.map((e) => Medicine(
     designation: e.designation,
-    color: e.color.value,
+    color: e.color.toARGB32(),
     dosis: e.defaultDosis == null ? null : Weight.mg(e.defaultDosis!),
   ));
   await Future.forEach(oldMeds, medRepo.add);
app/lib/model/horizontal_graph_line.dart
@@ -24,7 +24,7 @@ class HorizontalGraphLine {
 
   /// Serialize the object to a restoreable map.
   Map<String, dynamic> toJson() => {
-    'color': color.value,
+    'color': color.toARGB32(),
     'height': height,
   };
 }
app/test/features/input/forms/add_entry_form_test.dart
@@ -276,7 +276,7 @@ void main() {
     final value = (
       timestamp: intake.time,
       intake: intake,
-      note: Note(time: intake.time, note: '123test', color: Colors.teal.value),
+      note: Note(time: intake.time, note: '123test', color: Colors.teal.toARGB32()),
       record: mockRecord(time: intake.time, sys: 123, dia: 45, pul: 67),
       weight: BodyweightRecord(time: intake.time, weight: Weight.kg(123.45))
     );
@@ -303,7 +303,7 @@ void main() {
     final value = (
       timestamp: intake.time,
       intake: intake,
-      note: Note(time: intake.time, note: '123test', color: Colors.teal.value),
+      note: Note(time: intake.time, note: '123test', color: Colors.teal.toARGB32()),
       record: mockRecord(time: intake.time, sys: 123, dia: 45, pul: 67),
       weight: BodyweightRecord(time: intake.time, weight: Weight.kg(123.45))
     );
app/test/features/measurement_list/measurement_list_entry_test.dart
@@ -111,7 +111,7 @@ void main() {
     
     expect(find.byWidgetPredicate((widget) => widget is Icon
       && widget.icon == Icons.medication
-      && widget.color?.value == Colors.red.value), findsOneWidget);
+      && widget.color?.toARGB32() == Colors.red.toARGB32()), findsOneWidget);
   });
 }
 
app/test/features/statistics/value_graph_test.dart
@@ -190,7 +190,7 @@ Widget _buildGraph(
     height: 300,
     child: BloodPressureValueGraph(
       records: data,
-      colors: colors.map((e) => Note(time: e.$1, color: e.$2.value)).toList(),
+      colors: colors.map((e) => Note(time: e.$1, color: e.$2.toARGB32())).toList(),
       intakes: intakes,
     ),
   ),
app/test/model/export_import/csv_converter_test.dart
@@ -288,7 +288,7 @@ void main() {
       .having((p0) => p0.$1.dia?.mmHg, 'diastolic', 71)
       .having((p0) => p0.$1.pul, 'pulse', 66)
       .having((p0) => p0.$2.note, 'notes', 'fsaf &_*¢|^✓[=%®©')
-      .having((p0) => p0.$2.color, 'color', Colors.lightGreen.value),
+      .having((p0) => p0.$2.color, 'color', Colors.lightGreen.toARGB32()),
     ),);
     expect(records, anyElement(isA<FullEntry>()
       .having((p0) => p0.$1.time.millisecondsSinceEpoch, 'timestamp', 1701034952000)
app/test/model/export_import/record_formatter_test.dart
@@ -72,7 +72,7 @@ void main() {
       final r = mockEntryPos(DateTime.now(), null, null, null, '', Colors.purple);
       final encodedPurple = ScriptedFormatter(r'$COLOR',).encode(r.$1, r.$2, r.$3, null);
       expect(ScriptedFormatter(r'$COLOR',).decode(encodedPurple)?.$1, RowDataFieldType.color);
-      expect(ScriptedFormatter(r'$COLOR',).decode(encodedPurple)?.$2, Colors.purple.value);
+      expect(ScriptedFormatter(r'$COLOR',).decode(encodedPurple)?.$2, Colors.purple.toARGB32());
       expect(ScriptedFormatter(r'test$SYS',).decode('test567'), (RowDataFieldType.sys, 567));
       expect(ScriptedFormatter(r'test$SYS123',).decode('test567123'), (RowDataFieldType.sys, 567));
       expect(ScriptedFormatter(r'test$DIA123',).decode('test567123'), (RowDataFieldType.dia, 567));
@@ -163,7 +163,7 @@ FullEntry mockEntry({
     Note(
       time: time,
       note: note,
-      color: pin?.value,
+      color: pin?.toARGB32(),
     ),
     (intake == null ? [] : [ intake ]),
   );
app/test/model/storage/db/file_settings_loader_test.dart
@@ -28,7 +28,7 @@ void main() {
       final settings1 = await loader1.loadSettings();
       settings1.sysColor = Colors.blueGrey;
       final settings2 = await loader2.loadSettings();
-      expect(settings2.sysColor.value, settings1.sysColor.value);
+      expect(settings2.sysColor.toARGB32(), settings1.sysColor.toARGB32());
 
       final exportSettings1 = await loader1.loadExportSettings();
       exportSettings1.exportFormat = ExportFormat.db;
app/test/model/convert_util_test.dart
@@ -76,12 +76,12 @@ void main() {
 
   test('parseMaterialColor should parse valid values correctly', () {
     expect(ConvertUtil.parseColor(Colors.deepOrange), Colors.deepOrange);
-    expect(ConvertUtil.parseColor(Colors.grey)?.value, Colors.grey.value);
-    expect(ConvertUtil.parseColor(Colors.grey.value)?.value, Colors.grey.value);
-    expect(ConvertUtil.parseColor(Colors.deepOrange.value)?.value, Colors.deepOrange.value);
-    expect(ConvertUtil.parseColor(0xff000000)?.value, 0xff000000);
-    expect(ConvertUtil.parseColor('0x00ff0000')?.value, 0x00ff0000);
-    expect(ConvertUtil.parseColor(const Color(0x00ff0000))?.value, 0x00ff0000);
+    expect(ConvertUtil.parseColor(Colors.grey)?.toARGB32(), Colors.grey.toARGB32());
+    expect(ConvertUtil.parseColor(Colors.grey.toARGB32())?.toARGB32(), Colors.grey.toARGB32());
+    expect(ConvertUtil.parseColor(Colors.deepOrange.toARGB32())?.toARGB32(), Colors.deepOrange.toARGB32());
+    expect(ConvertUtil.parseColor(0xff000000)?.toARGB32(), 0xff000000);
+    expect(ConvertUtil.parseColor('0x00ff0000')?.toARGB32(), 0x00ff0000);
+    expect(ConvertUtil.parseColor(const Color(0x00ff0000))?.toARGB32(), 0x00ff0000);
   });
   test('parseMaterialColor should parse invalid values as null', () {
     expect(ConvertUtil.parseColor('test'), null);
app/test/model/json_serialization_test.dart
@@ -106,10 +106,10 @@ void main() {
       final fromJson = Settings.fromJson(initial.toJson());
 
       expect(initial.language, fromJson.language);
-      expect(initial.accentColor.value, fromJson.accentColor.value);
-      expect(initial.sysColor.value, fromJson.sysColor.value);
-      expect(initial.diaColor.value, fromJson.diaColor.value);
-      expect(initial.pulColor.value, fromJson.pulColor.value);
+      expect(initial.accentColor.toARGB32(), fromJson.accentColor.toARGB32());
+      expect(initial.sysColor.toARGB32(), fromJson.sysColor.toARGB32());
+      expect(initial.diaColor.toARGB32(), fromJson.diaColor.toARGB32());
+      expect(initial.pulColor.toARGB32(), fromJson.pulColor.toARGB32());
       expect(initial.dateFormatString, fromJson.dateFormatString);
       expect(initial.graphLineThickness, fromJson.graphLineThickness);
       expect(initial.animationSpeed, fromJson.animationSpeed);
@@ -124,7 +124,7 @@ void main() {
       expect(initial.startWithAddMeasurementPage, fromJson.startWithAddMeasurementPage);
       expect(initial.compactList, fromJson.compactList);
       expect(initial.horizontalGraphLines.length, fromJson.horizontalGraphLines.length);
-      expect(initial.horizontalGraphLines.first.color.value, fromJson.horizontalGraphLines.first.color.value);
+      expect(initial.horizontalGraphLines.first.color.toARGB32(), fromJson.horizontalGraphLines.first.color.toARGB32());
       expect(initial.horizontalGraphLines.first.height, fromJson.horizontalGraphLines.first.height);
       expect(initial.needlePinBarWidth, fromJson.needlePinBarWidth);
       expect(initial.bottomAppBars, fromJson.bottomAppBars);
@@ -151,7 +151,7 @@ void main() {
       final v3 = Settings.fromJson('{"validateInputs": "month", "useLegacyList": 10.5}');
       Settings.fromJson('{"sysWarn": 18.6, "diaWarn": 90.65}');
 
-      expect(v1.pulColor.value, Settings().pulColor.value);
+      expect(v1.pulColor.toARGB32(), Settings().pulColor.toARGB32());
       expect(v2.validateInputs, Settings().validateInputs);
       expect(v3.compactList, Settings().compactList);
     });
app/test/util.dart
@@ -267,13 +267,13 @@ Medicine mockMedicine({
   double? defaultDosis,
 }) {
   final matchingMeds = _meds.where((med) => med.dosis?.mg == defaultDosis
-    && med.color == color.value
+    && med.color == color.toARGB32()
     && med.designation == designation,
   );
   if (matchingMeds.isNotEmpty) return matchingMeds.first;
   final med = Medicine(
     designation: designation,
-    color: color.value,
+    color: color.toARGB32(),
     dosis: defaultDosis == null ? null : Weight.mg(defaultDosis),
   );
   _meds.add(med);
app/analysis_options.yaml
@@ -25,7 +25,6 @@ linter:
     - matching_super_parameters
     - no_literal_bool_comparisons
     - noop_primitive_operations
-    - package_api_docs
     - prefer_asserts_in_initializer_lists
     - prefer_expression_function_bodies
     - prefer_final_in_for_each
health_data_store/lib/src/types/full_entry.dart
@@ -34,7 +34,7 @@ extension FastFullEntryGetters on FullEntry {
 
   /// ARGB color in number format.
   ///
-  /// Can also be obtained through the `dart:ui` Colors `value` attribute.
+  /// Can also be obtained through the `Colors.toARGB32()` method in `dart:ui`.
   /// Sample value: `0xFF42A5F5`
   int? get color => this.$2.color;
 }
health_data_store/lib/src/types/medicine.dart
@@ -13,7 +13,7 @@ class Medicine with _$Medicine {
 
     /// ARGB color in number format.
     ///
-    /// Can also be obtained through the `dart:ui` Colors `value` attribute.
+    /// Can also be obtained through the `Colors.toARGB32()` method in `dart:ui`.
     /// Sample value: `0xFF42A5F5`
     int? color,
 
health_data_store/lib/src/types/note.dart
@@ -15,7 +15,7 @@ class Note with _$Note {
 
     /// ARGB color in number format.
     ///
-    /// Can also be obtained through the `dart:ui` Colors `value` attribute.
+    /// Can also be obtained through the `Colors.toARGB32()` method in `dart:ui`.
     /// Sample value: `0xFF42A5F5`
     int? color,
   }) = _Notes;