Commit 5081b259 by VJ Pranay Committed by GitHub

Merge pull request #2 from PonnamKarthik/master

Update fork
parents 42a42d3f 653e7dc3
## [2.2.1]
* default toast style fix #38
## [2.2.0]
* Background color fixed #29
## [2.1.5]
* Merged PR #36 - Fix Number Cast Error for issue #35
## [2.1.4]
* Merged PR #32
## [2.1.2]
* iOS Color Fix
* Background color fix in PIE
## [2.1.1]
* Background color does not fill the whole Toast fixed
......
......@@ -11,7 +11,7 @@ Android Toast Library for Flutter
```yaml
# add this line to your dependencies
fluttertoast: ^2.1.1
fluttertoast: ^2.2.1
```
```dart
......@@ -24,8 +24,8 @@ Fluttertoast.showToast(
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIos: 1,
bgcolor: "#e74c3c",
textcolor: '#ffffff'
backgroundColor: Colors.red,
textColor: Colors.white
);
```
......@@ -35,8 +35,8 @@ msg | String (Not Null)(required)
toastLength| Toast.LENGTH_SHORT or Toast.LENGTH_LONG (optional)
gravity | ToastGravity.TOP (or) ToastGravity.CENTER (or) ToastGravity.BOTTOM
timeInSecForIos | int (only for ios)
bgcolor | string (color in hex format)
textcolor| '#ffffff'
bgcolor | Colors.red
textcolor| Colors.white
## Preview Images
......
......@@ -8,7 +8,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
......@@ -32,3 +32,7 @@ android {
disable 'InvalidPackage'
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:27.1.1'
}
package io.github.ponnamkarthik.toast.fluttertoast;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import android.content.Context;
import android.content.ContextWrapper;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RoundRectShape;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.Gravity;
import android.widget.TextView;
import android.widget.Toast;
import android.util.Log;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;
/** FluttertoastPlugin */
public class FluttertoastPlugin implements MethodCallHandler {
Context ctx;
int defaultTextColor = Color.TRANSPARENT;
FluttertoastPlugin(Context context) {
ctx = context;
}
......@@ -39,11 +39,14 @@ public class FluttertoastPlugin implements MethodCallHandler {
String msg = call.argument("msg").toString();
String length = call.argument("length").toString();
String gravity = call.argument("gravity").toString();
String bgcolor = call.argument("bgcolor").toString();
String textcolor = call.argument("textcolor").toString();
Number bgcolor = call.argument("bgcolor");
Number textcolor = call.argument("textcolor");
Toast toast = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT);
toast.setText(msg);
if(length.equals("long")) {
toast.setDuration(Toast.LENGTH_LONG);
} else {
......@@ -60,37 +63,25 @@ public class FluttertoastPlugin implements MethodCallHandler {
default:
toast.setGravity(Gravity.BOTTOM, 0, 100);
}
TextView text = toast.getView().findViewById(android.R.id.message);
if (defaultTextColor == 0) {
defaultTextColor = text.getCurrentTextColor();
}
if (!bgcolor.equals("null")) {
try {
RoundRectShape rectShape = new RoundRectShape(new float[] {100f, 100f, 100f, 100f, 100f, 100f, 100f, 100f}, null, null);
TextView text = toast.getView().findViewById(android.R.id.message);
ShapeDrawable shapeDrawable = new ShapeDrawable(rectShape);
shapeDrawable.getPaint().setColor(Color.parseColor(bgcolor));
shapeDrawable.getPaint().setStyle(Paint.Style.FILL);
shapeDrawable.getPaint().setAntiAlias(true);
shapeDrawable.getPaint().setFlags(Paint.ANTI_ALIAS_FLAG);
if(bgcolor != null) {
Drawable shapeDrawable = ContextCompat.getDrawable(ctx, R.drawable.toast_bg);
if (shapeDrawable != null) {
shapeDrawable.setColorFilter(bgcolor.intValue(), PorterDuff.Mode.SRC_IN);
if (Build.VERSION.SDK_INT <= 27) {
toast.getView().setBackground(shapeDrawable);
// text.setBackground(shapeDrawable);
} catch (Exception e) {
e.printStackTrace();
} else {
text.setBackground(shapeDrawable);
}
}
if (!textcolor.equals("null")) {
try {
text.setTextColor(Color.parseColor(textcolor));
} catch (Exception e) {
e.printStackTrace();
}
} else {
text.setTextColor(defaultTextColor);
if(textcolor != null) {
text.setTextColor(textcolor.intValue());
}
toast.show();
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners
android:radius="100dp">
</corners>
<solid
android:color="#000000">
</solid>
<padding
android:left="24dp"
android:top="15dp"
android:right="24dp"
android:bottom="15dp" />
</shape>
\ No newline at end of file
......@@ -8,7 +8,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
......
#Fri Jun 23 08:50:38 CEST 2017
#Thu Dec 20 12:42:32 IST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
......@@ -25,8 +25,8 @@ class _MyAppState extends State<MyApp> {
Fluttertoast.showToast(
msg: "This is Colored Toast",
toastLength: Toast.LENGTH_SHORT,
bgcolor: "#e74c3c",
textcolor: '#ffffff');
backgroundColor: Colors.red,
textColor: Colors.white);
}
void showShortToast() {
......
......@@ -9,81 +9,65 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
}
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel
+ (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];
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;
}
- (UIColor *)getUIColorObjectFromHexString:(NSString *)hexStr alpha:(CGFloat)alpha
{
// Convert hex string to an integer
unsigned int hexint = [self intFromHexString:hexStr];
- (UIColor*) colorWithHex: (NSUInteger)hex {
CGFloat red, green, blue, alpha;
// 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];
red = ((CGFloat)((hex >> 16) & 0xFF)) / ((CGFloat)0xFF);
green = ((CGFloat)((hex >> 8) & 0xFF)) / ((CGFloat)0xFF);
blue = ((CGFloat)((hex >> 0) & 0xFF)) / ((CGFloat)0xFF);
alpha = hex > 0xFFFFFF ? ((CGFloat)((hex >> 24) & 0xFF)) / ((CGFloat)0xFF) : 1;
return color;
return [UIColor colorWithRed: red green:green blue:blue alpha:alpha];
}
- (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"];
NSNumber *bgcolor = call.arguments[@"bgcolor"];
NSNumber *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(![textcolor isEqualToString:@"null"]) {
style.messageColor = [self getUIColorObjectFromHexString:textcolor alpha:1.0];
}
style.backgroundColor = [self colorWithHex:bgcolor.unsignedIntegerValue];
style.messageColor = [self colorWithHex:textcolor.unsignedIntegerValue];
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"]) {
} else if ([gravity isEqualToString:@"center"]) {
[[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg
duration: time
duration:time
position:CSToastPositionCenter
style:style];
} else {
[[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg
duration: time
duration:time
position:CSToastPositionBottom
style:style];
}
......@@ -94,31 +78,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
import 'dart:async';
import 'dart:ui';
import 'package:flutter/services.dart';
import 'package:meta/meta.dart';
enum Toast { LENGTH_SHORT, LENGTH_LONG }
enum Toast {
LENGTH_SHORT,
LENGTH_LONG
}
enum ToastGravity {
TOP,
BOTTOM,
CENTER
}
enum ToastGravity { TOP, BOTTOM, CENTER }
class Fluttertoast {
static const MethodChannel _channel =
const MethodChannel('PonnamKarthik/fluttertoast');
static Future<String> showToast ({
static Future<String> showToast({
@required String msg,
Toast toastLength,
int timeInSecForIos = 1,
ToastGravity gravity,
String bgcolor = "null",
String textcolor = "null"
Color backgroundColor,
Color textColor,
}) async {
String toast = "short";
if(toastLength == Toast.LENGTH_LONG) {
if (toastLength == Toast.LENGTH_LONG) {
toast = "long";
}
String gravityToast = "bottom";
if(gravity == ToastGravity.TOP) {
if (gravity == ToastGravity.TOP) {
gravityToast = "top";
} else if(gravity == ToastGravity.CENTER) {
} else if (gravity == ToastGravity.CENTER) {
gravityToast = "center";
} else {
gravityToast = "bottom";
}
final Map<String, dynamic> params = <String, dynamic> {
final Map<String, dynamic> params = <String, dynamic>{
'msg': msg,
'length': toast,
'time': timeInSecForIos,
'gravity': gravityToast,
'bgcolor': bgcolor,
'textcolor': textcolor
'bgcolor': backgroundColor != null ? backgroundColor.value : backgroundColor,
'textcolor': textColor != null ? textColor.value: textColor,
};
String res = await _channel.invokeMethod('showToast', params);
return res;
}
}
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
// ignore_for_file: non_constant_identifier_names
// ignore_for_file: camel_case_types
// ignore_for_file: prefer_single_quotes
//This file is automatically generated. DO NOT EDIT, all your changes would be lost.
class S implements WidgetsLocalizations {
const S();
static const GeneratedLocalizationsDelegate delegate =
GeneratedLocalizationsDelegate();
static S of(BuildContext context) => Localizations.of<S>(context, S);
@override
TextDirection get textDirection => TextDirection.ltr;
}
class en extends S {
const en();
}
class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
const GeneratedLocalizationsDelegate();
List<Locale> get supportedLocales {
return const <Locale>[
Locale("en", ""),
];
}
LocaleListResolutionCallback listResolution({Locale fallback}) {
return (List<Locale> locales, Iterable<Locale> supported) {
if (locales == null || locales.isEmpty) {
return fallback ?? supported.first;
} else {
return _resolve(locales.first, fallback, supported);
}
};
}
LocaleResolutionCallback resolution({Locale fallback}) {
return (Locale locale, Iterable<Locale> supported) {
return _resolve(locale, fallback, supported);
};
}
Locale _resolve(Locale locale, Locale fallback, Iterable<Locale> supported) {
if (locale == null || !isSupported(locale)) {
return fallback ?? supported.first;
}
final Locale languageLocale = Locale(locale.languageCode, "");
if (supported.contains(locale)) {
return locale;
} else if (supported.contains(languageLocale)) {
return languageLocale;
} else {
final Locale fallbackLocale = fallback ?? supported.first;
return fallbackLocale;
}
}
@override
Future<S> load(Locale locale) {
final String lang = getLang(locale);
if (lang != null) {
switch (lang) {
case "en":
return SynchronousFuture<S>(const en());
default:
// NO-OP.
}
}
return SynchronousFuture<S>(const S());
}
@override
bool isSupported(Locale locale) =>
locale != null && supportedLocales.contains(locale);
@override
bool shouldReload(GeneratedLocalizationsDelegate old) => false;
}
String getLang(Locale l) => l == null
? null
: l.countryCode != null && l.countryCode.isEmpty
? l.languageCode
: l.toString();
name: fluttertoast
description: Toast Library for FLutter
version: 2.1.1
version: 2.2.1
author: Karthik Ponnam <ponnamkarthik3@gmail.com>
homepage: https://github.com/PonnamKarthik/FlutterToast
......
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