Commit a10da367 by Karthik Ponnam

v7.1.0

parent 92760b47
## [7.1.0]
- Breaking change for FToast, Need to call `FToast.init(context)` before `showToast`
- AnimationController fix
- Android `NonNull` build Fix
- FToast Added new `PositionedToastBuilder` you can define Custom Postition now for toast
- Merged #228, Fix UIView+Toast.o duplicate symbols - Thanks @jackkang0401 and @yongshuai.kang
- Now `textcolor` will work for web toast
## [7.0.4]
- iOS Build Failed Fixed #218
......
......@@ -34,7 +34,7 @@ This one has limited features and no control over UI
```yaml
# add this line to your dependencies
fluttertoast: ^7.0.4
fluttertoast: ^7.1.0
```
```dart
......@@ -112,7 +112,8 @@ FToast fToast;
@override
void initState() {
super.initState();
fToast = FToast(context);
fToast = FToast();
fToast.init(context);
}
_showToast() {
......@@ -140,6 +141,18 @@ _showToast() {
gravity: ToastGravity.BOTTOM,
toastDuration: Duration(seconds: 2),
);
// Custom Toast Position
fToast.showToast(
child: toast,
toastDuration: Duration(seconds: 2),
positionedToastBuilder: (context, child) {
return Positioned(
child: child,
top: 16.0,
left: 16.0,
);
});
}
```
......@@ -179,6 +192,9 @@ fToast.removeQueuedCustomToasts();
...
## Help needed for iOS
Looking for iOS Dev who can check out and fix the issues releated to iOS (I dont have a Mac and iOS)
## Buy Me a Coffee
......
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value>
<package name="java.util" alias="false" withSubpackages="false" />
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
<package name="io.ktor" alias="false" withSubpackages="true" />
</value>
</option>
<option name="PACKAGES_IMPORT_LAYOUT">
<value>
<package name="" alias="false" withSubpackages="true" />
<package name="java" alias="false" withSubpackages="true" />
<package name="javax" alias="false" withSubpackages="true" />
<package name="kotlin" alias="false" withSubpackages="true" />
<package name="" alias="true" withSubpackages="true" />
</value>
</option>
</JetCodeStyleSettings>
<codeStyleSettings language="XML">
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
......
......@@ -3,6 +3,7 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/modules/FlutterToast.iml" filepath="$PROJECT_DIR$/.idea/modules/FlutterToast.iml" group="FlutterToast" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/com.example.FlutterToast-FlutterToast.iml" filepath="$PROJECT_DIR$/.idea/modules/com.example.FlutterToast-FlutterToast.iml" group="FlutterToast" />
</modules>
</component>
</project>
\ No newline at end of file
package io.github.ponnamkarthik.toast.fluttertoast
import android.content.Context
import androidx.annotation.NonNull
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MethodChannel
......
......@@ -48,7 +48,7 @@ internal class MethodCallHandlerImpl(var context: Context) : MethodCallHandler {
} else {
context.resources.getDrawable(R.drawable.corner)
}
if(bgcolor != null && gradientDrawable != null) {
if(bgcolor != null) {
gradientDrawable.setColorFilter(bgcolor.toInt(), PorterDuff.Mode.SRC)
}
text.background = gradientDrawable
......@@ -59,17 +59,21 @@ internal class MethodCallHandlerImpl(var context: Context) : MethodCallHandler {
text.setTextColor(textcolor.toInt())
}
mToast = Toast(context)
mToast.setDuration(mDuration)
mToast.setView(layout)
mToast.duration = mDuration
mToast.view = layout
} else {
mToast = Toast.makeText(context, mMessage, mDuration)
}
if (mGravity == Gravity.CENTER) {
mToast.setGravity(mGravity, 0, 0)
} else if (mGravity == Gravity.TOP) {
mToast.setGravity(mGravity, 0, 100)
} else {
mToast.setGravity(mGravity, 0, 100)
when (mGravity) {
Gravity.CENTER -> {
mToast.setGravity(mGravity, 0, 0)
}
Gravity.TOP -> {
mToast.setGravity(mGravity, 0, 100)
}
else -> {
mToast.setGravity(mGravity, 0, 100)
}
}
if (context is Activity) {
(context as Activity).runOnUiThread { mToast.show() }
......@@ -79,9 +83,7 @@ internal class MethodCallHandlerImpl(var context: Context) : MethodCallHandler {
result.success(true)
}
"cancel" -> {
if (mToast != null) {
mToast.cancel()
}
mToast.cancel()
result.success(true)
}
else -> result.notImplemented()
......
package com.example.example
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/yongshuai.kang/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/yongshuai.kang/Desktop/FlutterToast/example"
export "FLUTTER_TARGET=/Users/yongshuai.kang/Desktop/FlutterToast/example/lib/main.dart"
export "FLUTTER_ROOT=C:\Users\ponna\Desktop\sdk\flutter"
export "FLUTTER_APPLICATION_PATH=C:\Users\ponna\Desktop\my\plugins\fluttertoast\example"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "SYMROOT=${SOURCE_ROOT}/../build\ios"
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
export "FLUTTER_FRAMEWORK_DIR=/Users/yongshuai.kang/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_FRAMEWORK_DIR=C:\Users\ponna\Desktop\sdk\flutter\bin\cache\artifacts\engine\ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "TRACK_WIDGET_CREATION=true"
export "DART_DEFINES=flutter.inspector.structuredErrors=true"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=false"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.packages"
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
#import "GeneratedPluginRegistrant.h"
......@@ -35,6 +35,20 @@ class _ToastContextState extends State<ToastContext> {
);
}
_showBuilderToast() {
fToast.showToast(
child: toast,
gravity: ToastGravity.BOTTOM,
toastDuration: Duration(seconds: 2),
positionedToastBuilder: (context, child) {
return Positioned(
child: child,
top: 16.0,
left: 16.0,
);
});
}
_showToastCancel() {
Widget toastWithButton = Container(
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
......@@ -112,7 +126,8 @@ class _ToastContextState extends State<ToastContext> {
@override
void initState() {
super.initState();
fToast = FToast(context);
fToast = FToast();
fToast.init(context);
}
@override
......@@ -132,6 +147,12 @@ class _ToastContextState extends State<ToastContext> {
_showToast();
},
),
RaisedButton(
child: Text("Show Custom Toast via PositionedToastBuilder"),
onPressed: () {
_showBuilderToast();
},
),
SizedBox(
height: 24.0,
),
......
......@@ -14,6 +14,7 @@ class ToastNoContext extends StatelessWidget {
msg: "This is Colored Toast with android duration of 5 Sec",
toastLength: Toast.LENGTH_SHORT,
webBgColor: "#e74c3c",
textColor: Colors.black,
timeInSecForIosWeb: 5,
);
}
......
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.13"
args:
dependency: transitive
description:
name: args
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.6.0"
async:
dependency: transitive
description:
name: async
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.1"
version: "2.5.0-nullsafety"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
charcode:
version: "2.1.0-nullsafety"
characters:
dependency: transitive
description:
name: charcode
url: "https://pub.flutter-io.cn"
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
collection:
version: "1.1.0-nullsafety.2"
charcode:
dependency: transitive
description:
name: collection
url: "https://pub.flutter-io.cn"
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.12"
convert:
version: "1.2.0-nullsafety"
clock:
dependency: transitive
description:
name: convert
url: "https://pub.flutter-io.cn"
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
crypto:
version: "1.1.0-nullsafety"
collection:
dependency: transitive
description:
name: crypto
url: "https://pub.flutter-io.cn"
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
version: "1.15.0-nullsafety.2"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety"
flutter:
dependency: "direct main"
description: flutter
......@@ -85,49 +78,28 @@ packages:
path: ".."
relative: true
source: path
version: "7.0.4"
image:
dependency: transitive
description:
name: image
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.12"
version: "7.1.0"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.6"
version: "0.12.10-nullsafety"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
version: "1.3.0-nullsafety.2"
path:
dependency: transitive
description:
name: path
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.6.4"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.4.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
version: "1.8.0-nullsafety"
sky_engine:
dependency: transitive
description: flutter
......@@ -137,65 +109,58 @@ packages:
dependency: transitive
description:
name: source_span
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0-nullsafety"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.3"
version: "1.10.0-nullsafety"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0-nullsafety"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
version: "1.1.0-nullsafety"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0-nullsafety"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.15"
version: "0.2.19-nullsafety"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.3.0-nullsafety.2"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.8"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "3.6.1"
version: "2.1.0-nullsafety.2"
sdks:
dart: ">=2.7.0 <3.0.0"
dart: ">=2.10.0-0.0.dev <2.10.0"
flutter: ">=1.10.0"
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="A new Flutter project.">
<!-- iOS meta tags & icons -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="example">
<link rel="apple-touch-icon" href="icons/Icon-192.png">
<!-- Favicon -->
<link rel="icon" type="image/png" href="favicon.png"/>
<title>example</title>
<link rel="manifest" href="manifest.json">
</head>
<body>
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('flutter_service_worker.js');
});
}
</script>
<script src="main.dart.js" type="application/javascript"></script>
</body>
</html>
{
"name": "example",
"short_name": "example",
"start_url": ".",
"display": "standalone",
"background_color": "#0175C2",
"theme_color": "#0175C2",
"description": "A new Flutter project.",
"orientation": "portrait-primary",
"prefer_related_applications": false,
"icons": [
{
"src": "icons/Icon-192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "icons/Icon-512.png",
"sizes": "512x512",
"type": "image/png"
}
]
}
......@@ -67,16 +67,21 @@ class Fluttertoast {
}
}
typedef PositionedToastBuilder = Widget Function(BuildContext context, Widget child);
class FToast {
BuildContext context;
static final FToast _instance = FToast._internal();
factory FToast(BuildContext context) {
_instance.context = context;
factory FToast() {
return _instance;
}
init(BuildContext context) {
_instance.context = context;
}
FToast._internal();
OverlayEntry _entry;
......@@ -90,7 +95,7 @@ class FToast {
}
_ToastEntry _toastEntry = _overlayQueue.removeAt(0);
_entry = _toastEntry.entry;
if (context == null) throw ("Error: Context is null");
if (context == null) throw ("Error: Context is null, Please call init(context) before showing toast.");
Overlay.of(context).insert(_entry);
_timer = Timer(_toastEntry.duration, () {
......@@ -117,52 +122,54 @@ class FToast {
void showToast({
@required Widget child,
PositionedToastBuilder positionedToastBuilder,
Duration toastDuration,
ToastGravity gravity,
}) {
Widget newChild = _ToastStateFul(
child,
toastDuration ?? Duration(seconds: 2),
);
OverlayEntry newEntry = OverlayEntry(builder: (context) {
return _getPostionWidgetBasedOnGravity(child, gravity, toastDuration);
if (positionedToastBuilder != null) return positionedToastBuilder(context, newChild);
return _getPostionWidgetBasedOnGravity(newChild, gravity);
});
_overlayQueue.add(_ToastEntry(entry: newEntry, duration: toastDuration ?? Duration(seconds: 2)));
if (_timer == null) _showOverlay();
}
_getPostionWidgetBasedOnGravity(Widget child, ToastGravity gravity, Duration duration) {
Widget newChild = _ToastStateFul(
child,
duration,
);
_getPostionWidgetBasedOnGravity(Widget child, ToastGravity gravity) {
switch (gravity) {
case ToastGravity.TOP:
return Positioned(top: 100.0, left: 24.0, right: 24.0, child: newChild);
return Positioned(top: 100.0, left: 24.0, right: 24.0, child: child);
break;
case ToastGravity.TOP_LEFT:
return Positioned(top: 100.0, left: 24.0, child: newChild);
return Positioned(top: 100.0, left: 24.0, child: child);
break;
case ToastGravity.TOP_RIGHT:
return Positioned(top: 100.0, right: 24.0, child: newChild);
return Positioned(top: 100.0, right: 24.0, child: child);
break;
case ToastGravity.CENTER:
return Positioned(top: 50.0, bottom: 50.0, left: 24.0, right: 24.0, child: newChild);
return Positioned(top: 50.0, bottom: 50.0, left: 24.0, right: 24.0, child: child);
break;
case ToastGravity.CENTER_LEFT:
return Positioned(top: 50.0, bottom: 50.0, left: 24.0, child: newChild);
return Positioned(top: 50.0, bottom: 50.0, left: 24.0, child: child);
break;
case ToastGravity.CENTER_RIGHT:
return Positioned(top: 50.0, bottom: 50.0, right: 24.0, child: newChild);
return Positioned(top: 50.0, bottom: 50.0, right: 24.0, child: child);
break;
case ToastGravity.BOTTOM_LEFT:
return Positioned(bottom: 50.0, left: 24.0, child: newChild);
return Positioned(bottom: 50.0, left: 24.0, child: child);
break;
case ToastGravity.BOTTOM_RIGHT:
return Positioned(bottom: 50.0, right: 24.0, child: newChild);
return Positioned(bottom: 50.0, right: 24.0, child: child);
break;
case ToastGravity.SNACKBAR:
return Positioned(bottom: MediaQuery.of(context).viewInsets.bottom, left: 0, right: 0, child: newChild);
return Positioned(bottom: MediaQuery.of(context).viewInsets.bottom, left: 0, right: 0, child: child);
break;
case ToastGravity.BOTTOM:
default:
return Positioned(bottom: 50.0, left: 24.0, right: 24.0, child: newChild);
return Positioned(bottom: 50.0, left: 24.0, right: 24.0, child: child);
}
}
}
......@@ -185,19 +192,20 @@ class _ToastStateFul extends StatefulWidget {
}
class ToastStateFulState extends State<_ToastStateFul> with SingleTickerProviderStateMixin {
bool _visible = false;
showIt() {
_animationController.forward();
}
hideIt() {
_animationController.reverse();
_timer?.cancel();
}
AnimationController _animationController;
Animation _fadeAnimation;
Timer _timer;
@override
void initState() {
_animationController = AnimationController(
......@@ -208,20 +216,21 @@ class ToastStateFulState extends State<_ToastStateFul> with SingleTickerProvider
super.initState();
showIt();
Future.delayed(widget.duration, () {
_timer = Timer(widget.duration, () {
hideIt();
});
}
@override
void deactivate() {
_timer?.cancel();
_animationController.stop();
super.deactivate();
}
@override
void dispose() {
_timer?.cancel();
_animationController?.dispose();
super.dispose();
}
......
import 'dart:async';
import 'dart:html' as html;
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
......@@ -17,8 +18,6 @@ class FluttertoastWebPlugin {
Future<dynamic> handleMethodCall(MethodCall call) async {
switch (call.method) {
case 'showToast':
print("showToast");
print(call.arguments);
showToast(call.arguments);
return true;
default:
......@@ -40,11 +39,13 @@ class FluttertoastWebPlugin {
String bgColor = args['webBgColor'] ?? "linear-gradient(to right, #00b09b, #96c93d)";
int textColor = args['textcolor'];
int time = args['time'] == null ? 3000 : (int.parse(args['time'].toString()) * 1000);
bool showClose = args['webShowClose'] ?? false;
addHtmlToast(msg: msg, gravity: gravity, position: position, bgcolor: bgColor, showClose: showClose, time: time);
addHtmlToast(msg: msg, gravity: gravity, position: position, bgcolor: bgColor, showClose: showClose, time: time, textColor: textColor);
}
Future<void> injectCssAndJSLibraries() async {
......@@ -73,8 +74,8 @@ class FluttertoastWebPlugin {
String position = "right",
String bgcolor = "linear-gradient(to right, #00b09b, #96c93d)",
int time = 3000,
bool showClose = false}) {
print(html.querySelector("#toast-content"));
bool showClose = false,
int textColor}) {
html.Element ele = html.querySelector("#toast-content");
String content = """
var toastElement = Toastify({
......@@ -94,5 +95,11 @@ class FluttertoastWebPlugin {
..id = "toast-content"
..innerHtml = content;
html.querySelector('head').children.add(scriptText);
if (textColor != null) {
html.Element toast = html.querySelector('.toastify');
String tcRadix = textColor.toRadixString(16);
final String tC = "${tcRadix.substring(2)}${tcRadix.substring(0, 2)}";
toast.style.setProperty('color', "#$tC");
}
}
}
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.2"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.12"
version: "1.15.0-nullsafety.2"
flutter:
dependency: "direct main"
description: flutter
......@@ -22,9 +29,9 @@ packages:
dependency: transitive
description:
name: meta
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
version: "1.3.0-nullsafety.2"
sky_engine:
dependency: transitive
description: flutter
......@@ -34,16 +41,16 @@ packages:
dependency: transitive
description:
name: typed_data
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.3.0-nullsafety.2"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
version: "2.1.0-nullsafety.2"
sdks:
dart: ">=2.7.0 <3.0.0"
dart: ">=2.10.0-0.0.dev <2.10.0"
flutter: ">=1.10.0"
name: fluttertoast
description: Toast Library for Flutter, Easily create toast messages in single line of code
version: 7.0.4
version: 7.1.0
homepage: https://github.com/PonnamKarthik/FlutterToast
issue_tracker: https://github.com/ponnamkarthik/FlutterToast/issues
......
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