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] ## [7.0.4]
- iOS Build Failed Fixed #218 - iOS Build Failed Fixed #218
......
...@@ -34,7 +34,7 @@ This one has limited features and no control over UI ...@@ -34,7 +34,7 @@ This one has limited features and no control over UI
```yaml ```yaml
# add this line to your dependencies # add this line to your dependencies
fluttertoast: ^7.0.4 fluttertoast: ^7.1.0
``` ```
```dart ```dart
...@@ -112,7 +112,8 @@ FToast fToast; ...@@ -112,7 +112,8 @@ FToast fToast;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
fToast = FToast(context); fToast = FToast();
fToast.init(context);
} }
_showToast() { _showToast() {
...@@ -140,6 +141,18 @@ _showToast() { ...@@ -140,6 +141,18 @@ _showToast() {
gravity: ToastGravity.BOTTOM, gravity: ToastGravity.BOTTOM,
toastDuration: Duration(seconds: 2), 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(); ...@@ -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 ## Buy Me a Coffee
......
<component name="ProjectCodeStyleConfiguration"> <component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173"> <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"> <codeStyleSettings language="XML">
<indentOptions> <indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" /> <option name="CONTINUATION_INDENT_SIZE" value="4" />
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <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/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> </modules>
</component> </component>
</project> </project>
\ No newline at end of file
package io.github.ponnamkarthik.toast.fluttertoast package io.github.ponnamkarthik.toast.fluttertoast
import android.content.Context import android.content.Context
import androidx.annotation.NonNull
import io.flutter.embedding.engine.plugins.FlutterPlugin import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.BinaryMessenger import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel
......
...@@ -48,7 +48,7 @@ internal class MethodCallHandlerImpl(var context: Context) : MethodCallHandler { ...@@ -48,7 +48,7 @@ internal class MethodCallHandlerImpl(var context: Context) : MethodCallHandler {
} else { } else {
context.resources.getDrawable(R.drawable.corner) context.resources.getDrawable(R.drawable.corner)
} }
if(bgcolor != null && gradientDrawable != null) { if(bgcolor != null) {
gradientDrawable.setColorFilter(bgcolor.toInt(), PorterDuff.Mode.SRC) gradientDrawable.setColorFilter(bgcolor.toInt(), PorterDuff.Mode.SRC)
} }
text.background = gradientDrawable text.background = gradientDrawable
...@@ -59,17 +59,21 @@ internal class MethodCallHandlerImpl(var context: Context) : MethodCallHandler { ...@@ -59,17 +59,21 @@ internal class MethodCallHandlerImpl(var context: Context) : MethodCallHandler {
text.setTextColor(textcolor.toInt()) text.setTextColor(textcolor.toInt())
} }
mToast = Toast(context) mToast = Toast(context)
mToast.setDuration(mDuration) mToast.duration = mDuration
mToast.setView(layout) mToast.view = layout
} else { } else {
mToast = Toast.makeText(context, mMessage, mDuration) mToast = Toast.makeText(context, mMessage, mDuration)
} }
if (mGravity == Gravity.CENTER) { when (mGravity) {
mToast.setGravity(mGravity, 0, 0) Gravity.CENTER -> {
} else if (mGravity == Gravity.TOP) { mToast.setGravity(mGravity, 0, 0)
mToast.setGravity(mGravity, 0, 100) }
} else { Gravity.TOP -> {
mToast.setGravity(mGravity, 0, 100) mToast.setGravity(mGravity, 0, 100)
}
else -> {
mToast.setGravity(mGravity, 0, 100)
}
} }
if (context is Activity) { if (context is Activity) {
(context as Activity).runOnUiThread { mToast.show() } (context as Activity).runOnUiThread { mToast.show() }
...@@ -79,9 +83,7 @@ internal class MethodCallHandlerImpl(var context: Context) : MethodCallHandler { ...@@ -79,9 +83,7 @@ internal class MethodCallHandlerImpl(var context: Context) : MethodCallHandler {
result.success(true) result.success(true)
} }
"cancel" -> { "cancel" -> {
if (mToast != null) { mToast.cancel()
mToast.cancel()
}
result.success(true) result.success(true)
} }
else -> result.notImplemented() else -> result.notImplemented()
......
package com.example.example
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
#!/bin/sh #!/bin/sh
# This is a generated file; do not edit or check into version control. # This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/yongshuai.kang/flutter" export "FLUTTER_ROOT=C:\Users\ponna\Desktop\sdk\flutter"
export "FLUTTER_APPLICATION_PATH=/Users/yongshuai.kang/Desktop/FlutterToast/example" export "FLUTTER_APPLICATION_PATH=C:\Users\ponna\Desktop\my\plugins\fluttertoast\example"
export "FLUTTER_TARGET=/Users/yongshuai.kang/Desktop/FlutterToast/example/lib/main.dart" export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build" export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios" export "SYMROOT=${SOURCE_ROOT}/../build\ios"
export "OTHER_LDFLAGS=$(inherited) -framework Flutter" 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_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1" export "FLUTTER_BUILD_NUMBER=1"
export "TRACK_WIDGET_CREATION=true" export "DART_OBFUSCATION=false"
export "DART_DEFINES=flutter.inspector.structuredErrors=true" 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> { ...@@ -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() { _showToastCancel() {
Widget toastWithButton = Container( Widget toastWithButton = Container(
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0), padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
...@@ -112,7 +126,8 @@ class _ToastContextState extends State<ToastContext> { ...@@ -112,7 +126,8 @@ class _ToastContextState extends State<ToastContext> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
fToast = FToast(context); fToast = FToast();
fToast.init(context);
} }
@override @override
...@@ -132,6 +147,12 @@ class _ToastContextState extends State<ToastContext> { ...@@ -132,6 +147,12 @@ class _ToastContextState extends State<ToastContext> {
_showToast(); _showToast();
}, },
), ),
RaisedButton(
child: Text("Show Custom Toast via PositionedToastBuilder"),
onPressed: () {
_showBuilderToast();
},
),
SizedBox( SizedBox(
height: 24.0, height: 24.0,
), ),
......
...@@ -14,6 +14,7 @@ class ToastNoContext extends StatelessWidget { ...@@ -14,6 +14,7 @@ class ToastNoContext extends StatelessWidget {
msg: "This is Colored Toast with android duration of 5 Sec", msg: "This is Colored Toast with android duration of 5 Sec",
toastLength: Toast.LENGTH_SHORT, toastLength: Toast.LENGTH_SHORT,
webBgColor: "#e74c3c", webBgColor: "#e74c3c",
textColor: Colors.black,
timeInSecForIosWeb: 5, timeInSecForIosWeb: 5,
); );
} }
......
# Generated by pub # Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile # See https://dart.dev/tools/pub/glossary#lockfile
packages: 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: async:
dependency: transitive dependency: transitive
description: description:
name: async name: async
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.4.1" version: "2.5.0-nullsafety"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive
description: description:
name: boolean_selector name: boolean_selector
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.0" version: "2.1.0-nullsafety"
charcode: characters:
dependency: transitive dependency: transitive
description: description:
name: charcode name: characters
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.3" version: "1.1.0-nullsafety.2"
collection: charcode:
dependency: transitive dependency: transitive
description: description:
name: collection name: charcode
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.14.12" version: "1.2.0-nullsafety"
convert: clock:
dependency: transitive dependency: transitive
description: description:
name: convert name: clock
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.1" version: "1.1.0-nullsafety"
crypto: collection:
dependency: transitive dependency: transitive
description: description:
name: crypto name: collection
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.4" version: "1.15.0-nullsafety.2"
cupertino_icons: cupertino_icons:
dependency: "direct main" dependency: "direct main"
description: description:
name: cupertino_icons name: cupertino_icons
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.1.3" 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: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
...@@ -85,49 +78,28 @@ packages: ...@@ -85,49 +78,28 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "7.0.4" version: "7.1.0"
image:
dependency: transitive
description:
name: image
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.12"
matcher: matcher:
dependency: transitive dependency: transitive
description: description:
name: matcher name: matcher
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.12.6" version: "0.12.10-nullsafety"
meta: meta:
dependency: transitive dependency: transitive
description: description:
name: meta name: meta
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.8" version: "1.3.0-nullsafety.2"
path: path:
dependency: transitive dependency: transitive
description: description:
name: path name: path
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
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"
source: hosted source: hosted
version: "2.1.3" version: "1.8.0-nullsafety"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
...@@ -137,65 +109,58 @@ packages: ...@@ -137,65 +109,58 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: source_span name: source_span
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.7.0" version: "1.8.0-nullsafety"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
name: stack_trace name: stack_trace
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.9.3" version: "1.10.0-nullsafety"
stream_channel: stream_channel:
dependency: transitive dependency: transitive
description: description:
name: stream_channel name: stream_channel
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.0" version: "2.1.0-nullsafety"
string_scanner: string_scanner:
dependency: transitive dependency: transitive
description: description:
name: string_scanner name: string_scanner
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.5" version: "1.1.0-nullsafety"
term_glyph: term_glyph:
dependency: transitive dependency: transitive
description: description:
name: term_glyph name: term_glyph
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.0" version: "1.2.0-nullsafety"
test_api: test_api:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.2.15" version: "0.2.19-nullsafety"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
name: typed_data name: typed_data
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.6" version: "1.3.0-nullsafety.2"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:
name: vector_math name: vector_math
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "3.6.1" version: "2.1.0-nullsafety.2"
sdks: sdks:
dart: ">=2.7.0 <3.0.0" dart: ">=2.10.0-0.0.dev <2.10.0"
flutter: ">=1.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 { ...@@ -67,16 +67,21 @@ class Fluttertoast {
} }
} }
typedef PositionedToastBuilder = Widget Function(BuildContext context, Widget child);
class FToast { class FToast {
BuildContext context; BuildContext context;
static final FToast _instance = FToast._internal(); static final FToast _instance = FToast._internal();
factory FToast(BuildContext context) { factory FToast() {
_instance.context = context;
return _instance; return _instance;
} }
init(BuildContext context) {
_instance.context = context;
}
FToast._internal(); FToast._internal();
OverlayEntry _entry; OverlayEntry _entry;
...@@ -90,7 +95,7 @@ class FToast { ...@@ -90,7 +95,7 @@ class FToast {
} }
_ToastEntry _toastEntry = _overlayQueue.removeAt(0); _ToastEntry _toastEntry = _overlayQueue.removeAt(0);
_entry = _toastEntry.entry; _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); Overlay.of(context).insert(_entry);
_timer = Timer(_toastEntry.duration, () { _timer = Timer(_toastEntry.duration, () {
...@@ -117,52 +122,54 @@ class FToast { ...@@ -117,52 +122,54 @@ class FToast {
void showToast({ void showToast({
@required Widget child, @required Widget child,
PositionedToastBuilder positionedToastBuilder,
Duration toastDuration, Duration toastDuration,
ToastGravity gravity, ToastGravity gravity,
}) { }) {
Widget newChild = _ToastStateFul(
child,
toastDuration ?? Duration(seconds: 2),
);
OverlayEntry newEntry = OverlayEntry(builder: (context) { 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))); _overlayQueue.add(_ToastEntry(entry: newEntry, duration: toastDuration ?? Duration(seconds: 2)));
if (_timer == null) _showOverlay(); if (_timer == null) _showOverlay();
} }
_getPostionWidgetBasedOnGravity(Widget child, ToastGravity gravity, Duration duration) { _getPostionWidgetBasedOnGravity(Widget child, ToastGravity gravity) {
Widget newChild = _ToastStateFul(
child,
duration,
);
switch (gravity) { switch (gravity) {
case ToastGravity.TOP: 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; break;
case ToastGravity.TOP_LEFT: 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; break;
case ToastGravity.TOP_RIGHT: 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; break;
case ToastGravity.CENTER: 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; break;
case ToastGravity.CENTER_LEFT: 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; break;
case ToastGravity.CENTER_RIGHT: 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; break;
case ToastGravity.BOTTOM_LEFT: 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; break;
case ToastGravity.BOTTOM_RIGHT: 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; break;
case ToastGravity.SNACKBAR: 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; break;
case ToastGravity.BOTTOM: case ToastGravity.BOTTOM:
default: 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 { ...@@ -185,19 +192,20 @@ class _ToastStateFul extends StatefulWidget {
} }
class ToastStateFulState extends State<_ToastStateFul> with SingleTickerProviderStateMixin { class ToastStateFulState extends State<_ToastStateFul> with SingleTickerProviderStateMixin {
bool _visible = false;
showIt() { showIt() {
_animationController.forward(); _animationController.forward();
} }
hideIt() { hideIt() {
_animationController.reverse(); _animationController.reverse();
_timer?.cancel();
} }
AnimationController _animationController; AnimationController _animationController;
Animation _fadeAnimation; Animation _fadeAnimation;
Timer _timer;
@override @override
void initState() { void initState() {
_animationController = AnimationController( _animationController = AnimationController(
...@@ -208,20 +216,21 @@ class ToastStateFulState extends State<_ToastStateFul> with SingleTickerProvider ...@@ -208,20 +216,21 @@ class ToastStateFulState extends State<_ToastStateFul> with SingleTickerProvider
super.initState(); super.initState();
showIt(); showIt();
_timer = Timer(widget.duration, () {
Future.delayed(widget.duration, () {
hideIt(); hideIt();
}); });
} }
@override @override
void deactivate() { void deactivate() {
_timer?.cancel();
_animationController.stop(); _animationController.stop();
super.deactivate(); super.deactivate();
} }
@override @override
void dispose() { void dispose() {
_timer?.cancel();
_animationController?.dispose(); _animationController?.dispose();
super.dispose(); super.dispose();
} }
......
import 'dart:async'; import 'dart:async';
import 'dart:html' as html; import 'dart:html' as html;
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart';
...@@ -17,8 +18,6 @@ class FluttertoastWebPlugin { ...@@ -17,8 +18,6 @@ class FluttertoastWebPlugin {
Future<dynamic> handleMethodCall(MethodCall call) async { Future<dynamic> handleMethodCall(MethodCall call) async {
switch (call.method) { switch (call.method) {
case 'showToast': case 'showToast':
print("showToast");
print(call.arguments);
showToast(call.arguments); showToast(call.arguments);
return true; return true;
default: default:
...@@ -40,11 +39,13 @@ class FluttertoastWebPlugin { ...@@ -40,11 +39,13 @@ class FluttertoastWebPlugin {
String bgColor = args['webBgColor'] ?? "linear-gradient(to right, #00b09b, #96c93d)"; 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); int time = args['time'] == null ? 3000 : (int.parse(args['time'].toString()) * 1000);
bool showClose = args['webShowClose'] ?? false; 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 { Future<void> injectCssAndJSLibraries() async {
...@@ -73,8 +74,8 @@ class FluttertoastWebPlugin { ...@@ -73,8 +74,8 @@ class FluttertoastWebPlugin {
String position = "right", String position = "right",
String bgcolor = "linear-gradient(to right, #00b09b, #96c93d)", String bgcolor = "linear-gradient(to right, #00b09b, #96c93d)",
int time = 3000, int time = 3000,
bool showClose = false}) { bool showClose = false,
print(html.querySelector("#toast-content")); int textColor}) {
html.Element ele = html.querySelector("#toast-content"); html.Element ele = html.querySelector("#toast-content");
String content = """ String content = """
var toastElement = Toastify({ var toastElement = Toastify({
...@@ -94,5 +95,11 @@ class FluttertoastWebPlugin { ...@@ -94,5 +95,11 @@ class FluttertoastWebPlugin {
..id = "toast-content" ..id = "toast-content"
..innerHtml = content; ..innerHtml = content;
html.querySelector('head').children.add(scriptText); 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 # Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile # See https://dart.dev/tools/pub/glossary#lockfile
packages: packages:
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.2"
collection: collection:
dependency: transitive dependency: transitive
description: description:
name: collection name: collection
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.14.12" version: "1.15.0-nullsafety.2"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
...@@ -22,9 +29,9 @@ packages: ...@@ -22,9 +29,9 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: meta name: meta
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.8" version: "1.3.0-nullsafety.2"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
...@@ -34,16 +41,16 @@ packages: ...@@ -34,16 +41,16 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: typed_data name: typed_data
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.6" version: "1.3.0-nullsafety.2"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:
name: vector_math name: vector_math
url: "https://pub.flutter-io.cn" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.8" version: "2.1.0-nullsafety.2"
sdks: sdks:
dart: ">=2.7.0 <3.0.0" dart: ">=2.10.0-0.0.dev <2.10.0"
flutter: ">=1.10.0" flutter: ">=1.10.0"
name: fluttertoast name: fluttertoast
description: Toast Library for Flutter, Easily create toast messages in single line of code 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 homepage: https://github.com/PonnamKarthik/FlutterToast
issue_tracker: https://github.com/ponnamkarthik/FlutterToast/issues 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