Commit 904930d7 by Zac Chan

Added did tap on ios need testing

parent d4bba0db
...@@ -4,9 +4,13 @@ ...@@ -4,9 +4,13 @@
static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast"; static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
@interface FluttertoastPlugin ()
@property(nonatomic, retain) FluttertoastPlugin *channel;
@end
@implementation FluttertoastPlugin { @implementation FluttertoastPlugin {
FlutterResult _result; FlutterResult _result;
} }
+ (void)registerWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar { + (void)registerWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar {
...@@ -16,6 +20,7 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast"; ...@@ -16,6 +20,7 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
UIViewController *viewController = UIViewController *viewController =
[UIApplication sharedApplication].delegate.window.rootViewController; [UIApplication sharedApplication].delegate.window.rootViewController;
FluttertoastPlugin *instance = [[FluttertoastPlugin alloc] init]; FluttertoastPlugin *instance = [[FluttertoastPlugin alloc] init];
instance.channel = channel;
[registrar addMethodCallDelegate:instance channel:channel]; [registrar addMethodCallDelegate:instance channel:channel];
} }
...@@ -38,7 +43,8 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast"; ...@@ -38,7 +43,8 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
NSString *durationTime = call.arguments[@"time"]; NSString *durationTime = call.arguments[@"time"];
NSNumber *bgcolor = call.arguments[@"bgcolor"]; NSNumber *bgcolor = call.arguments[@"bgcolor"];
NSNumber *textcolor = call.arguments[@"textcolor"]; NSNumber *textcolor = call.arguments[@"textcolor"];
NSNumber *size = call.arguments[@"size"];
int time = 1; int time = 1;
@try { @try {
time = [durationTime intValue]; time = [durationTime intValue];
...@@ -64,7 +70,15 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast"; ...@@ -64,7 +70,15 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
[[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg [[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg
duration:time duration:time
position:CSToastPositionCenter position:CSToastPositionCenter
style:style]; style:style
completion:^(BOOL didTap){
[self.channel invokeMethod:@"onTap" arguments:@{
@"didTao" : didTap
}];
}];
} else { } else {
[[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg [[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg
duration:time duration:time
......
...@@ -80,6 +80,11 @@ static const NSString * CSToastQueueKey = @"CSToastQueueKey"; ...@@ -80,6 +80,11 @@ static const NSString * CSToastQueueKey = @"CSToastQueueKey";
[self showToast:toast duration:duration position:position completion:nil]; [self showToast:toast duration:duration position:position completion:nil];
} }
- (void)makeToast:(NSString *)message duration:(NSTimeInterval)duration position:(id)position style:(CSToastStyle *)style completion:(void(^)(BOOL didTap))completion {
UIView *toast = [self toastViewForMessage:message title:nil image:nil style:style];
[self showToast:toast duration:duration position:position completion:completion];
}
- (void)makeToast:(NSString *)message duration:(NSTimeInterval)duration position:(id)position title:(NSString *)title image:(UIImage *)image style:(CSToastStyle *)style completion:(void(^)(BOOL didTap))completion { - (void)makeToast:(NSString *)message duration:(NSTimeInterval)duration position:(id)position title:(NSString *)title image:(UIImage *)image style:(CSToastStyle *)style completion:(void(^)(BOOL didTap))completion {
UIView *toast = [self toastViewForMessage:message title:title image:image style:style]; UIView *toast = [self toastViewForMessage:message title:title image:image style:style];
[self showToast:toast duration:duration position:position completion:completion]; [self showToast:toast duration:duration position:position completion:completion];
......
...@@ -13,14 +13,33 @@ class Fluttertoast { ...@@ -13,14 +13,33 @@ class Fluttertoast {
static const MethodChannel _channel = static const MethodChannel _channel =
const MethodChannel('PonnamKarthik/fluttertoast'); const MethodChannel('PonnamKarthik/fluttertoast');
static Future<String> showToast({ Fluttertoast _instance;
Fluttertoast get instance {
if (_instance == null) {
}
}
Fluttertoast(){
_channel.setMethodCallHandler(_handleMethod);
}
Function(bool) didTap;
Future<String> showToast({
@required String msg, @required String msg,
Toast toastLength, Toast toastLength,
int timeInSecForIos = 1, int timeInSecForIos = 1,
ToastGravity gravity, ToastGravity gravity,
Color backgroundColor, Color backgroundColor,
Color textColor, Color textColor,
Function(bool) didTap,
}) async { }) async {
this.didTap = didTap;
String toast = "short"; String toast = "short";
if (toastLength == Toast.LENGTH_LONG) { if (toastLength == Toast.LENGTH_LONG) {
toast = "long"; toast = "long";
...@@ -53,4 +72,14 @@ class Fluttertoast { ...@@ -53,4 +72,14 @@ class Fluttertoast {
String res = await _channel.invokeMethod('showToast', params); String res = await _channel.invokeMethod('showToast', params);
return res; return res;
} }
Future<dynamic> _handleMethod(MethodCall call) async {
switch(call.method) {
case "onTap":
didTap(true);
return new Future.value("");
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment