From 41b5f8dfafca97227ca6fd9c988d722ebe97b19d Mon Sep 17 00:00:00 2001 From: Amir Panahandeh Date: Mon, 29 Mar 2021 13:54:44 +0430 Subject: [PATCH 1/2] Migrated to null safety --- lib/flutter_user_agent.dart | 18 +++++++++--------- pubspec.yaml | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/flutter_user_agent.dart b/lib/flutter_user_agent.dart index 11312ef..edf3164 100644 --- a/lib/flutter_user_agent.dart +++ b/lib/flutter_user_agent.dart @@ -5,7 +5,7 @@ import 'package:flutter/services.dart'; class FlutterUserAgent { static const MethodChannel _channel = MethodChannel('flutter_user_agent'); - static Map _properties; + static Map? _properties; /// Initialize the module. /// @@ -16,7 +16,7 @@ class FlutterUserAgent { static Future init({force: false}) async { if (_properties == null || force) { _properties = - Map.unmodifiable(await _channel.invokeMethod('getProperties')); + Map.unmodifiable(await (_channel.invokeMethod('getProperties') as FutureOr>)); } } @@ -27,28 +27,28 @@ class FlutterUserAgent { } /// Returns the device's user agent. - static String get userAgent { - return _properties['userAgent']; + static String? get userAgent { + return _properties?['userAgent']; } /// Returns the device's webview user agent. - static String get webViewUserAgent { - return _properties['webViewUserAgent']; + static String? get webViewUserAgent { + return _properties?['webViewUserAgent']; } /// Fetch a [property] that can be used to build your own user agent string. static dynamic getProperty(String property) { - return _properties[property]; + return _properties?[property]; } /// Fetch a [property] asynchronously that can be used to build your own user agent string. static dynamic getPropertyAsync(String property) async { await init(); - return _properties[property]; + return _properties?[property]; } /// Return a map of properties that can be used to generate the user agent string. - static Map get properties { + static Map? get properties { return _properties; } } diff --git a/pubspec.yaml b/pubspec.yaml index 4617469..9f085d2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,7 +6,7 @@ version: 1.2.2 homepage: https://github.com/j0j00/flutter_user_agent environment: - sdk: ">=2.0.0-dev.68.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: From 6e720683520ac787ae83e34f82f769cc5694f0a8 Mon Sep 17 00:00:00 2001 From: Amir Panahandeh Date: Mon, 5 Apr 2021 09:20:58 +0430 Subject: [PATCH 2/2] Fixed issue with type casting caused by dart migrate --- lib/flutter_user_agent.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/flutter_user_agent.dart b/lib/flutter_user_agent.dart index edf3164..da4bf18 100644 --- a/lib/flutter_user_agent.dart +++ b/lib/flutter_user_agent.dart @@ -16,7 +16,7 @@ class FlutterUserAgent { static Future init({force: false}) async { if (_properties == null || force) { _properties = - Map.unmodifiable(await (_channel.invokeMethod('getProperties') as FutureOr>)); + Map.unmodifiable(await _channel.invokeMethod('getProperties')); } }