Skip to content

Commit 957ceaa

Browse files
committed
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
///

0 commit comments

Comments
 (0)