Commit f79f305e by Ben Getsug

attempt fixing ios background color

parent a8ec8c5d
...@@ -20,24 +20,12 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast"; ...@@ -20,24 +20,12 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
} }
- (unsigned int)intFromHexString:(NSString *)hexStr { - (UIColor *)getUIColorObjectFromInt:(unsigned int)value {
unsigned int hexInt = 0;
NSScanner *scanner = [NSScanner scannerWithString:hexStr];
[scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"#"]];
[scanner scanHexInt:&hexInt];
return hexInt;
}
- (UIColor *)getUIColorObjectFromHexString:(NSString *)hexStr alpha:(CGFloat)alpha {
// Convert hex string to an integer
unsigned int hexint = [self intFromHexString:hexStr];
// Create color object, specifying alpha as well
UIColor *color = UIColor *color =
[UIColor colorWithRed:((CGFloat) ((hexint & 0xFF0000) >> 16)) / 255 [UIColor colorWithRed:((CGFloat) ((value & 0xFF) << 16)) / 255
green:((CGFloat) ((hexint & 0xFF00) >> 8)) / 255 green:((CGFloat) ((value & 0xFF) << 8)) / 255
blue:((CGFloat) (hexint & 0xFF)) / 255 blue:((CGFloat) ((value & 0xFF) << 0)) / 255
alpha:alpha]; alpha:((CGFloat) ((value & 0xFF) << 24)) / 255];
return color; return color;
} }
...@@ -47,8 +35,8 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast"; ...@@ -47,8 +35,8 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
NSString *msg = call.arguments[@"msg"]; NSString *msg = call.arguments[@"msg"];
NSString *gravity = call.arguments[@"gravity"]; NSString *gravity = call.arguments[@"gravity"];
NSString *durationTime = call.arguments[@"time"]; NSString *durationTime = call.arguments[@"time"];
NSString *bgcolor = call.arguments[@"bgcolor"]; NSNumber *bgcolor = call.arguments[@"bgcolor"];
NSString *textcolor = call.arguments[@"textcolor"]; NSNumber *textcolor = call.arguments[@"textcolor"];
int time = 1; int time = 1;
@try { @try {
...@@ -62,13 +50,9 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast"; ...@@ -62,13 +50,9 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
CSToastStyle *style = [[CSToastStyle alloc] initWithDefaultStyle]; CSToastStyle *style = [[CSToastStyle alloc] initWithDefaultStyle];
if (![bgcolor isEqualToString:@"null"]) {
style.backgroundColor = [self getUIColorObjectFromHexString:bgcolor alpha:1.0];
}
if (![textcolor isEqualToString:@"null"]) { style.backgroundColor = [self getUIColorObjectFromInt:bgcolor.unsignedIntValue];
style.messageColor = [self getUIColorObjectFromHexString:textcolor alpha:1.0]; style.messageColor = [self getUIColorObjectFromInt:textcolor.unsignedIntValue];
}
if ([gravity isEqualToString:@"top"]) { if ([gravity isEqualToString:@"top"]) {
[[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg [[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg
...@@ -93,31 +77,4 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast"; ...@@ -93,31 +77,4 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
} }
} }
// - (void)showToastView:(FlutterMethodCall*)call:(NSString*)msg {
// [[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg];
// }
// func hexStringToUIColor (hex:String) -> UIColor {
// var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
// if (cString.hasPrefix("#")) {
// cString.remove(at: cString.startIndex)
// }
// if ((cString.count) != 6) {
// return UIColor.gray
// }
// var rgbValue:UInt32 = 0
// Scanner(string: cString).scanHexInt32(&rgbValue)
// return UIColor(
// red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
// green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
// blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
// alpha: CGFloat(1.0)
// )
// }
@end @end
...@@ -17,8 +17,8 @@ class Fluttertoast { ...@@ -17,8 +17,8 @@ class Fluttertoast {
Toast toastLength, Toast toastLength,
int timeInSecForIos = 1, int timeInSecForIos = 1,
ToastGravity gravity, ToastGravity gravity,
Color backgroundColor, Color backgroundColor = const Color.fromARGB(255, 0, 0, 0),
Color textColor, Color textColor = const Color.fromARGB(255, 255, 255, 255),
}) async { }) async {
String toast = "short"; String toast = "short";
if (toastLength == Toast.LENGTH_LONG) { if (toastLength == Toast.LENGTH_LONG) {
...@@ -39,9 +39,8 @@ class Fluttertoast { ...@@ -39,9 +39,8 @@ class Fluttertoast {
'length': toast, 'length': toast,
'time': timeInSecForIos, 'time': timeInSecForIos,
'gravity': gravityToast, 'gravity': gravityToast,
'bgcolor': 'bgcolor': backgroundColor.value,
backgroundColor != null ? backgroundColor.value.toString() : "null", 'textcolor': textColor.value,
'textcolor': textColor != null ? textColor.value.toString() : "null"
}; };
String res = await _channel.invokeMethod('showToast', params); String res = await _channel.invokeMethod('showToast', params);
return res; return res;
......
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