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]
- Only safe (?.) or non-null asserted (!!.) (#300)
......
......@@ -34,7 +34,7 @@ This one has limited features and no control over UI
```yaml
# add this line to your dependencies
fluttertoast: ^8.0.6
fluttertoast: ^8.0.7
```
```dart
......
......@@ -85,26 +85,20 @@ internal class MethodCallHandlerImpl(var context: Context) : MethodCallHandler {
}
}
}
// if(Build.VERSION.SDK_INT < 30) {
when (mGravity) {
Gravity.CENTER -> {
mToast.setGravity(mGravity, 0, 0)
}
Gravity.TOP -> {
mToast.setGravity(mGravity, 0, 100)
}
else -> {
mToast.setGravity(mGravity, 0, 100)
if(Build.VERSION.SDK_INT < 30) {
when (mGravity) {
Gravity.CENTER -> {
mToast.setGravity(mGravity, 0, 0)
}
Gravity.TOP -> {
mToast.setGravity(mGravity, 0, 100)
}
else -> {
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) {
(context as Activity).runOnUiThread { mToast.show() }
} else {
......
#!/bin/sh
# 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_TARGET=/Users/karthikponnam/Desktop/my/plugins/FlutterToast/example/lib/main.dart"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TRACK_WIDGET_CREATION=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:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
......
import 'package:flutter/material.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() {
Fluttertoast.showToast(
msg: "This is Long Toast",
......@@ -56,6 +61,11 @@ class ToastNoContext extends StatelessWidget {
}
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
......
......@@ -78,7 +78,7 @@ packages:
path: ".."
relative: true
source: path
version: "8.0.4"
version: "8.0.7"
js:
dependency: transitive
description:
......
......@@ -177,22 +177,32 @@ class FToast {
/// calls _showOverlay to display toast
///
/// Paramenter [child] is requried
///
/// fadeDuration default is 350 milliseconds
void showToast({
required Widget child,
PositionedToastBuilder? positionedToastBuilder,
Duration? toastDuration,
ToastGravity? gravity,
int fadeDuration = 350,
}) {
Widget newChild = _ToastStateFul(
child,
toastDuration ?? Duration(seconds: 2),
);
child, 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) {
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();
......@@ -246,10 +256,12 @@ class _ToastEntry {
/// internal [StatefulWidget] which handles the show and hide
/// animations for [FToast]
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 Duration duration;
final int fadeDuration;
@override
ToastStateFulState createState() => ToastStateFulState();
......@@ -279,7 +291,7 @@ class ToastStateFulState extends State<_ToastStateFul>
void initState() {
_animationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 350),
duration: Duration(milliseconds: widget.fadeDuration),
);
_fadeAnimation =
CurvedAnimation(parent: _animationController!, curve: Curves.easeIn);
......
name: fluttertoast
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
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