Commit 6e52d4a9 by Ben Getsug

attempt fixing ios background color

parent da7609f5
......@@ -9,85 +9,84 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
}
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:CHANNEL_NAME
binaryMessenger:[registrar messenger]];
+ (void)registerWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar {
FlutterMethodChannel *channel = [FlutterMethodChannel
methodChannelWithName:CHANNEL_NAME
binaryMessenger:[registrar messenger]];
UIViewController *viewController =
[UIApplication sharedApplication].delegate.window.rootViewController;
FluttertoastPlugin* instance = [[FluttertoastPlugin alloc] init];
[UIApplication sharedApplication].delegate.window.rootViewController;
FluttertoastPlugin *instance = [[FluttertoastPlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel];
}
- (unsigned int)intFromHexString:(NSString *)hexStr {
unsigned int hexInt = 0;
NSScanner *scanner = [NSScanner scannerWithString:hexStr];
[scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"#"]];
[scanner scanHexInt:&hexInt];
return hexInt;
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
{
- (UIColor *)getUIColorObjectFromHexString:(NSString *)hexStr alpha:(CGFloat)alpha {
// Convert hex string to an integer
unsigned int hexint = [self intFromHexString:hexStr];
unsigned int hexint = [self intFromHexString:hexStr];
// Create color object, specifying alpha as well
UIColor *color =
[UIColor colorWithRed:((CGFloat) ((hexint & 0xFF0000) >> 16))/255
green:((CGFloat) ((hexint & 0xFF00) >> 8))/255
blue:((CGFloat) (hexint & 0xFF))/255
alpha:alpha];
UIColor *color =
[UIColor colorWithRed:((CGFloat) ((hexint & 0xFF0000) >> 16)) / 255
green:((CGFloat) ((hexint & 0xFF00) >> 8)) / 255
blue:((CGFloat) (hexint & 0xFF)) / 255
alpha:alpha];
return color;
return color;
}
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
if ([@"showToast" isEqualToString:call.method]) {
NSString *msg = call.arguments[@"msg"];
NSString *gravity = call.arguments[@"gravity"];
NSString *durationTime = call.arguments[@"time"];
NSString *bgcolor = call.arguments[@"bgcolor"];
NSString *textcolor = call.arguments[@"textcolor"];
int time = 1;
@try{
@try {
time = [durationTime intValue];
} @catch(NSException *e){
} @catch (NSException *e) {
time = 3;
}
if(time > 10 ) time = 10;
else if(time < 1) time = 1;
if (time > 10) time = 10;
else if (time < 1) time = 1;
CSToastStyle *style = [[CSToastStyle alloc] initWithDefaultStyle];
if(![bgcolor isEqualToString:@"null"]) {
style.self.backgroundColor = [self getUIColorObjectFromHexString:bgcolor alpha:1.0];
if (![bgcolor isEqualToString:@"null"]) {
style.backgroundColor = [self getUIColorObjectFromHexString:bgcolor alpha:1.0];
}
if(![textcolor isEqualToString:@"null"]) {
if (![textcolor isEqualToString:@"null"]) {
style.messageColor = [self getUIColorObjectFromHexString:textcolor alpha:1.0];
}
if([gravity isEqualToString:@"top"]) {
if ([gravity isEqualToString:@"top"]) {
[[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg
duration: time
duration:time
position:CSToastPositionTop
style:style];
} else if([gravity isEqualToString:@"center"]) {
style:style];
} else if ([gravity isEqualToString:@"center"]) {
[[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg
duration: time
duration:time
position:CSToastPositionCenter
style:style];
style:style];
} else {
[[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg
duration: time
duration:time
position:CSToastPositionBottom
style:style];
style:style];
}
result(@"done");
} else {
result(FlutterMethodNotImplemented);
......
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