Commit 63449b28 by Zac Chan

using Result instead of callback

parent 9e385713
......@@ -55,7 +55,6 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
if (time > 10) time = 10;
else if (time < 1) time = 1;
NSLog(@"The code runs through here!");
CSToastStyle *style = [[CSToastStyle alloc] initWithDefaultStyle];
......@@ -73,11 +72,10 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
position:CSToastPositionCenter
style:style
completion:^(BOOL didTap){
NSNumber *boolNumber = [NSNumber numberWithBool:didTap];
NSLog(@"The code runs through here! 2");
[self.channel invokeMethod:@"onTap" arguments:@{
@"didTap" : boolNumber
}];
NSNumber *boolNumber = [NSNumber numberWithBool:didTap];
result(boolNumber)
}];
......@@ -88,7 +86,6 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
style:style];
}
result(@"done");
} else {
result(FlutterMethodNotImplemented);
}
......
......@@ -29,18 +29,18 @@ class Fluttertoast {
}
Function(bool) didTap;
// Function(bool) didTap;
Future<String> showToast({
Future<bool> showToast({
@required String msg,
Toast toastLength,
int timeInSecForIos = 1,
ToastGravity gravity,
Color backgroundColor,
Color textColor,
Function(bool) didTap,
// Function(bool) didTap,
}) async {
this.didTap = didTap;
// this.didTap = didTap;
String toast = "short";
if (toastLength == Toast.LENGTH_LONG) {
toast = "long";
......@@ -70,17 +70,17 @@ class Fluttertoast {
'textcolor': textColor != null ? textColor.value: null,
};
String res = await _channel.invokeMethod('showToast', params);
bool res = await _channel.invokeMethod('showToast', params);
return res;
}
Future<dynamic> _handleMethod(MethodCall call) async {
switch(call.method) {
case "onTap":
// Future<dynamic> _handleMethod(MethodCall call) async {
// switch(call.method) {
// case "onTap":
didTap(true);
// didTap(true);
return new Future.value("");
}
}
// 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