diff --git a/.github/workflows/flutter.yml b/.github/workflows/flutter.yml index a638500..42df8b6 100644 --- a/.github/workflows/flutter.yml +++ b/.github/workflows/flutter.yml @@ -16,7 +16,7 @@ jobs: java-version: '12.x' - uses: subosito/flutter-action@v1 with: - flutter-version: '1.22.4' + flutter-version: '2.0.1' - run: flutter pub get - run: flutter test - run: flutter analyze --no-pub --no-current-package lib diff --git a/CHANGELOG.md b/CHANGELOG.md index ea8a622..5bb6c59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.0.0 +* Add support for null safety + ## 1.0.1 * Improve docs diff --git a/example/lib/analytics.dart b/example/lib/analytics.dart index 0b2f195..eb05333 100644 --- a/example/lib/analytics.dart +++ b/example/lib/analytics.dart @@ -2,14 +2,14 @@ import 'package:mixpanel_flutter/mixpanel_flutter.dart'; class MixpanelManager { - static Mixpanel _instance; + static Mixpanel? _instance; static Future init() async { if (_instance == null) { _instance = await Mixpanel.init("Your Mixpanel Token", optOutTrackingDefault: false); } - return _instance; + return _instance!; } } \ No newline at end of file diff --git a/example/lib/event.dart b/example/lib/event.dart index 7e74a9a..7f6803a 100644 --- a/example/lib/event.dart +++ b/example/lib/event.dart @@ -11,10 +11,10 @@ class EventScreen extends StatefulWidget { } class _EventScreenState extends State { - Mixpanel _mixpanel; + late final Mixpanel _mixpanel; @override - Future initState() { + void initState() { super.initState(); _initMixpanel(); } diff --git a/example/lib/gdpr.dart b/example/lib/gdpr.dart index 0492242..a7b53b1 100644 --- a/example/lib/gdpr.dart +++ b/example/lib/gdpr.dart @@ -9,7 +9,7 @@ class GDPRScreen extends StatefulWidget { } class _GDPRScreenState extends State { - Mixpanel _mixpanel; + late final Mixpanel _mixpanel; @override void initState() { diff --git a/example/lib/group.dart b/example/lib/group.dart index c67104e..cb6492c 100644 --- a/example/lib/group.dart +++ b/example/lib/group.dart @@ -9,8 +9,8 @@ class GroupScreen extends StatefulWidget { } class _GroupScreenState extends State { - Mixpanel _mixpanel; - MixpanelGroup _mixpanelGroup; + late final Mixpanel _mixpanel; + late final MixpanelGroup _mixpanelGroup; @override void initState() { diff --git a/example/lib/profile.dart b/example/lib/profile.dart index 81a6bbf..85a43fa 100644 --- a/example/lib/profile.dart +++ b/example/lib/profile.dart @@ -9,7 +9,7 @@ class ProfileScreen extends StatefulWidget { } class _ProfileScreenState extends State { - Mixpanel _mixpanel; + late final Mixpanel _mixpanel; @override void initState() { diff --git a/example/lib/widget.dart b/example/lib/widget.dart index cb1c06f..4801cac 100644 --- a/example/lib/widget.dart +++ b/example/lib/widget.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; class MixpanelButton extends StatelessWidget { - MixpanelButton({@required this.onPressed, @required this.text}); + MixpanelButton({required this.onPressed, required this.text}); final GestureTapCallback onPressed; final String text; diff --git a/example/pubspec.lock b/example/pubspec.lock index 59c933b..334cf34 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,42 +7,42 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.3" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: @@ -56,7 +56,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -73,28 +73,28 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.1" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" mixpanel_flutter: dependency: "direct main" description: path: ".." relative: true source: path - version: "1.0.0" + version: "2.0.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.1" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -106,56 +106,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.2" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" sdks: - dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.20.0" + dart: ">=2.12.0 <3.0.0" + flutter: ">=2.0.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 7326b49..2c287c2 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -4,7 +4,7 @@ description: Demonstrates how to use the mixpanel_flutter plugin. publish_to: 'none' environment: - sdk: ">=2.7.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" dependencies: flutter: diff --git a/lib/mixpanel_flutter.dart b/lib/mixpanel_flutter.dart index 194c48e..a1fe3bb 100644 --- a/lib/mixpanel_flutter.dart +++ b/lib/mixpanel_flutter.dart @@ -11,13 +11,12 @@ class Mixpanel { 'mp_lib': 'flutter', }; - String _token; - People _people; + final String _token; + final People _people; - Mixpanel(String token) { - this._token = token; - this._people = new People(token); - } + Mixpanel(String token) + : _token = token, + _people = new People(token); /// /// Initializes an instance of the API with the given project token. @@ -27,7 +26,7 @@ class Mixpanel { /// optOutTracking() /// static Future init(String token, - {bool optOutTrackingDefault = false}) async { + {bool? optOutTrackingDefault = false}) async { var properties = {'token': token}; if (optOutTrackingDefault != null) { @@ -66,7 +65,7 @@ class Mixpanel { /// you are running into issues with the SDK that you want to debug /// /// * [loggingEnabled] whether to enable logging - void setLoggingEnabled(bool loggingEnabled) { + void setLoggingEnabled(bool? loggingEnabled) { if (Platform.isIOS) { if (loggingEnabled != null) { _channel.invokeMethod('setLoggingEnabled', @@ -81,7 +80,7 @@ class Mixpanel { /// Will return true if the user has opted out from tracking. /// return true if user has opted out from tracking. Defaults to false. - Future hasOptedOutTracking() async { + Future hasOptedOutTracking() async { return await _channel.invokeMethod('hasOptedOutTracking'); } @@ -101,7 +100,6 @@ class Mixpanel { _channel.invokeMethod('optOutTracking'); } - /// Associate all future calls to track() with the user identified by /// the given distinct id. /// @@ -161,7 +159,7 @@ class Mixpanel { /// /// * [eventName] The name of the event to send /// * [properties] An optional map containing the key value pairs of the properties to include in this event. - void track(String eventName, {Map properties}) { + void track(String eventName, {Map? properties}) { if (_MixpanelHelper.isValidString(eventName)) { _channel.invokeMethod('track', {'eventName': eventName, 'properties': properties}); @@ -326,7 +324,7 @@ class Mixpanel { /// and persist beyond the lifetime of your application. /// /// return Super properties for this Mixpanel instance. - Future getSuperProperties() async { + Future getSuperProperties() async { return await _channel.invokeMethod('getSuperProperties'); } @@ -360,7 +358,7 @@ class Mixpanel { /// * [eventName] the name of the event to be tracked that was previously called with timeEvent() /// /// Time elapsed since timeEvent(String) was called for the given eventName. - Future eventElapsedTime(String eventName) async { + Future eventElapsedTime(String eventName) async { if (_MixpanelHelper.isValidString(eventName)) { return await _channel.invokeMethod( 'eventElapsedTime', {'eventName': eventName}); @@ -386,7 +384,7 @@ class Mixpanel { /// ``` /// /// return Future the distinct id associated with Mixpanel event and People Analytics - Future getDistinctId() { + Future getDistinctId() { return _channel.invokeMethod('getDistinctId'); } @@ -413,11 +411,9 @@ class Mixpanel { class People { static const MethodChannel _channel = const MethodChannel('mixpanel_flutter'); - String _token; + final String _token; - People(String token) { - this._token = token; - } + const People(String token) : _token = token; /// Sets a single property with the given name and value for this user. /// The given name and value will be assigned to the user in Mixpanel People Analytics, @@ -554,17 +550,12 @@ class People { /// /// * [amount] the amount of money exchanged. Positive amounts represent purchases or income from the customer, negative amounts represent refunds or payments to the customer. /// * [properties] an optional collection of properties to associate with this transaction. - void trackCharge(double amount, {Map properties}) { - if (amount != null) { - _channel.invokeMethod('trackCharge', { - 'token': this._token, - 'amount': amount, - 'properties': properties - }); - } else { - developer.log('`people trackCharge` failed: amount cannot be blank', - name: 'Mixpanel'); - } + void trackCharge(double amount, {Map? properties}) { + _channel.invokeMethod('trackCharge', { + 'token': this._token, + 'amount': amount, + 'properties': properties + }); } /// Permanently clear the whole transaction history for the identified people profile. @@ -589,15 +580,14 @@ class People { class MixpanelGroup { static const MethodChannel _channel = const MethodChannel('mixpanel_flutter'); - String _token; - String _groupKey; - dynamic _groupID; + final String _token; + final String _groupKey; + final dynamic _groupID; - MixpanelGroup(String token, String groupKey, dynamic groupID) { - this._token = token; - this._groupKey = groupKey; - this._groupID = groupID; - } + MixpanelGroup(String token, String groupKey, dynamic groupID) + : _token = token, + _groupKey = groupKey, + _groupID = groupID; /// Sets a single property with the given name and value for this group. /// The given name and value will be assigned to the user in Mixpanel Group Analytics, @@ -691,11 +681,6 @@ class MixpanelGroup { name: 'Mixpanel'); return; } - if (value == null) { - developer.log('`group union` failed: value cannot be blank', - name: 'Mixpanel'); - return; - } _channel.invokeMethod('groupUnionProperty', { 'token': this._token, 'groupKey': this._groupKey, @@ -708,6 +693,6 @@ class MixpanelGroup { class _MixpanelHelper { static isValidString(String input) { - return input != null && input.isNotEmpty; + return input.isNotEmpty; } } diff --git a/pubspec.lock b/pubspec.lock index 567db0b..19e8f69 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,49 +7,49 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.3" + version: "1.15.0" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -66,21 +66,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.1" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.1" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -92,56 +92,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.2" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" sdks: - dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.20.0" + dart: ">=2.12.0 <3.0.0" + flutter: ">=2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 239d88a..494be66 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,11 +1,11 @@ name: mixpanel_flutter description: Official Flutter Tracking SDK for Mixpanel Analytics developed and maintained by Mixpanel, Inc. -version: 1.0.1 +version: 2.0.0 homepage: https://mixpanel.com environment: - sdk: ">=2.7.0 <3.0.0" - flutter: ">=1.20.0" + sdk: ">=2.12.0 <3.0.0" + flutter: ">=2.0.0" dependencies: flutter: diff --git a/test/mixpanel_flutter_test.dart b/test/mixpanel_flutter_test.dart index afd5ed6..7176b4f 100644 --- a/test/mixpanel_flutter_test.dart +++ b/test/mixpanel_flutter_test.dart @@ -4,8 +4,8 @@ import 'package:mixpanel_flutter/mixpanel_flutter.dart'; void main() { const MethodChannel channel = MethodChannel('mixpanel_flutter'); - MethodCall methodCall; - Mixpanel _mixpanel; + late MethodCall methodCall; + late Mixpanel _mixpanel; TestWidgetsFlutterBinding.ensureInitialized(); @@ -21,7 +21,6 @@ void main() { tearDown(() { channel.setMockMethodCallHandler(null); - methodCall = null; }); test('check initialize call', () async {