Commit 63449b28 by Zac Chan

using Result instead of callback

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