Skip to content

Commit

Permalink
Updated Example to null safety
Browse files Browse the repository at this point in the history
  • Loading branch information
jigarfumakiya committed Aug 9, 2021
1 parent 5f7af46 commit c538aec
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 63 deletions.
2 changes: 1 addition & 1 deletion example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_share_me","path":"/Users/jigafumakiya/Documents/Jigar/plugin/flutter_share_me/","dependencies":[]},{"name":"image_picker","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.8.3+1/","dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-2.0.2/","dependencies":[]},{"name":"flutter_share_me","path":"/Users/jigafumakiya/Documents/Jigar/plugin/flutter_share_me/","dependencies":[]},{"name":"image_picker","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.8.3+1/","dependencies":["flutter_plugin_android_lifecycle"]}],"macos":[],"linux":[],"windows":[],"web":[{"name":"image_picker_for_web","path":"/Users/jigafumakiya/Documents/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_for_web-2.1.2/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"flutter_share_me","dependencies":[]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle","image_picker_for_web"]},{"name":"image_picker_for_web","dependencies":[]}],"date_created":"2021-08-09 21:40:53.331373","version":"2.2.3"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_share_me","path":"/Users/jigafumakiya/Documents/Jigar/plugin/flutter_share_me/","dependencies":[]}],"android":[{"name":"flutter_share_me","path":"/Users/jigafumakiya/Documents/Jigar/plugin/flutter_share_me/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_share_me","dependencies":[]}],"date_created":"2021-08-09 23:04:56.041201","version":"2.2.3"}
101 changes: 45 additions & 56 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_share_me/flutter_share_me.dart';
import 'package:image_picker/image_picker.dart';

enum Share { facebook, twitter, whatsapp, whatsapp_business, share_system }

void main() => runApp(MyApp());

Expand All @@ -10,12 +11,6 @@ class MyApp extends StatefulWidget {
}

class _MyAppState extends State<MyApp> {
String msg = 'Flutter share is great!!';
FlutterShareMe shareMe = FlutterShareMe();
String base;
XFile image;
ImagePicker _picker = ImagePicker();

@override
void initState() {
// TODO: implement initState
Expand All @@ -35,65 +30,59 @@ class _MyAppState extends State<MyApp> {
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(height: 30),
RaisedButton(
child: Text('Pick image'),
onPressed: () async {
image = await _picker.pickImage(source: ImageSource.gallery);
setState(() {});
},
),
SizedBox(height: 30),
RaisedButton(
child: Text('share to twitter'),
onPressed: () async {
var response = await FlutterShareMe().shareToTwitter(
url: 'https://github.com/lizhuoyuan', msg: msg);
if (response == 'success') {
print('navigate success');
}
},
),
RaisedButton(
ElevatedButton(
onPressed: () => onButtonTap(Share.twitter),
child: Text('share to twitter')),
ElevatedButton(
onPressed: () => onButtonTap(Share.whatsapp),
child: Text('share to WhatsApp'),
onPressed: () {

FlutterShareMe().shareToWhatsApp(msg: msg);


},
),
RaisedButton(
child: Text('share to WhatsApp Business'),
onPressed: () async {
String response;

response =await FlutterShareMe().shareToWhatsApp(msg: msg);

print(response);
},
ElevatedButton(
onPressed: () => onButtonTap(Share.whatsapp_business),
child: Text('share to WhatsApp Business'),
),
RaisedButton(
child: Text('share to shareFacebook'),
onPressed: () {
FlutterShareMe().shareToFacebook(
url: 'https://pub.dev/packages/flutter_share_me',
msg: msg);
},
ElevatedButton(
onPressed: () => onButtonTap(Share.facebook),
child: Text('share to FaceBook'),
),
RaisedButton(
ElevatedButton(
onPressed: () => onButtonTap(Share.share_system),
child: Text('share to System'),
onPressed: () async {
var response = await FlutterShareMe()
.shareToSystem(msg: 'Here is the share value');
if (response == 'success') {
print('navigate success');
}
},
),
],
),
),
),
);
}

Future<void> onButtonTap(Share share) async {
String msg =
'Flutter share is great!!\n Check out full example at https://pub.dev/packages/flutter_share_me';
String url = 'https://pub.dev/packages/flutter_share_me';

String? response;
FlutterShareMe flutterShareMe = FlutterShareMe();
switch (share) {
case Share.facebook:
response = await flutterShareMe.shareToFacebook(url: url, msg: msg);
break;
case Share.twitter:
response = await flutterShareMe.shareToTwitter(url: url, msg: msg);
break;
case Share.whatsapp:
response = await flutterShareMe.shareToWhatsApp(msg: msg);
break;
case Share.whatsapp_business:
response = await flutterShareMe.shareToWhatsApp(msg: msg);

break;
case Share.share_system:
response = await flutterShareMe.shareToSystem(msg: msg);

break;
}

print(response);
}
}
3 changes: 1 addition & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Demonstrates how to use the flutter_share_me plugin.
publish_to: 'none'

environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'

dependencies:
flutter:
Expand All @@ -12,7 +12,6 @@ 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
image_picker: ^0.8.3+1

dev_dependencies:
flutter_test:
Expand Down
14 changes: 10 additions & 4 deletions ios/Classes/SwiftFlutterShareMePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,20 @@ public class SwiftFlutterShareMePlugin: NSObject, FlutterPlugin, SharingDelegate
// cast to an url
let urlschme = URL(string: escapedShareString)
// open in safari
if UIApplication.shared.canOpenURL(urlschme! as URL){
UIApplication.shared.openURL(urlschme!)
result("Sucess")
}else{
do {
if UIApplication.shared.canOpenURL(urlschme! as URL){
UIApplication.shared.openURL(urlschme!)
result("Sucess")
}else{
result(FlutterError(code: "Not found", message: "Twitter is not found", details: "Twitter not intalled or Check url scheme."));

}
} catch {
result(FlutterError(code: "Not found", message: "Twitter is not found", details: "Twitter not intalled or Check url scheme."));
}



}


Expand Down
2 changes: 2 additions & 0 deletions lib/flutter_share_me.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class FlutterShareMe {
}

///share to WhatsApp
/// @parm imageUrl is local image
Future<String?> shareToWhatsApp({String msg = '', String imageUrl = ''}) async {
final Map<String, dynamic> arguments = Map<String, dynamic>();
arguments.putIfAbsent('msg', () => msg);
Expand All @@ -47,6 +48,7 @@ class FlutterShareMe {
}

///share to WhatsApp4Biz
/// @parm imageUrl is local image
Future<String?> shareToWhatsApp4Biz({String msg = '', String imageUrl = ''}) async {
final Map<String, dynamic> arguments = Map<String, dynamic>();
arguments.putIfAbsent('msg', () => msg);
Expand Down

0 comments on commit c538aec

Please sign in to comment.