Skip to content

Commit

Permalink
null safety
Browse files Browse the repository at this point in the history
  • Loading branch information
Shine Wanna authored and Shine Wanna committed Feb 24, 2022
1 parent 5bf4e8a commit 207535e
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 68 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## 0.0.3
## 0.0.4

* Add isSupportCustomSim method which to know the device can set Custom Sim Slot or not.
* Migrated null safety
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ You can send SMS from foreground, background, and headless.

It only support Android for now.

## Getting Started

For help getting started with Flutter, view our online
[documentation](https://flutter.io/).

For help on editing plugin code, view the [documentation](https://flutter.io/platform-plugins/#edit-code).

## Installation and Usage

Add `background_sms` to the dependencies list
Expand Down Expand Up @@ -92,6 +85,11 @@ You can check Custom Sim Slot is support from Native Android.
}
```

## Platform Detail
Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 77d935af4d (2 months ago) • 2021-12-16 08:37:33 -0800
Engine • revision 890a5fca2e
Tools • Dart 2.15.1

### Created by
[Shine Wanna](https://github.com/shinewanna)
6 changes: 3 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class _MyAppState extends State<MyApp> {
Future<bool> _isPermissionGranted() async =>
await Permission.sms.status.isGranted;

_sendMessage(String phoneNumber, String message, {int simSlot}) async {
_sendMessage(String phoneNumber, String message, {int? simSlot}) async {
var result = await BackgroundSms.sendMessage(
phoneNumber: phoneNumber, message: message, simSlot: simSlot);
if (result == SmsStatus.sent) {
Expand All @@ -30,7 +30,7 @@ class _MyAppState extends State<MyApp> {
}
}

Future<bool> get _supportCustomSim async =>
Future<bool?> get _supportCustomSim async =>
await BackgroundSms.isSupportCustomSim;

@override
Expand All @@ -44,7 +44,7 @@ class _MyAppState extends State<MyApp> {
child: Icon(Icons.send),
onPressed: () async {
if (await _isPermissionGranted()) {
if (await _supportCustomSim)
if ((await _supportCustomSim)!)
_sendMessage("09xxxxxxxxx", "Hello", simSlot: 1);
else
_sendMessage("09xxxxxxxxx", "Hello");
Expand Down
71 changes: 46 additions & 25 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,63 +7,63 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.2"
version: "2.8.2"
background_sms:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "0.0.3"
version: "0.0.4"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
version: "1.3.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.13"
version: "1.15.0"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
version: "1.0.4"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -80,42 +80,63 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.8"
version: "0.12.11"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
version: "1.7.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0"
permission_handler:
dependency: "direct main"
description:
name: permission_handler
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.1+1"
version: "9.2.0"
permission_handler_android:
dependency: transitive
description:
name: permission_handler_android
url: "https://pub.dartlang.org"
source: hosted
version: "9.0.2"
permission_handler_apple:
dependency: transitive
description:
name: permission_handler_apple
url: "https://pub.dartlang.org"
source: hosted
version: "9.0.2"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
version: "3.7.0"
permission_handler_windows:
dependency: transitive
description:
name: permission_handler_windows
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
version: "2.1.2"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -127,56 +148,56 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.5"
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.17"
version: "0.4.3"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
version: "2.1.1"
sdks:
dart: ">=2.9.0-14.0.dev <3.0.0"
flutter: ">=1.20.0 <2.0.0"
dart: ">=2.15.0 <3.0.0"
flutter: ">=2.8.0"
6 changes: 3 additions & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: The main purpose is to send sms from background and headless.You ca
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
Expand All @@ -22,8 +22,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.3
permission_handler: ^5.0.1+1
cupertino_icons: ^1.0.4
permission_handler: ^9.2.0

dev_dependencies:
flutter_test:
Expand Down
4 changes: 2 additions & 2 deletions example/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ void main() {
// Verify that platform version is retrieved.
expect(
find.byWidgetPredicate(
(Widget widget) => widget is Text &&
widget.data.startsWith('Running on:'),
(Widget widget) =>
widget is Text && widget.data!.startsWith('Running on:'),
),
findsOneWidget,
);
Expand Down
8 changes: 5 additions & 3 deletions lib/background_sms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ class BackgroundSms {
static const MethodChannel _channel = const MethodChannel('background_sms');

static Future<SmsStatus> sendMessage(
{String phoneNumber, String message, int simSlot}) async {
{required String phoneNumber,
required String message,
int? simSlot}) async {
try {
String result = await _channel.invokeMethod('sendSms', <String, dynamic>{
String? result = await _channel.invokeMethod('sendSms', <String, dynamic>{
"phone": phoneNumber,
"msg": message,
"simSlot": simSlot
Expand All @@ -22,7 +24,7 @@ class BackgroundSms {
}
}

static Future<bool> get isSupportCustomSim async {
static Future<bool?> get isSupportCustomSim async {
try {
return await _channel.invokeMethod('isSupportMultiSim');
} on PlatformException catch (e) {
Expand Down
Loading

0 comments on commit 207535e

Please sign in to comment.