diff --git a/.github/workflows/flutter.yml b/.github/workflows/flutter.yml index a638500..2c981d5 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.3' - run: flutter pub get - run: flutter test - run: flutter analyze --no-pub --no-current-package lib diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 2916c6b..e6c87f7 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1,11 +1,11 @@ PODS: - Flutter (1.0.0) - - Mixpanel-swift (2.8.1): - - Mixpanel-swift/Complete (= 2.8.1) - - Mixpanel-swift/Complete (2.8.1) - - mixpanel_flutter (0.0.1): + - Mixpanel-swift (2.8.3): + - Mixpanel-swift/Complete (= 2.8.3) + - Mixpanel-swift/Complete (2.8.3) + - mixpanel_flutter (1.0.1): - Flutter - - Mixpanel-swift (= 2.8.1) + - Mixpanel-swift (= 2.8.3) DEPENDENCIES: - Flutter (from `Flutter`) @@ -22,9 +22,9 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/mixpanel_flutter/ios" SPEC CHECKSUMS: - Flutter: 0e3d915762c693b495b44d77113d4970485de6ec - Mixpanel-swift: 9d3a2597ef015f187abae0bfa5fda5997d5e4429 - mixpanel_flutter: 78b688d373cd5f0bb5bee423e323124ba3048353 + Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c + Mixpanel-swift: 947354668bf7dcaff5aaf9c64232fb5bea6ff0c7 + mixpanel_flutter: 59130decd93dbb51e1a8a258d0d9af432287768e PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 1d526a1..919434a 100644 --- a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> 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..3caf9b2 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() { + 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..6e6731d 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: "1.0.1" 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" + dart: ">=2.12.0 <3.0.0" flutter: ">=1.20.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 7326b49..f236489 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..00028cf 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. @@ -30,10 +29,7 @@ class Mixpanel { {bool optOutTrackingDefault = false}) async { var properties = {'token': token}; - if (optOutTrackingDefault != null) { - properties['optOutTrackingDefault'] = optOutTrackingDefault; - } - + properties['optOutTrackingDefault'] = optOutTrackingDefault; properties['mixpanelProperties'] = _mixpanelProperties; await _channel.invokeMethod('initialize', properties); @@ -68,6 +64,7 @@ class Mixpanel { /// * [loggingEnabled] whether to enable logging void setLoggingEnabled(bool loggingEnabled) { if (Platform.isIOS) { + // ignore: unnecessary_null_comparison if (loggingEnabled != null) { _channel.invokeMethod('setLoggingEnabled', {'loggingEnabled': loggingEnabled}); @@ -81,7 +78,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 +98,6 @@ class Mixpanel { _channel.invokeMethod('optOutTracking'); } - /// Associate all future calls to track() with the user identified by /// the given distinct id. /// @@ -161,7 +157,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 +322,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 +356,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 +382,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 +409,9 @@ class Mixpanel { class People { static const MethodChannel _channel = const MethodChannel('mixpanel_flutter'); - String _token; + final String _token; - People(String token) { - this._token = token; - } + 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,7 +548,8 @@ 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}) { + void trackCharge(double amount, {Map? properties}) { + // ignore: unnecessary_null_comparison if (amount != null) { _channel.invokeMethod('trackCharge', { 'token': this._token, @@ -589,15 +584,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,6 +685,7 @@ class MixpanelGroup { name: 'Mixpanel'); return; } + // ignore: unnecessary_null_comparison if (value == null) { developer.log('`group union` failed: value cannot be blank', name: 'Mixpanel'); @@ -708,6 +703,7 @@ class MixpanelGroup { class _MixpanelHelper { static isValidString(String input) { + // ignore: unnecessary_null_comparison return input != null && input.isNotEmpty; } } diff --git a/pubspec.lock b/pubspec.lock index 567db0b..37b2e4a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,55 +1,111 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + url: "https://pub.dartlang.org" + source: hosted + version: "19.0.0" + analyzer: + dependency: transitive + description: + name: analyzer + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.0" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" async: dependency: transitive description: 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" + cli_util: + dependency: transitive + description: + name: cli_util + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.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" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" + coverage: + dependency: transitive + description: + name: coverage + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.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" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.0" flutter: dependency: "direct main" description: flutter @@ -60,88 +116,263 @@ packages: description: flutter source: sdk version: "0.0.0" + glob: + dependency: transitive + description: + name: glob + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.0" + io: + dependency: transitive + description: + name: io + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.3" + logging: + dependency: transitive + description: + name: logging + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" matcher: dependency: transitive description: 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" + mime: + dependency: transitive + description: + name: mime + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + node_preamble: + dependency: transitive + description: + name: node_preamble + url: "https://pub.dartlang.org" + source: hosted + version: "1.4.13" + package_config: + dependency: transitive + description: + name: package_config + url: "https://pub.dartlang.org" + source: hosted + 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" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.11.0" + pool: + dependency: transitive + description: + name: pool + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.0" + pub_semver: + dependency: transitive + description: + name: pub_semver + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + shelf: + dependency: transitive + description: + name: shelf + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" + shelf_packages_handler: + dependency: transitive + description: + name: shelf_packages_handler + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" + shelf_static: + dependency: transitive + description: + name: shelf_static + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" sky_engine: dependency: transitive description: flutter source: sdk version: "0.0.99" + source_map_stack_trace: + dependency: transitive + description: + name: source_map_stack_trace + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + source_maps: + dependency: transitive + description: + name: source_maps + url: "https://pub.dartlang.org" + source: hosted + version: "0.10.10" source_span: dependency: transitive description: 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: + dependency: "direct dev" + description: + name: test + url: "https://pub.dartlang.org" + source: hosted + version: "1.16.5" 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" + test_core: + dependency: transitive + description: + name: test_core + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.15" 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" + vm_service: + dependency: transitive + description: + name: vm_service + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.0+1" + watcher: + dependency: transitive + description: + name: watcher + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + webkit_inspection_protocol: + dependency: transitive + description: + name: webkit_inspection_protocol + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + yaml: + dependency: transitive + description: + name: yaml + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.0" sdks: - dart: ">=2.10.0-110 <2.11.0" + dart: ">=2.12.0 <3.0.0" flutter: ">=1.20.0" diff --git a/pubspec.yaml b/pubspec.yaml index 239d88a..6769488 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ version: 1.0.1 homepage: https://mixpanel.com environment: - sdk: ">=2.7.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' flutter: ">=1.20.0" dependencies: @@ -14,6 +14,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter + test: ^1.16.5 flutter: plugin: diff --git a/test/mixpanel_flutter_test.dart b/test/mixpanel_flutter_test.dart index afd5ed6..9d138dc 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; + MethodCall? methodCall; + late Mixpanel _mixpanel; TestWidgetsFlutterBinding.ensureInitialized();