Skip to content

Commit 567878f

Browse files
committed
enable null safety
1 parent 8eb59a4 commit 567878f

13 files changed

+310
-82
lines changed

.github/workflows/flutter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
java-version: '12.x'
1717
- uses: subosito/flutter-action@v1
1818
with:
19-
flutter-version: '1.22.4'
19+
flutter-version: '2.0.3'
2020
- run: flutter pub get
2121
- run: flutter test
2222
- run: flutter analyze --no-pub --no-current-package lib

example/lib/analytics.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import 'package:mixpanel_flutter/mixpanel_flutter.dart';
22

33
class MixpanelManager {
44

5-
static Mixpanel _instance;
5+
static Mixpanel? _instance;
66

77
static Future<Mixpanel> init() async {
88
if (_instance == null) {
99
_instance = await Mixpanel.init("Your Mixpanel Token",
1010
optOutTrackingDefault: false);
1111
}
12-
return _instance;
12+
return _instance!;
1313
}
1414

1515
}

example/lib/event.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ class EventScreen extends StatefulWidget {
1111
}
1212

1313
class _EventScreenState extends State<EventScreen> {
14-
Mixpanel _mixpanel;
14+
late final Mixpanel _mixpanel;
1515

1616
@override
17-
Future<void> initState() {
17+
initState() {
1818
super.initState();
1919
_initMixpanel();
2020
}

example/lib/gdpr.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class GDPRScreen extends StatefulWidget {
99
}
1010

1111
class _GDPRScreenState extends State<GDPRScreen> {
12-
Mixpanel _mixpanel;
12+
late final Mixpanel _mixpanel;
1313

1414
@override
1515
void initState() {

example/lib/group.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class GroupScreen extends StatefulWidget {
99
}
1010

1111
class _GroupScreenState extends State<GroupScreen> {
12-
Mixpanel _mixpanel;
13-
MixpanelGroup _mixpanelGroup;
12+
late final Mixpanel _mixpanel;
13+
late final MixpanelGroup _mixpanelGroup;
1414

1515
@override
1616
void initState() {

example/lib/profile.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ProfileScreen extends StatefulWidget {
99
}
1010

1111
class _ProfileScreenState extends State<ProfileScreen> {
12-
Mixpanel _mixpanel;
12+
late final Mixpanel _mixpanel;
1313

1414
@override
1515
void initState() {

example/lib/widget.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:flutter/material.dart';
22

33
class MixpanelButton extends StatelessWidget {
4-
MixpanelButton({@required this.onPressed, @required this.text});
4+
MixpanelButton({required this.onPressed, required this.text});
55
final GestureTapCallback onPressed;
66
final String text;
77

example/pubspec.lock

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,42 @@ packages:
77
name: async
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "2.5.0-nullsafety.1"
10+
version: "2.5.0"
1111
boolean_selector:
1212
dependency: transitive
1313
description:
1414
name: boolean_selector
1515
url: "https://pub.dartlang.org"
1616
source: hosted
17-
version: "2.1.0-nullsafety.1"
17+
version: "2.1.0"
1818
characters:
1919
dependency: transitive
2020
description:
2121
name: characters
2222
url: "https://pub.dartlang.org"
2323
source: hosted
24-
version: "1.1.0-nullsafety.3"
24+
version: "1.1.0"
2525
charcode:
2626
dependency: transitive
2727
description:
2828
name: charcode
2929
url: "https://pub.dartlang.org"
3030
source: hosted
31-
version: "1.2.0-nullsafety.1"
31+
version: "1.2.0"
3232
clock:
3333
dependency: transitive
3434
description:
3535
name: clock
3636
url: "https://pub.dartlang.org"
3737
source: hosted
38-
version: "1.1.0-nullsafety.1"
38+
version: "1.1.0"
3939
collection:
4040
dependency: transitive
4141
description:
4242
name: collection
4343
url: "https://pub.dartlang.org"
4444
source: hosted
45-
version: "1.15.0-nullsafety.3"
45+
version: "1.15.0"
4646
cupertino_icons:
4747
dependency: "direct main"
4848
description:
@@ -56,7 +56,7 @@ packages:
5656
name: fake_async
5757
url: "https://pub.dartlang.org"
5858
source: hosted
59-
version: "1.2.0-nullsafety.1"
59+
version: "1.2.0"
6060
flutter:
6161
dependency: "direct main"
6262
description: flutter
@@ -73,28 +73,28 @@ packages:
7373
name: matcher
7474
url: "https://pub.dartlang.org"
7575
source: hosted
76-
version: "0.12.10-nullsafety.1"
76+
version: "0.12.10"
7777
meta:
7878
dependency: transitive
7979
description:
8080
name: meta
8181
url: "https://pub.dartlang.org"
8282
source: hosted
83-
version: "1.3.0-nullsafety.3"
83+
version: "1.3.0"
8484
mixpanel_flutter:
8585
dependency: "direct main"
8686
description:
8787
path: ".."
8888
relative: true
8989
source: path
90-
version: "1.0.0"
90+
version: "1.0.1"
9191
path:
9292
dependency: transitive
9393
description:
9494
name: path
9595
url: "https://pub.dartlang.org"
9696
source: hosted
97-
version: "1.8.0-nullsafety.1"
97+
version: "1.8.0"
9898
sky_engine:
9999
dependency: transitive
100100
description: flutter
@@ -106,56 +106,56 @@ packages:
106106
name: source_span
107107
url: "https://pub.dartlang.org"
108108
source: hosted
109-
version: "1.8.0-nullsafety.2"
109+
version: "1.8.0"
110110
stack_trace:
111111
dependency: transitive
112112
description:
113113
name: stack_trace
114114
url: "https://pub.dartlang.org"
115115
source: hosted
116-
version: "1.10.0-nullsafety.1"
116+
version: "1.10.0"
117117
stream_channel:
118118
dependency: transitive
119119
description:
120120
name: stream_channel
121121
url: "https://pub.dartlang.org"
122122
source: hosted
123-
version: "2.1.0-nullsafety.1"
123+
version: "2.1.0"
124124
string_scanner:
125125
dependency: transitive
126126
description:
127127
name: string_scanner
128128
url: "https://pub.dartlang.org"
129129
source: hosted
130-
version: "1.1.0-nullsafety.1"
130+
version: "1.1.0"
131131
term_glyph:
132132
dependency: transitive
133133
description:
134134
name: term_glyph
135135
url: "https://pub.dartlang.org"
136136
source: hosted
137-
version: "1.2.0-nullsafety.1"
137+
version: "1.2.0"
138138
test_api:
139139
dependency: transitive
140140
description:
141141
name: test_api
142142
url: "https://pub.dartlang.org"
143143
source: hosted
144-
version: "0.2.19-nullsafety.2"
144+
version: "0.2.19"
145145
typed_data:
146146
dependency: transitive
147147
description:
148148
name: typed_data
149149
url: "https://pub.dartlang.org"
150150
source: hosted
151-
version: "1.3.0-nullsafety.3"
151+
version: "1.3.0"
152152
vector_math:
153153
dependency: transitive
154154
description:
155155
name: vector_math
156156
url: "https://pub.dartlang.org"
157157
source: hosted
158-
version: "2.1.0-nullsafety.3"
158+
version: "2.1.0"
159159
sdks:
160-
dart: ">=2.10.0-110 <2.11.0"
160+
dart: ">=2.12.0 <3.0.0"
161161
flutter: ">=1.20.0"

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Demonstrates how to use the mixpanel_flutter plugin.
44
publish_to: 'none'
55

66
environment:
7-
sdk: ">=2.7.0 <3.0.0"
7+
sdk: '>=2.12.0 <3.0.0'
88

99
dependencies:
1010
flutter:

lib/mixpanel_flutter.dart

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ class Mixpanel {
1111
'mp_lib': 'flutter',
1212
};
1313

14-
String _token;
15-
People _people;
14+
final String _token;
15+
final People _people;
1616

17-
Mixpanel(String token) {
18-
this._token = token;
19-
this._people = new People(token);
20-
}
17+
Mixpanel(String token)
18+
: _token = token,
19+
_people = new People(token);
2120

2221
///
2322
/// Initializes an instance of the API with the given project token.
@@ -30,10 +29,7 @@ class Mixpanel {
3029
{bool optOutTrackingDefault = false}) async {
3130
var properties = <String, dynamic>{'token': token};
3231

33-
if (optOutTrackingDefault != null) {
34-
properties['optOutTrackingDefault'] = optOutTrackingDefault;
35-
}
36-
32+
properties['optOutTrackingDefault'] = optOutTrackingDefault;
3733
properties['mixpanelProperties'] = _mixpanelProperties;
3834

3935
await _channel.invokeMethod<void>('initialize', properties);
@@ -68,6 +64,7 @@ class Mixpanel {
6864
/// * [loggingEnabled] whether to enable logging
6965
void setLoggingEnabled(bool loggingEnabled) {
7066
if (Platform.isIOS) {
67+
// ignore: unnecessary_null_comparison
7168
if (loggingEnabled != null) {
7269
_channel.invokeMethod<void>('setLoggingEnabled',
7370
<String, dynamic>{'loggingEnabled': loggingEnabled});
@@ -81,7 +78,7 @@ class Mixpanel {
8178

8279
/// Will return true if the user has opted out from tracking.
8380
/// return true if user has opted out from tracking. Defaults to false.
84-
Future<bool> hasOptedOutTracking() async {
81+
Future<bool?> hasOptedOutTracking() async {
8582
return await _channel.invokeMethod<bool>('hasOptedOutTracking');
8683
}
8784

@@ -101,7 +98,6 @@ class Mixpanel {
10198
_channel.invokeMethod<void>('optOutTracking');
10299
}
103100

104-
105101
/// Associate all future calls to track() with the user identified by
106102
/// the given distinct id.
107103
///
@@ -161,7 +157,7 @@ class Mixpanel {
161157
///
162158
/// * [eventName] The name of the event to send
163159
/// * [properties] An optional map containing the key value pairs of the properties to include in this event.
164-
void track(String eventName, {Map<String, dynamic> properties}) {
160+
void track(String eventName, {Map<String, dynamic>? properties}) {
165161
if (_MixpanelHelper.isValidString(eventName)) {
166162
_channel.invokeMethod<void>('track',
167163
<String, dynamic>{'eventName': eventName, 'properties': properties});
@@ -326,7 +322,7 @@ class Mixpanel {
326322
/// and persist beyond the lifetime of your application.
327323
///
328324
/// return Super properties for this Mixpanel instance.
329-
Future<Map> getSuperProperties() async {
325+
Future<Map?> getSuperProperties() async {
330326
return await _channel.invokeMethod<Map>('getSuperProperties');
331327
}
332328

@@ -360,7 +356,7 @@ class Mixpanel {
360356
/// * [eventName] the name of the event to be tracked that was previously called with timeEvent()
361357
///
362358
/// Time elapsed since timeEvent(String) was called for the given eventName.
363-
Future<double> eventElapsedTime(String eventName) async {
359+
Future<double?> eventElapsedTime(String eventName) async {
364360
if (_MixpanelHelper.isValidString(eventName)) {
365361
return await _channel.invokeMethod<double>(
366362
'eventElapsedTime', <String, dynamic>{'eventName': eventName});
@@ -386,7 +382,7 @@ class Mixpanel {
386382
/// ```
387383
///
388384
/// return Future<String> the distinct id associated with Mixpanel event and People Analytics
389-
Future<String> getDistinctId() {
385+
Future<String?> getDistinctId() {
390386
return _channel.invokeMethod<String>('getDistinctId');
391387
}
392388

@@ -413,11 +409,9 @@ class Mixpanel {
413409
class People {
414410
static const MethodChannel _channel = const MethodChannel('mixpanel_flutter');
415411

416-
String _token;
412+
final String _token;
417413

418-
People(String token) {
419-
this._token = token;
420-
}
414+
People(String token) : _token = token;
421415

422416
/// Sets a single property with the given name and value for this user.
423417
/// The given name and value will be assigned to the user in Mixpanel People Analytics,
@@ -554,7 +548,8 @@ class People {
554548
///
555549
/// * [amount] the amount of money exchanged. Positive amounts represent purchases or income from the customer, negative amounts represent refunds or payments to the customer.
556550
/// * [properties] an optional collection of properties to associate with this transaction.
557-
void trackCharge(double amount, {Map<String, dynamic> properties}) {
551+
void trackCharge(double amount, {Map<String, dynamic>? properties}) {
552+
// ignore: unnecessary_null_comparison
558553
if (amount != null) {
559554
_channel.invokeMethod<void>('trackCharge', <String, dynamic>{
560555
'token': this._token,
@@ -589,15 +584,14 @@ class People {
589584
class MixpanelGroup {
590585
static const MethodChannel _channel = const MethodChannel('mixpanel_flutter');
591586

592-
String _token;
593-
String _groupKey;
594-
dynamic _groupID;
587+
final String _token;
588+
final String _groupKey;
589+
final dynamic _groupID;
595590

596-
MixpanelGroup(String token, String groupKey, dynamic groupID) {
597-
this._token = token;
598-
this._groupKey = groupKey;
599-
this._groupID = groupID;
600-
}
591+
MixpanelGroup(String token, String groupKey, dynamic groupID)
592+
: _token = token,
593+
_groupKey = groupKey,
594+
_groupID = groupID;
601595

602596
/// Sets a single property with the given name and value for this group.
603597
/// The given name and value will be assigned to the user in Mixpanel Group Analytics,
@@ -691,6 +685,7 @@ class MixpanelGroup {
691685
name: 'Mixpanel');
692686
return;
693687
}
688+
// ignore: unnecessary_null_comparison
694689
if (value == null) {
695690
developer.log('`group union` failed: value cannot be blank',
696691
name: 'Mixpanel');
@@ -708,6 +703,7 @@ class MixpanelGroup {
708703

709704
class _MixpanelHelper {
710705
static isValidString(String input) {
706+
// ignore: unnecessary_null_comparison
711707
return input != null && input.isNotEmpty;
712708
}
713709
}

0 commit comments

Comments
 (0)