From c612ae8da5fbf384fabf57be3acdf9032101114a Mon Sep 17 00:00:00 2001 From: aref hosseini Date: Wed, 22 Sep 2021 10:04:20 +0330 Subject: [PATCH 1/4] migrate to null safety --- example/lib/main.dart | 18 +++++++++--------- example/pubspec.yaml | 6 +++--- example/test/widget_test.dart | 2 +- lib/sim_info.dart | 10 +++++----- pubspec.yaml | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 42335cf..0ecccfd 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -10,11 +10,11 @@ class MyApp extends StatefulWidget { } class _MyAppState extends State { - String _allowsVOIP; - String _carrierName; - String _isoCountryCode; - String _mobileCountryCode; - String _mobileNetworkCode; + String? _allowsVOIP; + String? _carrierName; + String? _isoCountryCode; + String? _mobileCountryCode; + String? _mobileNetworkCode; @override void initState() { @@ -24,10 +24,10 @@ class _MyAppState extends State { Future getSimInfo() async { String allowsVOIP = await SimInfo.getAllowsVOIP; - String carrierName = await SimInfo.getCarrierName; - String isoCountryCode = await SimInfo.getIsoCountryCode; - String mobileCountryCode = await SimInfo.getMobileCountryCode; - String mobileNetworkCode = await SimInfo.getMobileNetworkCode; + String? carrierName = await SimInfo.getCarrierName; + String? isoCountryCode = await SimInfo.getIsoCountryCode; + String? mobileCountryCode = await SimInfo.getMobileCountryCode; + String? mobileNetworkCode = await SimInfo.getMobileNetworkCode; setState(() { _allowsVOIP = allowsVOIP; diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 5b34acb..7d19f74 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -3,7 +3,7 @@ description: Demonstrates how to use the sim_info plugin. publish_to: 'none' environment: - sdk: ">=2.1.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: @@ -11,8 +11,8 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.2 - permission_handler: ^3.2.0 + cupertino_icons: ^1.0.3 + permission_handler: ^8.1.6 dev_dependencies: flutter_test: diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index 6a8c71d..f48d9f9 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -19,7 +19,7 @@ void main() { expect( find.byWidgetPredicate( (Widget widget) => widget is Text && - widget.data.startsWith('Running on:'), + widget.data!.startsWith('Running on:'), ), findsOneWidget, ); diff --git a/lib/sim_info.dart b/lib/sim_info.dart index e44b0dc..ae8bce2 100644 --- a/lib/sim_info.dart +++ b/lib/sim_info.dart @@ -8,23 +8,23 @@ class SimInfo { const MethodChannel('flutter.moum.sim_info'); static Future get getAllowsVOIP async { - bool value = await _channel.invokeMethod('allowsVOIP'); + bool? value = await _channel.invokeMethod('allowsVOIP'); return value.toString(); } - static Future get getCarrierName async { + static Future get getCarrierName async { return await _channel.invokeMethod('carrierName'); } - static Future get getIsoCountryCode async { + static Future get getIsoCountryCode async { return await _channel.invokeMethod('isoCountryCode'); } - static Future get getMobileCountryCode async { + static Future get getMobileCountryCode async { return await _channel.invokeMethod('mobileCountryCode'); } - static Future get getMobileNetworkCode async { + static Future get getMobileNetworkCode async { return await _channel.invokeMethod('mobileNetworkCode'); } diff --git a/pubspec.yaml b/pubspec.yaml index 6573925..799a503 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,7 +6,7 @@ homepage: https://github.com/flutter-moum/flutter_sim_info environment: - sdk: ">=2.1.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' flutter: ">=1.12.0 <2.0.0" dependencies: From 044f06f66cf76b815bc645bcc4f2963909d1feb3 Mon Sep 17 00:00:00 2001 From: aref hosseini Date: Wed, 22 Sep 2021 14:32:20 +0330 Subject: [PATCH 2/4] android v2 embedding --- .../android/app/src/main/AndroidManifest.xml | 27 ++++++++++++++----- .../moum/sim_info_example/MainActivity.java | 1 - .../app/src/main/res/values/styles.xml | 12 ++++++++- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index f5aa146..e3dd5ae 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -9,7 +9,6 @@ additional functionality it is fine to subclass or reimplement FlutterApplication and put your custom class here. --> - + + android:name="io.flutter.embedding.android.NormalTheme" + android:resource="@style/NormalTheme" + /> + + + + diff --git a/example/android/app/src/main/java/flutter/moum/sim_info_example/MainActivity.java b/example/android/app/src/main/java/flutter/moum/sim_info_example/MainActivity.java index 19a8873..30b30eb 100644 --- a/example/android/app/src/main/java/flutter/moum/sim_info_example/MainActivity.java +++ b/example/android/app/src/main/java/flutter/moum/sim_info_example/MainActivity.java @@ -3,5 +3,4 @@ import io.flutter.embedding.android.FlutterActivity; public class MainActivity extends FlutterActivity { - } diff --git a/example/android/app/src/main/res/values/styles.xml b/example/android/app/src/main/res/values/styles.xml index 00fa441..d460d1e 100644 --- a/example/android/app/src/main/res/values/styles.xml +++ b/example/android/app/src/main/res/values/styles.xml @@ -1,8 +1,18 @@ - + + From b05aec23667dd4511ad96b8cbe44c942b67eee0a Mon Sep 17 00:00:00 2001 From: aref hosseini Date: Sat, 25 Sep 2021 08:56:07 +0330 Subject: [PATCH 3/4] fix MissingPluginException bug & remove deprecate method --- .../java/flutter/moum/sim_info/MethodHandlerImpl.java | 3 ++- .../java/flutter/moum/sim_info/SimInfoPlugin.java | 11 +---------- example/pubspec.yaml | 6 +++--- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/android/src/main/java/flutter/moum/sim_info/MethodHandlerImpl.java b/android/src/main/java/flutter/moum/sim_info/MethodHandlerImpl.java index 2e1f820..cc95678 100644 --- a/android/src/main/java/flutter/moum/sim_info/MethodHandlerImpl.java +++ b/android/src/main/java/flutter/moum/sim_info/MethodHandlerImpl.java @@ -14,7 +14,8 @@ class MethodHandlerImpl implements MethodChannel.MethodCallHandler { Context context; private final TelephonyManager mTelephonyManager; - public MethodHandlerImpl() { + public MethodHandlerImpl(Context context) { + this.context = context; mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); } diff --git a/android/src/main/java/flutter/moum/sim_info/SimInfoPlugin.java b/android/src/main/java/flutter/moum/sim_info/SimInfoPlugin.java index 08131b2..16b111a 100644 --- a/android/src/main/java/flutter/moum/sim_info/SimInfoPlugin.java +++ b/android/src/main/java/flutter/moum/sim_info/SimInfoPlugin.java @@ -6,23 +6,14 @@ import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.MethodChannel; -import io.flutter.plugin.common.PluginRegistry.Registrar; /** SimInfoPlugin */ public class SimInfoPlugin implements FlutterPlugin { private MethodChannel channel; - - /** Plugin registration. */ - public static void registerWith(Registrar registrar) { - SimInfoPlugin plugin = new SimInfoPlugin(); - plugin.setMethodChannel(registrar.context(), registrar.messenger()); - } - private void setMethodChannel(Context context, BinaryMessenger messenger) { channel = new MethodChannel(messenger, "flutter.moum.sim_info"); - channel.setMethodCallHandler(new MethodHandlerImpl()); - + channel.setMethodCallHandler(new MethodHandlerImpl(context)); } @Override diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 7d19f74..e4dbd3d 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -14,13 +14,13 @@ dependencies: cupertino_icons: ^1.0.3 permission_handler: ^8.1.6 + sim_info: + path: ../ + dev_dependencies: flutter_test: sdk: flutter - sim_info: - path: ../ - # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec From 534b8c6dd3e9187c62f9dd77f410b9f73d887a8e Mon Sep 17 00:00:00 2001 From: Aref Hosseini Date: Sat, 25 Sep 2021 09:11:47 +0330 Subject: [PATCH 4/4] Update README.md Add null safety to example --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 6df6702..2471ab3 100644 --- a/README.md +++ b/README.md @@ -28,11 +28,11 @@ import 'package:sim_info/sim_info.dart'; Use below to get SIM data: ```dart - String _allowsVOIP; - String _carrierName; - String _isoCountryCode; - String _mobileCountryCode; - String _mobileNetworkCode; + String? _allowsVOIP; + String? _carrierName; + String? _isoCountryCode; + String? _mobileCountryCode; + String? _mobileNetworkCode; @override void initState() { @@ -41,11 +41,11 @@ Use below to get SIM data: } void getSimInfo() async { - String allowsVOIP = await SimInfo.getAllowsVOIP; - String carrierName = await SimInfo.getCarrierName; - String isoCountryCode = await SimInfo.getIsoCountryCode; - String mobileCountryCode = await SimInfo.getMobileCountryCode; - String mobileNetworkCode = await SimInfo.getMobileNetworkCode; + String? allowsVOIP = await SimInfo.getAllowsVOIP; + String? carrierName = await SimInfo.getCarrierName; + String? isoCountryCode = await SimInfo.getIsoCountryCode; + String? mobileCountryCode = await SimInfo.getMobileCountryCode; + String? mobileNetworkCode = await SimInfo.getMobileNetworkCode; } ``` [Full list of available SIM data](https://github.com/flutter-moum/flutter_sim_info/wiki).