Commit 60439d3b by Karthik Ponnam

added new parameter for FToast, fixes #287 , #281, #303

parent c33e5321
## [8.0.7]
- Added fadeDuration in FToast to set fade animation Duration
- Fixed Toast behind the screen #287 , #281
- Fixed #303
## [8.0.6] ## [8.0.6]
- Only safe (?.) or non-null asserted (!!.) (#300) - Only safe (?.) or non-null asserted (!!.) (#300)
......
...@@ -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: ^8.0.6 fluttertoast: ^8.0.7
``` ```
```dart ```dart
......
...@@ -85,8 +85,7 @@ internal class MethodCallHandlerImpl(var context: Context) : MethodCallHandler { ...@@ -85,8 +85,7 @@ internal class MethodCallHandlerImpl(var context: Context) : MethodCallHandler {
} }
} }
} }
if(Build.VERSION.SDK_INT < 30) {
// if(Build.VERSION.SDK_INT < 30) {
when (mGravity) { when (mGravity) {
Gravity.CENTER -> { Gravity.CENTER -> {
mToast.setGravity(mGravity, 0, 0) mToast.setGravity(mGravity, 0, 0)
...@@ -98,12 +97,7 @@ internal class MethodCallHandlerImpl(var context: Context) : MethodCallHandler { ...@@ -98,12 +97,7 @@ internal class MethodCallHandlerImpl(var context: Context) : MethodCallHandler {
mToast.setGravity(mGravity, 0, 100) mToast.setGravity(mGravity, 0, 100)
} }
} }
// } }
// val inputMethodManager = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
// if(inputMethodManager.isAcceptingText) {
// mToast.setGravity(Gravity.CENTER, 0, 0)
// }
if (context is Activity) { if (context is Activity) {
(context as Activity).runOnUiThread { mToast.show() } (context as Activity).runOnUiThread { mToast.show() }
......
#!/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=/usr/local/Caskroom/flutter/1.22.3/flutter" export "FLUTTER_ROOT=/Users/karthikponnam/Desktop/SDK/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/karthikponnam/Desktop/my/plugins/FlutterToast/example" export "FLUTTER_APPLICATION_PATH=/Users/karthikponnam/Desktop/my/plugins/FlutterToast/example"
export "FLUTTER_TARGET=/Users/karthikponnam/Desktop/my/plugins/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 "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1" export "FLUTTER_BUILD_NUMBER=1"
export "DART_OBFUSCATION=false" export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true" export "TRACK_WIDGET_CREATION=false"
export "TREE_SHAKE_ICONS=false" export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=/Users/karthikponnam/Desktop/my/plugins/FlutterToast/example/.dart_tool/package_config.json" export "PACKAGE_CONFIG=.packages"
import 'dart:async';
import 'package:fluttertoast_example/main.dart'; import 'package:fluttertoast_example/main.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart'; import 'package:fluttertoast/fluttertoast.dart';
......
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart'; import 'package:fluttertoast/fluttertoast.dart';
class ToastNoContext extends StatelessWidget { class ToastNoContext extends StatefulWidget {
@override
_ToastNoContextState createState() => _ToastNoContextState();
}
class _ToastNoContextState extends State<ToastNoContext> {
void showLongToast() { void showLongToast() {
Fluttertoast.showToast( Fluttertoast.showToast(
msg: "This is Long Toast", msg: "This is Long Toast",
...@@ -56,6 +61,11 @@ class ToastNoContext extends StatelessWidget { ...@@ -56,6 +61,11 @@ class ToastNoContext extends StatelessWidget {
} }
@override @override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new MaterialApp( return new MaterialApp(
home: new Scaffold( home: new Scaffold(
......
...@@ -78,7 +78,7 @@ packages: ...@@ -78,7 +78,7 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "8.0.4" version: "8.0.7"
js: js:
dependency: transitive dependency: transitive
description: description:
......
...@@ -177,22 +177,32 @@ class FToast { ...@@ -177,22 +177,32 @@ class FToast {
/// calls _showOverlay to display toast /// calls _showOverlay to display toast
/// ///
/// Paramenter [child] is requried /// Paramenter [child] is requried
/// /// fadeDuration default is 350 milliseconds
void showToast({ void showToast({
required Widget child, required Widget child,
PositionedToastBuilder? positionedToastBuilder, PositionedToastBuilder? positionedToastBuilder,
Duration? toastDuration, Duration? toastDuration,
ToastGravity? gravity, ToastGravity? gravity,
int fadeDuration = 350,
}) { }) {
Widget newChild = _ToastStateFul( Widget newChild = _ToastStateFul(
child, child, toastDuration ?? Duration(seconds: 2),
toastDuration ?? Duration(seconds: 2), fadeDuration: fadeDuration);
);
/// Check for keyboard open
/// If open will ignore the gravity bottom and change it to center
if (gravity == ToastGravity.BOTTOM) {
if (MediaQuery.of(context!).viewInsets.bottom != 0) {
gravity = ToastGravity.CENTER;
}
}
OverlayEntry newEntry = OverlayEntry(builder: (context) { OverlayEntry newEntry = OverlayEntry(builder: (context) {
if (positionedToastBuilder != null) if (positionedToastBuilder != null)
return positionedToastBuilder(context, newChild); return positionedToastBuilder(context, newChild);
return _getPostionWidgetBasedOnGravity(newChild, gravity); return _getPostionWidgetBasedOnGravity(newChild, gravity);
}); });
_overlayQueue.add(_ToastEntry( _overlayQueue.add(_ToastEntry(
entry: newEntry, duration: toastDuration ?? Duration(seconds: 2))); entry: newEntry, duration: toastDuration ?? Duration(seconds: 2)));
if (_timer == null) _showOverlay(); if (_timer == null) _showOverlay();
...@@ -246,10 +256,12 @@ class _ToastEntry { ...@@ -246,10 +256,12 @@ class _ToastEntry {
/// internal [StatefulWidget] which handles the show and hide /// internal [StatefulWidget] which handles the show and hide
/// animations for [FToast] /// animations for [FToast]
class _ToastStateFul extends StatefulWidget { class _ToastStateFul extends StatefulWidget {
_ToastStateFul(this.child, this.duration, {Key? key}) : super(key: key); _ToastStateFul(this.child, this.duration, {Key? key, this.fadeDuration = 350})
: super(key: key);
final Widget child; final Widget child;
final Duration duration; final Duration duration;
final int fadeDuration;
@override @override
ToastStateFulState createState() => ToastStateFulState(); ToastStateFulState createState() => ToastStateFulState();
...@@ -279,7 +291,7 @@ class ToastStateFulState extends State<_ToastStateFul> ...@@ -279,7 +291,7 @@ class ToastStateFulState extends State<_ToastStateFul>
void initState() { void initState() {
_animationController = AnimationController( _animationController = AnimationController(
vsync: this, vsync: this,
duration: const Duration(milliseconds: 350), duration: Duration(milliseconds: widget.fadeDuration),
); );
_fadeAnimation = _fadeAnimation =
CurvedAnimation(parent: _animationController!, curve: Curves.easeIn); CurvedAnimation(parent: _animationController!, curve: Curves.easeIn);
......
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: 8.0.6 version: 8.0.7
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