update flutter_sms to the latest version
This commit is contained in:
@@ -1,32 +1,38 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'src/flutter_sms_platform.dart';
|
||||
import 'src/flutter_sms_io.dart'
|
||||
if (dart.library.js_interop) 'src/flutter_sms_web.dart';
|
||||
|
||||
final FlutterSms _flutterSms = FlutterSms();
|
||||
|
||||
/// Open SMS Dialog on iOS/Android/Web
|
||||
Future<String> sendSMS({
|
||||
required String message,
|
||||
required List<String> recipients,
|
||||
bool sendDirect = false,
|
||||
}) =>
|
||||
FlutterSmsPlatform.instance.sendSMS(
|
||||
message: message,
|
||||
recipients: recipients,
|
||||
sendDirect: sendDirect,
|
||||
);
|
||||
}) {
|
||||
return _flutterSms.sendSMS(
|
||||
message: message,
|
||||
recipients: recipients,
|
||||
);
|
||||
}
|
||||
|
||||
/// Launch SMS Url Scheme on all platforms
|
||||
Future<bool> launchSms({
|
||||
String? message,
|
||||
String? number,
|
||||
}) =>
|
||||
FlutterSmsPlatform.instance.launchSms(number, message);
|
||||
}) {
|
||||
return _flutterSms.launchSms(number, message);
|
||||
}
|
||||
|
||||
/// Launch SMS Url Scheme on all platforms
|
||||
Future<bool> launchSmsMulti({
|
||||
required String message,
|
||||
required List<String> numbers,
|
||||
}) =>
|
||||
FlutterSmsPlatform.instance.launchSmsMulti(numbers, message);
|
||||
}) {
|
||||
return _flutterSms.launchSmsMulti(numbers, message);
|
||||
}
|
||||
|
||||
/// Check if you can send SMS on this platform
|
||||
Future<bool> canSendSMS() => FlutterSmsPlatform.instance.canSendSMS();
|
||||
Future<bool> canSendSMS() {
|
||||
return _flutterSms.canSendSMS();
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
|
||||
|
||||
import 'src/flutter_sms_platform.dart';
|
||||
|
||||
class FlutterSmsPlugin extends FlutterSmsPlatform {
|
||||
static void registerWith(Registrar registrar) {
|
||||
// WidgetsFlutterBinding.ensureInitialized();
|
||||
FlutterSmsPlatform.instance = FlutterSmsPlugin();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> sendSMS({
|
||||
required String message,
|
||||
required List<String> recipients,
|
||||
bool sendDirect = false,
|
||||
}) async {
|
||||
bool _messageSent =
|
||||
await FlutterSmsPlatform.instance.launchSmsMulti(recipients, message);
|
||||
if (_messageSent) return 'Message Sent!';
|
||||
return 'Error Sending Message!';
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> canSendSMS() => Future.value(true);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
abstract class FlutterSmsPlatform {
|
||||
const FlutterSmsPlatform();
|
||||
|
||||
Future<String> sendSMS({
|
||||
required String message,
|
||||
required List<String> recipients,
|
||||
});
|
||||
|
||||
Future<bool> canSendSMS();
|
||||
|
||||
Future<bool> launchSmsMulti(List<String> numbers, [String? body]);
|
||||
|
||||
Future<bool> launchSms(String? number, [String? body]);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_sms/src/messages.g.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import 'flutter_sms_interface.dart';
|
||||
import 'user_agent/io.dart';
|
||||
|
||||
class FlutterSms extends FlutterSmsPlatform {
|
||||
final SmsHostApi _api = SmsHostApi();
|
||||
|
||||
///
|
||||
///
|
||||
Future<String> sendSMS({
|
||||
required String message,
|
||||
required List<String> recipients,
|
||||
}) {
|
||||
return _api.sendSms(message, recipients);
|
||||
}
|
||||
|
||||
Future<bool> canSendSMS() {
|
||||
return _api.canSendSms();
|
||||
}
|
||||
|
||||
Future<bool> launchSmsMulti(List<String> numbers, [String? body]) {
|
||||
if (numbers.length == 1) {
|
||||
return launchSms(numbers.first, body);
|
||||
}
|
||||
String _phones = numbers.join(';');
|
||||
if (body != null) {
|
||||
final _body = Uri.encodeComponent(body);
|
||||
return launchUrl(
|
||||
Uri.parse('sms:/open?addresses=$_phones${separator}body=$_body'));
|
||||
}
|
||||
return launchUrl(Uri.parse('sms:/open?addresses=$_phones'));
|
||||
}
|
||||
|
||||
Future<bool> launchSms(String? number, [String? body]) {
|
||||
// ignore: parameter_assignments
|
||||
number ??= '';
|
||||
if (body != null) {
|
||||
final _body = Uri.encodeComponent(body);
|
||||
return launchUrl(Uri.parse('sms:/$number${separator}body=$_body'));
|
||||
}
|
||||
return launchUrl(Uri.parse('sms:/$number'));
|
||||
}
|
||||
|
||||
String get separator => isCupertino() ? '&' : '?';
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io' show Platform;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import 'user_agent/io.dart' if (dart.library.html) 'user_agent/web.dart';
|
||||
|
||||
const MethodChannel _channel = MethodChannel('flutter_sms');
|
||||
|
||||
class FlutterSmsPlatform extends PlatformInterface {
|
||||
/// Constructs a FlutterSmsPlatform.
|
||||
FlutterSmsPlatform() : super(token: _token);
|
||||
|
||||
static final Object _token = Object();
|
||||
|
||||
static FlutterSmsPlatform _instance = FlutterSmsPlatform();
|
||||
|
||||
/// The default instance of [FlutterSmsPlatform] to use.
|
||||
///
|
||||
/// Defaults to [MethodChannelFlutterSmsPlatform].
|
||||
static FlutterSmsPlatform get instance => _instance;
|
||||
|
||||
/// Platform-specific plugins should set this with their own platform-specific
|
||||
/// class that extends [FlutterSmsPlatform] when they register themselves.
|
||||
// TODO(amirh): Extract common platform interface logic.
|
||||
// https://github.com/flutter/flutter/issues/43368
|
||||
static set instance(FlutterSmsPlatform instance) {
|
||||
PlatformInterface.verifyToken(instance, _token);
|
||||
_instance = instance;
|
||||
}
|
||||
|
||||
///
|
||||
///
|
||||
Future<String> sendSMS({
|
||||
required String message,
|
||||
required List<String> recipients,
|
||||
bool sendDirect = false,
|
||||
}) {
|
||||
final mapData = <dynamic, dynamic>{};
|
||||
mapData['message'] = message;
|
||||
if (!kIsWeb && Platform.isIOS) {
|
||||
mapData['recipients'] = recipients;
|
||||
return _channel
|
||||
.invokeMethod<String>('sendSMS', mapData)
|
||||
.then((value) => value ?? 'Error sending sms');
|
||||
} else {
|
||||
String _phones = recipients.join(';');
|
||||
mapData['recipients'] = _phones;
|
||||
mapData['sendDirect'] = sendDirect;
|
||||
return _channel
|
||||
.invokeMethod<String>('sendSMS', mapData)
|
||||
.then((value) => value ?? 'Error sending sms');
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> canSendSMS() {
|
||||
return _channel
|
||||
.invokeMethod<bool>('canSendSMS')
|
||||
.then((value) => value ?? false);
|
||||
}
|
||||
|
||||
Future<bool> launchSmsMulti(List<String> numbers, [String? body]) {
|
||||
if (numbers.length == 1) {
|
||||
return launchSms(numbers.first, body);
|
||||
}
|
||||
String _phones = numbers.join(';');
|
||||
if (body != null) {
|
||||
final _body = Uri.encodeComponent(body);
|
||||
return launchUrl(
|
||||
Uri.parse('sms:/open?addresses=$_phones${separator}body=$_body'));
|
||||
}
|
||||
return launchUrl(Uri.parse('sms:/open?addresses=$_phones'));
|
||||
}
|
||||
|
||||
Future<bool> launchSms(String? number, [String? body]) {
|
||||
// ignore: parameter_assignments
|
||||
number ??= '';
|
||||
if (body != null) {
|
||||
final _body = Uri.encodeComponent(body);
|
||||
return launchUrl(Uri.parse('sms:/$number${separator}body=$_body'));
|
||||
}
|
||||
return launchUrl(Uri.parse('sms:/$number'));
|
||||
}
|
||||
|
||||
String get separator => isCupertino() ? '&' : '?';
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import 'flutter_sms_interface.dart';
|
||||
import 'user_agent/web.dart';
|
||||
|
||||
class FlutterSms extends FlutterSmsPlatform {
|
||||
@override
|
||||
Future<String> sendSMS({
|
||||
required String message,
|
||||
required List<String> recipients,
|
||||
}) async {
|
||||
bool messageSent = await launchSmsMulti(recipients, message);
|
||||
if (messageSent) return 'Message Sent!';
|
||||
return 'Error Sending Message!';
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> canSendSMS() => Future.value(true);
|
||||
|
||||
@override
|
||||
Future<bool> launchSmsMulti(List<String> numbers, [String? body]) {
|
||||
if (numbers.length == 1) {
|
||||
return launchSms(numbers.first, body);
|
||||
}
|
||||
String phones = numbers.join(';');
|
||||
if (body != null) {
|
||||
final encodedBody = Uri.encodeComponent(body);
|
||||
return launchUrl(
|
||||
Uri.parse('sms:/open?addresses=$phones$separator}body=$encodedBody'));
|
||||
}
|
||||
return launchUrl(Uri.parse('sms:/open?addresses=$phones'));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> launchSms(String? number, [String? body]) {
|
||||
// ignore: parameter_assignments
|
||||
number ??= '';
|
||||
if (body != null) {
|
||||
final encodedBody = Uri.encodeComponent(body);
|
||||
return launchUrl(Uri.parse('sms:/$number$separator}body=$encodedBody'));
|
||||
}
|
||||
return launchUrl(Uri.parse('sms:/$number'));
|
||||
}
|
||||
|
||||
String get separator => isCupertino() ? '&' : '?';
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
// Autogenerated from Pigeon (v26.1.5), do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, omit_obvious_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List;
|
||||
|
||||
import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer;
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
PlatformException _createConnectionError(String channelName) {
|
||||
return PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel: "$channelName".',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
class _PigeonCodec extends StandardMessageCodec {
|
||||
const _PigeonCodec();
|
||||
@override
|
||||
void writeValue(WriteBuffer buffer, Object? value) {
|
||||
if (value is int) {
|
||||
buffer.putUint8(4);
|
||||
buffer.putInt64(value);
|
||||
} else {
|
||||
super.writeValue(buffer, value);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Object? readValueOfType(int type, ReadBuffer buffer) {
|
||||
switch (type) {
|
||||
default:
|
||||
return super.readValueOfType(type, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SmsHostApi {
|
||||
/// Constructor for [SmsHostApi]. The [binaryMessenger] named argument is
|
||||
/// available for dependency injection. If it is left null, the default
|
||||
/// BinaryMessenger will be used which routes to the host platform.
|
||||
SmsHostApi({BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''})
|
||||
: pigeonVar_binaryMessenger = binaryMessenger,
|
||||
pigeonVar_messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : '';
|
||||
final BinaryMessenger? pigeonVar_binaryMessenger;
|
||||
|
||||
static const MessageCodec<Object?> pigeonChannelCodec = _PigeonCodec();
|
||||
|
||||
final String pigeonVar_messageChannelSuffix;
|
||||
|
||||
Future<String> sendSms(String message, List<String> recipients) async {
|
||||
final pigeonVar_channelName = 'dev.flutter.pigeon.flutter_sms.SmsHostApi.sendSms$pigeonVar_messageChannelSuffix';
|
||||
final pigeonVar_channel = BasicMessageChannel<Object?>(
|
||||
pigeonVar_channelName,
|
||||
pigeonChannelCodec,
|
||||
binaryMessenger: pigeonVar_binaryMessenger,
|
||||
);
|
||||
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(<Object?>[message, recipients]);
|
||||
final pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;
|
||||
if (pigeonVar_replyList == null) {
|
||||
throw _createConnectionError(pigeonVar_channelName);
|
||||
} else if (pigeonVar_replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: pigeonVar_replyList[0]! as String,
|
||||
message: pigeonVar_replyList[1] as String?,
|
||||
details: pigeonVar_replyList[2],
|
||||
);
|
||||
} else if (pigeonVar_replyList[0] == null) {
|
||||
throw PlatformException(
|
||||
code: 'null-error',
|
||||
message: 'Host platform returned null value for non-null return value.',
|
||||
);
|
||||
} else {
|
||||
return (pigeonVar_replyList[0] as String?)!;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> canSendSms() async {
|
||||
final pigeonVar_channelName = 'dev.flutter.pigeon.flutter_sms.SmsHostApi.canSendSms$pigeonVar_messageChannelSuffix';
|
||||
final pigeonVar_channel = BasicMessageChannel<Object?>(
|
||||
pigeonVar_channelName,
|
||||
pigeonChannelCodec,
|
||||
binaryMessenger: pigeonVar_binaryMessenger,
|
||||
);
|
||||
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(null);
|
||||
final pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;
|
||||
if (pigeonVar_replyList == null) {
|
||||
throw _createConnectionError(pigeonVar_channelName);
|
||||
} else if (pigeonVar_replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: pigeonVar_replyList[0]! as String,
|
||||
message: pigeonVar_replyList[1] as String?,
|
||||
details: pigeonVar_replyList[2],
|
||||
);
|
||||
} else if (pigeonVar_replyList[0] == null) {
|
||||
throw PlatformException(
|
||||
code: 'null-error',
|
||||
message: 'Host platform returned null value for non-null return value.',
|
||||
);
|
||||
} else {
|
||||
return (pigeonVar_replyList[0] as bool?)!;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,5 +16,11 @@ bool isCupertino() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
final userAgent = web.window.navigator.userAgent.toLowerCase();
|
||||
if (userAgent.contains('iphone') ||
|
||||
userAgent.contains('ipad') ||
|
||||
userAgent.contains('ipod')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user