Skip to content

Commit 957ceaa

Browse files
committedMar 12, 2021
nullsafety 1.2.0
1 parent e35bd94 commit 957ceaa

36 files changed

+117
-140
lines changed
 

‎README.md

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ A Flutter wrapper for [HealthKitReporter](https://cocoapods.org/pods/HealthKitRe
1818
dependencies:
1919
health_kit_reporter: ^1.1.1
2020
```
21+
or with null safety:
22+
``` Dart
23+
dependencies:
24+
health_kit_reporter: ^1.2.0-nullsafety.0
25+
```
2126
- Get dependencies
2227

2328
``` shell

‎example/ios/Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PODS:
22
- Flutter (1.0.0)
33
- flutter_local_notifications (0.0.1):
44
- Flutter
5-
- health_kit_reporter (1.1.0):
5+
- health_kit_reporter (1.1.1):
66
- Flutter
77
- HealthKitReporter
88
- HealthKitReporter (1.4.0)
@@ -27,7 +27,7 @@ EXTERNAL SOURCES:
2727
SPEC CHECKSUMS:
2828
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
2929
flutter_local_notifications: 0c0b1ae97e741e1521e4c1629a459d04b9aec743
30-
health_kit_reporter: 4f07356cf70fff8d50b92b76ee9beacf7e3d70f9
30+
health_kit_reporter: 9ac0e8b9d1933d67b23f1ee8e4d45eb4611bfe84
3131
HealthKitReporter: 1bd60f53111044cc3a0d575d57dc4b23767c8ac6
3232

3333
PODFILE CHECKSUM: a75497545d4391e2d394c3668e20cfb1c2bbd4aa

‎example/pubspec.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ packages:
6868
name: flutter_local_notifications
6969
url: "https://pub.dartlang.org"
7070
source: hosted
71-
version: "5.0.0-nullsafety.0"
71+
version: "5.0.0-nullsafety.1"
7272
flutter_local_notifications_platform_interface:
7373
dependency: transitive
7474
description:
7575
name: flutter_local_notifications_platform_interface
7676
url: "https://pub.dartlang.org"
7777
source: hosted
78-
version: "3.0.0-nullsafety.2"
78+
version: "3.0.0-nullsafety.4"
7979
flutter_test:
8080
dependency: "direct dev"
8181
description: flutter
@@ -87,7 +87,7 @@ packages:
8787
path: ".."
8888
relative: true
8989
source: path
90-
version: "1.1.0"
90+
version: "1.2.0-nullsafety.0"
9191
intl:
9292
dependency: transitive
9393
description:
@@ -129,7 +129,7 @@ packages:
129129
name: plugin_platform_interface
130130
url: "https://pub.dartlang.org"
131131
source: hosted
132-
version: "1.0.3"
132+
version: "2.0.0"
133133
sky_engine:
134134
dependency: transitive
135135
description: flutter
@@ -199,5 +199,5 @@ packages:
199199
source: hosted
200200
version: "2.1.0"
201201
sdks:
202-
dart: ">=2.12.0-0.0 <3.0.0"
202+
dart: ">=2.12.0 <3.0.0"
203203
flutter: ">=1.20.0"

‎example/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ description: Demonstrates how to use the health_kit_reporter plugin.
1414
version: 1.0.0
1515

1616
environment:
17-
sdk: ">=2.7.0 <3.0.0"
17+
sdk: ">=2.12.0 <3.0.0"
1818

1919
dependencies:
2020
flutter:
2121
sdk: flutter
22-
flutter_local_notifications: ^5.0.0-nullsafety.0
22+
flutter_local_notifications: ^5.0.0-nullsafety.1
2323
health_kit_reporter:
2424
# When depending on this package from a real application you should use:
2525
# health_kit_reporter: ^x.y.z

‎example/test/widget_test.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import 'package:flutter/material.dart';
99
import 'package:flutter_test/flutter_test.dart';
10-
1110
import 'package:health_kit_reporter_example/main.dart';
1211

1312
void main() {
@@ -18,8 +17,8 @@ void main() {
1817
// Verify that platform version is retrieved.
1918
expect(
2019
find.byWidgetPredicate(
21-
(Widget widget) => widget is Text &&
22-
widget.data.startsWith('Running on:'),
20+
(Widget widget) =>
21+
widget is Text && widget.data!.startsWith('Running on:'),
2322
),
2423
findsOneWidget,
2524
);

‎lib/health_kit_reporter.dart

+15-11
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class HealthKitReporter {
152152
/// Provide the [predicate] to set the date interval.
153153
///
154154
static StreamSubscription<dynamic> heartbeatSeriesQuery(Predicate predicate,
155-
{Function(HeartbeatSerie) onUpdate}) {
155+
{required Function(HeartbeatSerie) onUpdate}) {
156156
final arguments = predicate.map;
157157
return _heartbeatSeriesQueryChannel
158158
.receiveBroadcastStream(arguments)
@@ -169,7 +169,7 @@ class HealthKitReporter {
169169
/// Provide the [predicate] to set the date interval.
170170
///
171171
static StreamSubscription<dynamic> workoutRouteQuery(Predicate predicate,
172-
{Function(WorkoutRoute) onUpdate}) {
172+
{required Function(WorkoutRoute) onUpdate}) {
173173
final arguments = predicate.map;
174174
return _workoutRouteQueryChannel
175175
.receiveBroadcastStream(arguments)
@@ -188,7 +188,7 @@ class HealthKitReporter {
188188
///
189189
static StreamSubscription<dynamic> observerQuery(
190190
String identifier, Predicate predicate,
191-
{Function(String) onUpdate}) {
191+
{required Function(String) onUpdate}) {
192192
final arguments = <String, dynamic>{
193193
'identifier': identifier,
194194
};
@@ -211,7 +211,7 @@ class HealthKitReporter {
211211
///
212212
static StreamSubscription<dynamic> anchoredObjectQuery(
213213
String identifier, Predicate predicate,
214-
{Function(List<Sample>, List<DeletedObject>) onUpdate}) {
214+
{required Function(List<Sample>, List<DeletedObject>) onUpdate}) {
215215
final arguments = <String, dynamic>{
216216
'identifier': identifier,
217217
};
@@ -225,7 +225,9 @@ class HealthKitReporter {
225225
for (final String element in samplesList) {
226226
final json = jsonDecode(element);
227227
final sample = Sample.factory(json);
228-
samples.add(sample);
228+
if (sample != null) {
229+
samples.add(sample);
230+
}
229231
}
230232
final deletedObjectsList = List.from(map['deletedObjects']);
231233
final deletedObjects = <DeletedObject>[];
@@ -247,7 +249,7 @@ class HealthKitReporter {
247249
///
248250
static StreamSubscription<dynamic> queryActivitySummaryUpdates(
249251
Predicate predicate,
250-
{Function(List<ActivitySummary>) onUpdate}) {
252+
{required Function(List<ActivitySummary>) onUpdate}) {
251253
final arguments = predicate.map;
252254
return _queryActivitySummaryChannel
253255
.receiveBroadcastStream(arguments)
@@ -281,7 +283,7 @@ class HealthKitReporter {
281283
DateTime enumerateFrom,
282284
DateTime enumerateTo,
283285
DateComponents intervalComponents,
284-
{Function(Statistics) onUpdate}) {
286+
{required Function(Statistics) onUpdate}) {
285287
final arguments = {
286288
'identifier': type.identifier,
287289
'unit': unit,
@@ -446,7 +448,9 @@ class HealthKitReporter {
446448
for (final String element in list) {
447449
final json = jsonDecode(element);
448450
final sample = Sample.factory(json);
449-
samples.add(sample);
451+
if (sample != null) {
452+
samples.add(sample);
453+
}
450454
}
451455
return samples;
452456
}
@@ -559,7 +563,7 @@ class HealthKitReporter {
559563
///
560564
static Future<List<Correlation>> correlationQuery(
561565
String identifier, Predicate predicate,
562-
{Map<String, Predicate> typePredicates}) async {
566+
{Map<String, Predicate>? typePredicates}) async {
563567
final arguments = {
564568
'identifier': identifier,
565569
'typePredicates': typePredicates,
@@ -598,7 +602,7 @@ class HealthKitReporter {
598602
/// [device] is optional.
599603
///
600604
static Future<bool> addCategory(List<Category> categories, Workout workout,
601-
{Device device}) async {
605+
{Device? device}) async {
602606
final arguments = {
603607
'categories': categories.map((e) => e.map).toList(),
604608
'workout': workout.map,
@@ -611,7 +615,7 @@ class HealthKitReporter {
611615
/// [device] is optional.
612616
///
613617
static Future<bool> addQuantity(List<Quantity> quantities, Workout workout,
614-
{Device device}) async {
618+
{Device? device}) async {
615619
final arguments = {
616620
'quantities': quantities.map((e) => e.map).toList(),
617621
'workout': workout.map,

‎lib/model/decorator/extensions.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ extension Date on String {
44
/// Try to parse the date coming from native side
55
/// Expected format from native side is [yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ]
66
///
7-
DateTime get date => this != null ? DateTime.tryParse(this) : null;
7+
DateTime get date => DateTime.parse(this);
88
}

‎lib/model/payload/activity_summary.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ActivitySummary {
3535
///
3636
ActivitySummary.fromJson(Map<String, dynamic> json)
3737
: identifier = json['identifier'],
38-
date = json['date']?.toString()?.date,
38+
date = json['date'].toString().date,
3939
harmonized = ActivitySummaryHarmonized.fromJson(json['harmonized']);
4040
}
4141

‎lib/model/payload/category.dart

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Category extends Sample<CategoryHarmonized> {
1919
String identifier,
2020
num startTimestamp,
2121
num endTimestamp,
22-
Device device,
22+
Device? device,
2323
SourceRevision sourceRevision,
2424
CategoryHarmonized harmonized,
2525
) : super(
@@ -40,16 +40,15 @@ class Category extends Sample<CategoryHarmonized> {
4040
'identifier': identifier,
4141
'startTimestamp': startTimestamp,
4242
'endTimestamp': endTimestamp,
43-
'device': device.map,
43+
'device': device?.map,
4444
'sourceRevision': sourceRevision.map,
4545
'harmonized': harmonized.map,
4646
};
4747

4848
/// General constructor from JSON payload
4949
///
5050
Category.fromJson(Map<String, dynamic> json)
51-
: super.fromJson(json,
52-
harmonized: CategoryHarmonized.fromJson(json['harmonized']));
51+
: super.from(json, CategoryHarmonized.fromJson(json['harmonized']));
5352

5453
/// Simplifies creating a list of objects from JSON payload.
5554
///
@@ -80,7 +79,7 @@ class CategoryHarmonized {
8079

8180
final num value;
8281
final String description;
83-
final Map<String, dynamic> metadata;
82+
final Map<String, dynamic>? metadata;
8483

8584
/// General map representation
8685
///

‎lib/model/payload/characteristic/biological_sex.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ extension Description on BiologicalSex {
3030
case BiologicalSex.other:
3131
return 'Other';
3232
}
33-
throw InvalidValueException('Unknown case: $this');
3433
}
3534
}
3635

@@ -46,7 +45,7 @@ extension BiologicalSexFactory on BiologicalSex {
4645
case 'Other':
4746
return BiologicalSex.other;
4847
default:
49-
return null;
48+
throw InvalidValueException('Unknown case: $string');
5049
}
5150
}
5251
}

‎lib/model/payload/characteristic/blood_type.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ extension Description on BloodType {
4343
case BloodType.oNegative:
4444
return 'O-';
4545
}
46-
throw InvalidValueException('Unknown case: $this');
4746
}
4847
}
4948

@@ -69,7 +68,7 @@ extension BloodTypeFactory on BloodType {
6968
case 'O-':
7069
return BloodType.oNegative;
7170
default:
72-
return null;
71+
throw InvalidValueException('Unknown case: $string');
7372
}
7473
}
7574
}

‎lib/model/payload/characteristic/characteristic.dart

+9-9
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ class Characteristic {
2323
this.skinType,
2424
);
2525

26-
final BiologicalSex biologicalSex;
27-
final DateTime birthday;
28-
final BloodType bloodType;
29-
final FitzpatrickSkinType skinType;
26+
final BiologicalSex? biologicalSex;
27+
final DateTime? birthday;
28+
final BloodType? bloodType;
29+
final FitzpatrickSkinType? skinType;
3030

31-
Map<String, String> get map => {
32-
'biologicalSex': biologicalSex.string,
31+
Map<String, String?> get map => {
32+
'biologicalSex': biologicalSex?.string,
3333
'birthday': birthday?.toIso8601String(),
34-
'bloodType': bloodType.string,
35-
'skinType': skinType.string,
34+
'bloodType': bloodType?.string,
35+
'skinType': skinType?.string,
3636
};
3737

3838
/// General constructor from JSON payload
3939
///
4040
Characteristic.fromJson(Map<String, dynamic> json)
4141
: biologicalSex = BiologicalSexFactory.from(json['biologicalSex']),
42-
birthday = json['birthday']?.toString()?.date,
42+
birthday = json['birthday']?.toString().date,
4343
bloodType = BloodTypeFactory.from(json['bloodType']),
4444
skinType = FitzpatrickSkinTypeFactory.from(json['skinType']);
4545
}

‎lib/model/payload/characteristic/fitzpatrick_skin_type.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ extension Description on FitzpatrickSkinType {
3737
case FitzpatrickSkinType.VI:
3838
return 'VI';
3939
}
40-
throw InvalidValueException('Unknown case: $this');
4140
}
4241
}
4342

@@ -59,7 +58,7 @@ extension FitzpatrickSkinTypeFactory on FitzpatrickSkinType {
5958
case 'VI':
6059
return FitzpatrickSkinType.VI;
6160
default:
62-
return null;
61+
throw InvalidValueException('Unknown case: $string');
6362
}
6463
}
6564
}

‎lib/model/payload/correlation.dart

+4-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Correlation extends Sample<CorrelationHarmonized> {
2222
String identifier,
2323
num startTimestamp,
2424
num endTimestamp,
25-
Device device,
25+
Device? device,
2626
SourceRevision sourceRevision,
2727
CorrelationHarmonized harmonized,
2828
) : super(
@@ -38,8 +38,7 @@ class Correlation extends Sample<CorrelationHarmonized> {
3838
/// General constructor from JSON payload
3939
///
4040
Correlation.fromJson(Map<String, dynamic> json)
41-
: super.fromJson(json,
42-
harmonized: CorrelationHarmonized.fromJson(json['harmonized']));
41+
: super.from(json, CorrelationHarmonized.fromJson(json['harmonized']));
4342

4443
/// General map representation
4544
///
@@ -49,7 +48,7 @@ class Correlation extends Sample<CorrelationHarmonized> {
4948
'identifier': identifier,
5049
'startTimestamp': startTimestamp,
5150
'endTimestamp': endTimestamp,
52-
'device': device.map,
51+
'device': device?.map,
5352
'sourceRevision': sourceRevision.map,
5453
'harmonized': harmonized.map,
5554
};
@@ -72,7 +71,7 @@ class CorrelationHarmonized {
7271

7372
final List<Quantity> quantitySamples;
7473
final List<Category> categorySamples;
75-
final Map<String, dynamic> metadata;
74+
final Map<String, dynamic>? metadata;
7675

7776
/// General map representation
7877
///

‎lib/model/payload/date_components.dart

+15-15
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ class DateComponents {
2020
this.weekOfYear,
2121
this.yearForWeekOfYear,
2222
});
23-
final int era;
24-
final int year;
25-
final int month;
26-
final int day;
27-
final int hour;
28-
final int minute;
29-
final int second;
30-
final int nanosecond;
31-
final int weekday;
32-
final int weekdayOrdinal;
33-
final int quarter;
34-
final int weekOfMonth;
35-
final int weekOfYear;
36-
final int yearForWeekOfYear;
23+
final int? era;
24+
final int? year;
25+
final int? month;
26+
final int? day;
27+
final int? hour;
28+
final int? minute;
29+
final int? second;
30+
final int? nanosecond;
31+
final int? weekday;
32+
final int? weekdayOrdinal;
33+
final int? quarter;
34+
final int? weekOfMonth;
35+
final int? weekOfYear;
36+
final int? yearForWeekOfYear;
3737

3838
/// General map representation
3939
///
40-
Map<String, int> get map => {
40+
Map<String, int?> get map => {
4141
'era': era,
4242
'year': year,
4343
'month': month,

‎lib/model/payload/deleted_object.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class DeletedObject {
1010
const DeletedObject(this.uuid, this.metadata);
1111

1212
final String uuid;
13-
final Map<String, dynamic> metadata;
13+
final Map<String, dynamic>? metadata;
1414

1515
/// General map representation
1616
///

‎lib/model/payload/device.dart

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ class Device {
1818
this.udiDeviceIdentifier,
1919
);
2020

21-
final String name;
22-
final String manufacturer;
23-
final String model;
24-
final String hardwareVersion;
25-
final String firmwareVersion;
26-
final String softwareVersion;
27-
final String localIdentifier;
28-
final String udiDeviceIdentifier;
21+
final String? name;
22+
final String? manufacturer;
23+
final String? model;
24+
final String? hardwareVersion;
25+
final String? firmwareVersion;
26+
final String? softwareVersion;
27+
final String? localIdentifier;
28+
final String? udiDeviceIdentifier;
2929

30-
Map<String, String> get map => {
30+
Map<String, String?> get map => {
3131
'name': name,
3232
'manufacturer': manufacturer,
3333
'model': model,

‎lib/model/payload/electrocardiogram.dart

+5-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Electrocardiogram extends Sample<ElectrocardiogramHarmonized> {
2020
String identifier,
2121
num startTimestamp,
2222
num endTimestamp,
23-
Device device,
23+
Device? device,
2424
SourceRevision sourceRevision,
2525
ElectrocardiogramHarmonized harmonized,
2626
this.numberOfMeasurements,
@@ -44,7 +44,7 @@ class Electrocardiogram extends Sample<ElectrocardiogramHarmonized> {
4444
'identifier': identifier,
4545
'startTimestamp': startTimestamp,
4646
'endTimestamp': endTimestamp,
47-
'device': device.map,
47+
'device': device?.map,
4848
'sourceRevision': sourceRevision.map,
4949
'harmonized': harmonized.map,
5050
'numberOfMeasurements': numberOfMeasurements,
@@ -54,9 +54,8 @@ class Electrocardiogram extends Sample<ElectrocardiogramHarmonized> {
5454
///
5555
Electrocardiogram.fromJson(Map<String, dynamic> json)
5656
: numberOfMeasurements = json['numberOfMeasurements'],
57-
super.fromJson(json,
58-
harmonized:
59-
ElectrocardiogramHarmonized.fromJson(json['harmonized']));
57+
super.from(
58+
json, ElectrocardiogramHarmonized.fromJson(json['harmonized']));
6059
}
6160

6261
/// Equivalent of [Electrocardiogram.Harmonized]
@@ -84,7 +83,7 @@ class ElectrocardiogramHarmonized {
8483
final String samplingFrequencyUnit;
8584
final String classification;
8685
final String symptomsStatus;
87-
final Map<String, dynamic> metadata;
86+
final Map<String, dynamic>? metadata;
8887

8988
/// General map representation
9089
///

‎lib/model/payload/quantity.dart

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Quantity extends Sample<QuantityHarmonized> {
1919
String identifier,
2020
num startTimestamp,
2121
num endTimestamp,
22-
Device device,
22+
Device? device,
2323
SourceRevision sourceRevision,
2424
QuantityHarmonized harmonized,
2525
) : super(
@@ -40,16 +40,15 @@ class Quantity extends Sample<QuantityHarmonized> {
4040
'identifier': identifier,
4141
'startTimestamp': startTimestamp,
4242
'endTimestamp': endTimestamp,
43-
'device': device.map,
43+
'device': device?.map,
4444
'sourceRevision': sourceRevision.map,
4545
'harmonized': harmonized.map,
4646
};
4747

4848
/// General constructor from JSON payload
4949
///
5050
Quantity.fromJson(Map<String, dynamic> json)
51-
: super.fromJson(json,
52-
harmonized: QuantityHarmonized.fromJson(json['harmonized']));
51+
: super.from(json, QuantityHarmonized.fromJson(json['harmonized']));
5352

5453
/// Simplifies creating a list of objects from JSON payload.
5554
///
@@ -80,7 +79,7 @@ class QuantityHarmonized {
8079

8180
final num value;
8281
final String unit;
83-
final Map<String, dynamic> metadata;
82+
final Map<String, dynamic>? metadata;
8483

8584
/// General map representation
8685
///

‎lib/model/payload/sample.dart

+6-7
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import 'workout.dart';
1818
///
1919
/// Supports [map] representation.
2020
///
21-
/// Has a [Sample.fromJson] constructor
22-
/// to create instances from JSON payload coming from iOS native code.
21+
/// Has a [Sample.from] constructor
22+
/// to create instances from JSON payload coming from iOS native code and a generic Harmonized object.
2323
///
2424
/// Has a [factory] method for creating a specific instance of types:
2525
/// - [Quantity]
@@ -56,7 +56,7 @@ abstract class Sample<Harmonized> {
5656
final String identifier;
5757
final num startTimestamp;
5858
final num endTimestamp;
59-
final Device device;
59+
final Device? device;
6060
final SourceRevision sourceRevision;
6161
final Harmonized harmonized;
6262

@@ -66,13 +66,12 @@ abstract class Sample<Harmonized> {
6666

6767
/// General constructor from JSON payload
6868
///
69-
Sample.fromJson(Map<String, dynamic> json, {Harmonized harmonized})
69+
Sample.from(Map<String, dynamic> json, Harmonized harmonized)
7070
: uuid = json['uuid'],
7171
identifier = json['identifier'],
7272
startTimestamp = json['startTimestamp'],
7373
endTimestamp = json['endTimestamp'],
74-
device =
75-
json['device'] != null ? Device.fromJson(json['device']) : null,
74+
device = Device.fromJson(json['device']),
7675
sourceRevision = SourceRevision.fromJson(json['sourceRevision']),
7776
harmonized = harmonized;
7877

@@ -90,7 +89,7 @@ abstract class Sample<Harmonized> {
9089
/// Factory method to create instances as a result of
9190
/// [HealthKitReporter.sampleQuery]
9291
///
93-
static Sample factory(Map<String, dynamic> json) {
92+
static Sample? factory(Map<String, dynamic> json) {
9493
final identifier = json['identifier'];
9594
final quantityType = QuantityTypeFactory.tryFrom(identifier);
9695
if (quantityType != null) {

‎lib/model/payload/source_revision.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class SourceRevision {
1818
);
1919

2020
final Source source;
21-
final String version;
22-
final String productType;
21+
final String? version;
22+
final String? productType;
2323
final String systemVersion;
2424
final OperatingSystem operatingSystem;
2525

‎lib/model/payload/statistics.dart

+5-7
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ class Statistics {
3535
'harmonized': harmonized.map,
3636
};
3737

38-
Statistics.fromJson(Map<String, dynamic> json,
39-
{StatisticsHarmonized harmonized})
38+
Statistics.fromJson(Map<String, dynamic> json)
4039
: identifier = json['identifier'],
4140
startTimestamp = json['startTimestamp'],
4241
endTimestamp = json['endTimestamp'],
43-
sources =
44-
json['sources'] != null ? Source.collect(json['sources']) : null,
42+
sources = Source.collect(json['sources']),
4543
harmonized = StatisticsHarmonized.fromJson(json['harmonized']);
4644
}
4745

@@ -61,9 +59,9 @@ class StatisticsHarmonized {
6159
this.unit,
6260
);
6361

64-
final num summary;
65-
final num average;
66-
final num recent;
62+
final num? summary;
63+
final num? average;
64+
final num? recent;
6765
final String unit;
6866

6967
/// General map representation

‎lib/model/payload/workout.dart

+8-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Workout extends Sample<WorkoutHarmonized> {
2020
String identifier,
2121
num startTimestamp,
2222
num endTimestamp,
23-
Device device,
23+
Device? device,
2424
SourceRevision sourceRevision,
2525
WorkoutHarmonized harmonized,
2626
this.workoutName,
@@ -49,7 +49,7 @@ class Workout extends Sample<WorkoutHarmonized> {
4949
'startTimestamp': startTimestamp,
5050
'endTimestamp': endTimestamp,
5151
'workoutName': workoutName,
52-
'device': device.map,
52+
'device': device?.map,
5353
'sourceRevision': sourceRevision.map,
5454
'duration': duration,
5555
'workoutEvents': workoutEvents.map((e) => e.map).toList(),
@@ -62,8 +62,7 @@ class Workout extends Sample<WorkoutHarmonized> {
6262
: workoutName = json['workoutName'],
6363
duration = json['duration'],
6464
workoutEvents = WorkoutEvent.collect(json['workoutEvents']),
65-
super.fromJson(json,
66-
harmonized: WorkoutHarmonized.fromJson(json['harmonized']));
65+
super.from(json, WorkoutHarmonized.fromJson(json['harmonized']));
6766
}
6867

6968
/// Equivalent of [Workout.Harmonized]
@@ -89,15 +88,15 @@ class WorkoutHarmonized {
8988
);
9089

9190
final int value;
92-
final num totalEnergyBurned;
91+
final num? totalEnergyBurned;
9392
final String totalEnergyBurnedUnit;
94-
final num totalDistance;
93+
final num? totalDistance;
9594
final String totalDistanceUnit;
96-
final num totalSwimmingStrokeCount;
95+
final num? totalSwimmingStrokeCount;
9796
final String totalSwimmingStrokeCountUnit;
98-
final num totalFlightsClimbed;
97+
final num? totalFlightsClimbed;
9998
final String totalFlightsClimbedUnit;
100-
final Map<String, dynamic> metadata;
99+
final Map<String, dynamic>? metadata;
101100

102101
/// General map representation
103102
///

‎lib/model/payload/workout_event.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class WorkoutEventHarmonized {
7070
);
7171

7272
final int value;
73-
final Map<String, dynamic> metadata;
73+
final Map<String, dynamic>? metadata;
7474

7575
/// General map representation
7676
///

‎lib/model/type/activity_summary_type.dart

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import '../../exceptions.dart';
2-
31
/// Equivalent of [ActivitySummaryType]
42
/// from [HealthKitReporter] https://cocoapods.org/pods/HealthKitReporter
53
///
@@ -16,6 +14,5 @@ extension ActivitySummaryTypeIdentifier on ActivitySummaryType {
1614
case ActivitySummaryType.activitySummaryType:
1715
return 'HKActivitySummaryTypeIdentifier';
1816
}
19-
throw InvalidValueException('Unknown case: $this');
2017
}
2118
}

‎lib/model/type/category_type.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ extension CategoryTypeIdentifier on CategoryType {
193193
case CategoryType.wheezing:
194194
return 'HKCategoryTypeIdentifierWheezing';
195195
}
196-
throw InvalidValueException('Unknown case: $this');
197196
}
198197
}
199198

@@ -209,7 +208,7 @@ extension CategoryTypeFactory on CategoryType {
209208

210209
/// The [from] exception handling
211210
///
212-
static CategoryType tryFrom(String identifier) {
211+
static CategoryType? tryFrom(String identifier) {
213212
try {
214213
return from(identifier);
215214
} on InvalidValueException {

‎lib/model/type/characteristic_type.dart

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import '../../exceptions.dart';
2-
31
/// Equivalent of [CharacteristicType]
42
/// from [HealthKitReporter] https://cocoapods.org/pods/HealthKitReporter
53
///
@@ -31,6 +29,5 @@ extension CharacteristicTypeIdentifier on CharacteristicType {
3129
case CharacteristicType.activityMoveMode:
3230
return 'HKCharacteristicTypeIdentifierActivityMoveMode';
3331
}
34-
throw InvalidValueException('Unknown case: $this');
3532
}
3633
}

‎lib/model/type/correlation_type.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ extension CorrelationTypeIdentifier on CorrelationType {
2222
case CorrelationType.food:
2323
return 'HKCorrelationTypeIdentifierFood';
2424
}
25-
throw InvalidValueException('Unknown case: $this');
2625
}
2726
}
2827

@@ -38,7 +37,7 @@ extension CorrelationTypeFactory on CorrelationType {
3837

3938
/// The [from] exception handling
4039
///
41-
static CorrelationType tryFrom(String identifier) {
40+
static CorrelationType? tryFrom(String identifier) {
4241
try {
4342
return from(identifier);
4443
} on InvalidValueException {

‎lib/model/type/document_type.dart

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import '../../exceptions.dart';
2-
31
/// Equivalent of [DocumentType]
42
/// from [HealthKitReporter] https://cocoapods.org/pods/HealthKitReporter
53
///
@@ -16,6 +14,5 @@ extension DocumentTypeIdentifier on DocumentType {
1614
case DocumentType.cda:
1715
return 'HKDocumentTypeIdentifierCDA';
1816
}
19-
throw InvalidValueException('Unknown case: $this');
2017
}
2118
}

‎lib/model/type/electrocardiogram_type.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ extension ElectrocardiogramTypeIdentifier on ElectrocardiogramType {
1919
case ElectrocardiogramType.electrocardiogramType:
2020
return 'HKDataTypeIdentifierElectrocardiogram';
2121
}
22-
throw InvalidValueException('Unknown case: $this');
2322
}
2423
}
2524

@@ -35,7 +34,7 @@ extension ElectrocardiogramTypeFactory on ElectrocardiogramType {
3534

3635
/// The [from] exception handling
3736
///
38-
static ElectrocardiogramType tryFrom(String identifier) {
37+
static ElectrocardiogramType? tryFrom(String identifier) {
3938
try {
4039
return from(identifier);
4140
} on InvalidValueException {

‎lib/model/type/quantity_type.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ extension QuantityTypeIdentifier on QuantityType {
286286
case QuantityType.uvExposure:
287287
return 'HKQuantityTypeIdentifierUVExposure';
288288
}
289-
throw InvalidValueException('Unknown case: $this');
290289
}
291290
}
292291

@@ -302,7 +301,7 @@ extension QuantityTypeFactory on QuantityType {
302301

303302
/// The [from] exception handling
304303
///
305-
static QuantityType tryFrom(String identifier) {
304+
static QuantityType? tryFrom(String identifier) {
306305
try {
307306
return from(identifier);
308307
} on InvalidValueException {

‎lib/model/type/series_type.dart

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import '../../exceptions.dart';
2-
31
/// Equivalent of [SeriesType]
42
/// from [HealthKitReporter] https://cocoapods.org/pods/HealthKitReporter
53
///
@@ -19,6 +17,5 @@ extension SeriesTypeIdentifier on SeriesType {
1917
case SeriesType.route:
2018
return 'HKWorkoutRouteTypeIdentifier';
2119
}
22-
throw InvalidValueException('Unknown case: $this');
2320
}
2421
}

‎lib/model/type/workout_type.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ extension WorkoutTypeIdentifier on WorkoutType {
1616
case WorkoutType.workoutType:
1717
return 'HKWorkoutTypeIdentifier';
1818
}
19-
throw InvalidValueException('Unknown case: $this');
2019
}
2120
}
2221

@@ -32,7 +31,7 @@ extension WorkoutTypeFactory on WorkoutType {
3231

3332
/// The [from] exception handling
3433
///
35-
static WorkoutType tryFrom(String identifier) {
34+
static WorkoutType? tryFrom(String identifier) {
3635
try {
3736
return from(identifier);
3837
} on InvalidValueException {

‎lib/model/update_frequency.dart

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import '../exceptions.dart';
2-
31
/// Equivalent of [UpdateFrequency]
42
/// from [HealthKitReporter] https://cocoapods.org/pods/HealthKitReporter
53
///
@@ -25,6 +23,5 @@ extension Value on UpdateFrequency {
2523
case UpdateFrequency.weekly:
2624
return 4;
2725
}
28-
throw InvalidValueException('Unknown case: $this');
2926
}
3027
}

‎pubspec.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,5 @@ packages:
157157
source: hosted
158158
version: "2.1.0"
159159
sdks:
160-
dart: ">=2.12.0-0.0 <3.0.0"
160+
dart: ">=2.12.0 <3.0.0"
161161
flutter: ">=1.20.0"

‎pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: health_kit_reporter
22
description: Helps to write or read data from Apple Health via HealthKit framework.
3-
version: 1.1.1
3+
version: 1.2.0-nullsafety.0
44
homepage: https://github.com/VictorKachalov/health_kit_reporter
55

66
environment:
7-
sdk: ">=2.7.0 <3.0.0"
7+
sdk: ">=2.12.0 <3.0.0"
88
flutter: ">=1.20.0"
99

1010
dependencies:

0 commit comments

Comments
 (0)
Please sign in to comment.