jackjonson / flutter_styled_toast Goto Github PK
View Code? Open in Web Editor NEWA Styled Toast Flutter package.
License: Apache License 2.0
A Styled Toast Flutter package.
License: Apache License 2.0
I already set isIgnoring
to false and put a button inside the widget I create in showToastWidget
, the button is work until I set endOffset
with Offset(0, 1)
, seems the button is ignoring the pointer. any suggestion?
/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_styled_toast-2.0.0/lib/src/styled_toast.dart:1559:20: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
Is there any way to dismiss the toast with a swipe gesture, or at least by tapping on it?
Thanks.
Hello at you , when i try to use flutter_styled_toast in flutter 2.0 i got
/C:/Flutter%20v2.0/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_styled_toast-1.3.0/lib/src/styled_toast.dart:1880:15: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'BuildContext'.
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/Flutter%20v2.0/flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'inheritFromWidgetOfExactType'.
context.inheritFromWidgetOfExactType(_StyledToastTheme);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
please add this package for support null safety
Thanks for your plugin!
In a new plugin version, 1.5.2+1 has an issue, toast was not dismissed after the show
On 1.5.1+1 all work fine!
pubspec.yaml
dependencies:
flutter:
sdk: flutter
flutter_styled_toast: 1.5.2+1
Material app:
@override
Widget build(BuildContext context) {
return StyledToast(
child: MaterialApp(
title: _title,
home: MyWidget(),
),
locale: const Locale('en', 'US'),
textStyle: const TextStyle(
fontSize: 16.0,
color: Colors.white,
fontWeight: FontWeight.w800,
),
);
}
Widget code:
GestureDetector(
onTap: () {
showToast('Toast version flutter_styled_toast: 1.5.2+1');
},
child: Container(
width: 100,
color: Colors.blue,
),
),
How to hide the shown toast programmatically
======== Exception caught by gesture ===============================================================
The following assertion was thrown while handling a gesture:
'package:flutter_styled_toast/src/styled_toast.dart': Failed assertion: line 73 pos 10: 'context != null': is not true.
Hi, I am unable to reproduce this issue locally myself on any devices or simulators, Android or iOS, but in Crashlytics I am repeatedly seeing this reported crash in production:
Null check operator used on a null value. Error thrown null.
at OverlayEntry.remove(overlay.dart:163)
at ToastFuture.dismiss(styled_toast_manage.dart:73)
at new ToastFuture.create.(styled_toast_manage.dart:50)
It seems that this call in your code to remove an OverlayEntry is called on a null entry, which causes the issue in the Flutter SDK:
styled_toast_manage.dart:73 _entry.remove();
It is being reported from both iOS and Android devices, on a range of operating system versions too. Flutter version is 3.3.10. Any pointers or workarounds would be appreciated, as I'm at a loss how to control this, and this is now my most common crash.
I'm having an issue that using styled toast globally, this widget changing selection handle (droplet-like shape cursor under selected text) color that does not match with app theme. Yet StyledToast does not have option to changing its theme.
return StyledToast(
locale: const Locale('en', 'US'),
toastAnimation: StyledToastAnimation.slideFromTopFade,
reverseAnimation: StyledToastAnimation.slideToTopFade,
animDuration: const Duration(milliseconds: 350),
duration: const Duration(milliseconds: 2500),
child: MaterialApp(
// ...
);
While changing textSelectionTheme
or cupertinoOverrideTheme
in ThemeData.textSelectionTheme
will not fix this issue.
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
textSelectionTheme: TextSelectionThemeData(
// ...
selectionHandleColor: Colors.red,
),
cupertinoOverrideTheme: CupertinoThemeData(
primaryColor: Colors.red,
),
),
// ...
Color of the selection handle match with app theme color. (Dark blue)
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_styled_toast-2.1.3/lib/src/styled_toast.dart:497:63: Error: Property 'window' cannot be accessed on 'WidgetsBinding?' because it is potentially null.
The dependencies need to be upgraded as per sdk requirements?
Because no versions of flutter_styled_toast match >2.1.3 <3.0.0 and flutter_styled_toast 2.1.3 depends on flutter_localizations from sdk, flutter_styled_toast ^2.1.3 requires flutter_ localizations from sdk.
And because every version of flutter_localizations from sdk depends on intl 0.18.0, flutter_styled_toast ^2.1.3 requires intl 0.18.0
flutter_styled_ toast ^2.1.3 is incompatible with health ^6.0.0.
Now you apply both animation builders (forward and reverse) to show a toast and only reverse animation builder to dismiss a toast. What if I want to make on independent transition to show a toast and another independent transition to hide a toast?
I wonder why did you decide to mix animationBuilder and reverseAnimationBuilder for showing? And why don't you mix them on dismiss? It is very unusual behavior. And it is very uncomfortable to live with such behavior.
Here is my example. I want to animate scale and borderRadius of ClipRRect on showing, and fade out on dismissing. I have to use ClipRRect outside the toast widget and inside of animationBuilder because I use BackdropFilter which requires some clipping in a parent widget.
toasts.showToast(text,
context: context,
animationBuilder: (context, controller, duration, child) {
final scale = Tween<double>(begin: 1.3, end: 1.0).animate(
CurvedAnimation(
parent: controller,
curve: Curves.easeInSine,
reverseCurve: Curves.easeOutSine
),
);
final sigma = Tween<double>(begin: 0.0, end: 8.0).animate(
CurvedAnimation(
parent: controller,
curve: Curves.easeInSine,
reverseCurve: Curves.easeOutSine
),
);
final opacity = Tween<double>(begin: 0.0, end: 1.0).animate(
CurvedAnimation(
parent: controller,
curve: Curves.easeInSine,
reverseCurve: Curves.easeOutSine
),
);
return ScaleTransition(
scale: scale,
child: ClipRRect(
borderRadius: borderRadius,
child: BlurTransition(
sigma: sigma,
child: FadeTransition(
opacity: opacity,
child: child,
),
)
)
);
},
reverseAnimBuilder: (context, controller, duration, child) {
final sigma = Tween<double>(begin: 8.0, end: 0.0).animate(
CurvedAnimation(
parent: controller,
curve: Curves.easeOutSine,
reverseCurve: Curves.easeInSine
),
);
final opacity = Tween<double>(begin: 1.0, end: 0.0).animate(
CurvedAnimation(
parent: controller,
curve: Curves.easeOutSine,
reverseCurve: Curves.easeInSine
),
);
return ClipRRect(
borderRadius: borderRadius,
child: BlurTransition(
sigma: sigma,
child: FadeTransition(
opacity: opacity,
child: child,
),
),
);
},
animDuration: animDuration,
duration: totalDuration,
);
So, while a toast is showing up, it contains inside of FadeTransition
-> BlurTransition
-> ClipRRect (scaled border radius)
-> ScaleTransition
-> FadeTransition
-> BlurTransition
-> ClipRRect (normal border radius crops the scaled!!!)
Well, why don't you simply apply the only forward animationBuilder on showing and the only reverseAnimationBuilder (if exists) on dismissing? It would be a rather better idea, you simply would have to add some flag, say _dismissing
, in the StyledToastWidgetState
and check this flag in the build
method while deciding in which animation builder to put the widget - in animationBuilder
or in reverseAnimationBuilder
and that's all. Why did you choose so strange approach with mixing animations?
Hi, thanks for the very helpful package!
Since updating from v1.4.x to v1.5.x I'm no longer able to force the child widgets to update.
This is the approach I'm using which could definitely be part of the problem:
https://hillel.dev/2018/08/15/flutter-how-to-rebuild-the-entire-app-to-change-the-theme-or-locale/
Any thoughts?
can't add event click to toast
It will be nice to be able to slide a toast from the edge of the screen, and keep it connected to that edge with no gap.
In my design a toast takes full width of a screen, and it looks better with no gap, especially on devices with rounded corners, e.g. iPhone 11.
Hi, I'm using this package, and it is working fine. The only issue I'm facing on both Android
and iOS
is that when its position
is on the bottom
and the keyboard is active, toast hides behind the keyboard but showing on the top
position
. For now, I'm using it on the top position but it doesn't look so good in my scenario.
Kindly provide any solution to show it at the bottom of the screen without hiding it behind the keyboard. Thanks
No proper example of how to use, seems to be tied to one class MyHomePage ? Looks great but I cannot figure out how to use it.
When I scope flutter_styled_toast in flutter >=3.10.1, viewInsects in MediaQuery don't work.
Especially when a TextField on the bottom of my screen and I click the TextField, view wouldn't resize in time
We've been using this library in multiple ways without knowing (I wasn't a part in setup of the project), here's what I mean:
StyledToast
widget (StyledToast(child: MaterialApp(..))
)showToast
using context
parameter (showToast
and showToastWidget
)We had an issue where the provided context
could be disposed while the toast was showing (and/or was trying to dismiss), causing the following error:
Null check operator used on a null value
#0 OverlayEntry.remove (package:flutter/src/widgets/overlay.dart:170)
#1 ToastFuture.dismiss (package:flutter_styled_toast/src/styled_toast_manage.dart:74)
#2 new ToastFuture.create.<anonymous closure> (package:flutter_styled_toast/src/styled_toast_manage.dart:51)
#3 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18)
#4 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398)
#5 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429)
#6 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184)
/// in a widget under the same widget tree
/// `context` is from the widget
showToast(..., context: context, ...);
// or
showToastWidget(Text(...), context: context, ..);
At least that's the reason we think it's happening, since it stops happening when we set context
parameter to null
or don't use context
parameter at all.
Why be able to do both?
One way this could be avoided would be to have showToast
that doesn't have context parameter, and another called showToastOn
with a context parameter.
Let me know if I can help.
Hi there!
It would be very useful if I could access the StyledToastTheme
outside of the lib. And it would be nice to have a public function for that, which would receive optional BuildContext (like showToast
function which uses currentContext
if an optional context
is null).
Thank you!
════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building _OverlayEntryWidget-[LabeledGlobalKey<_OverlayEntryWidgetState>#39063](dirty, state: _OverlayEntryWidgetState#5b291):
No MediaQuery widget found.
_OverlayEntryWidget widgets require a MediaQuery widget ancestor.
The specific widget that could not find a MediaQuery ancestor was: _OverlayEntryWidget-[LabeledGlobalKey<_OverlayEntryWidgetState>#39063]
dirty
state: _OverlayEntryWidgetState#5b291
The ownership chain for the affected widget is: "_OverlayEntryWidget-[LabeledGlobalKey<_OverlayEntryWidgetState>#39063] ← _Theatre ← Overlay ← Stack ← Directionality ← _StyledToastTheme ← StyledToast ← CookingPlannerApp ← [root]"
Typically, the MediaQuery widget is introduced by the MaterialApp or WidgetsApp widget at the top of your application widget tree.
The relevant error-causing widget was
StyledToast
lib/main.dart:30
When the exception was thrown, this was the stack
#0 debugCheckHasMediaQuery.<anonymous closure>
package:flutter/…/widgets/debug.dart:215
#1 debugCheckHasMediaQuery
package:flutter/…/widgets/debug.dart:227
#2 _MaterialTextSelectionControls.buildToolbar
package:flutter/…/material/text_selection.dart:645
#3 TextSelectionOverlay._buildToolbar
package:flutter/…/widgets/text_selection.dart:556
#4 _OverlayEntryWidgetState.build
package:flutter/…/widgets/overlay.dart:177
...
════════════════════════════════════════════════════════════════════════════════
Reloaded 1 of 764 libraries in 865ms.
Reloaded 1 of 764 libraries in 914ms.
W/IInputConnectionWrapper( 8055): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 8055): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 8055): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 8055): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 8055): endBatchEdit on inactive InputConnection
[✓] Flutter (Channel stable, v1.17.0, on Linux, locale de_DE.UTF-8)
• Flutter version 1.17.0 at /home/krille/Lokal/HADTF/flutter_linux_v1.2.1-stable/flutter
• Framework revision e6b34c2b5c (vor 11 Tagen), 2020-05-02 11:39:18 -0700
• Engine revision 540786dd51
• Dart version 2.8.1
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /home/krille/Android/Sdk
• Platform android-29, build-tools 29.0.2
• Java binary at: /snap/android-studio/88/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.
[✓] Android Studio (version 3.6)
• Android Studio at /snap/android-studio/88/android-studio
• Flutter plugin version 45.1.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[✓] Connected device (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)
• No issues found!
Place another MaterialApp around StyledToast:
Widget build(BuildContext context) {
return MaterialApp(
home: StyledToast(
toastPositions: StyledToastPosition.top,
child: MaterialApp(
// ...
But this doesn't look that great ... so it would be nice if we could get a fix for this :)
Showing All Messages
../../../flutter/.pub-cache/hosted/pub.dartlang.org/flutter_styled_toast-2.1.3/lib/src/styled_toast.dart:497:63: Error: Property 'window' cannot be accessed on 'WidgetsBinding?' because it is potentially null
flutter 2.10.5
dart 2.16.2
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.