Coder Social home page Coder Social logo

jackjonson / flutter_styled_toast Goto Github PK

View Code? Open in Web Editor NEW
73.0 3.0 40.0 18.87 MB

A Styled Toast Flutter package.

License: Apache License 2.0

Java 0.11% Objective-C 0.59% Dart 99.24% Batchfile 0.06%
flutter flutter-package toast styled animation beautiful-ui

flutter_styled_toast's People

Contributors

agordn52 avatar darkstarx avatar jackjonson avatar jeuler avatar solid-maxim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

flutter_styled_toast's Issues

Button inside widget in showToastWidget is unclickable

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?

Getting issue on flutter version 3.0.0

/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.

  • 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/G:/AAAInstallation/src/flutter/packages/flutter/lib/src/widgets/binding.dart').
    WidgetsBinding.instance!.removeObserver(this);

Dismiss with a gesture.

Is there any way to dismiss the toast with a swipe gesture, or at least by tapping on it?
Thanks.

inheritFromWidgetOfExactType

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);
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Toast was not dismissed after the show

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,
    ),
  ),

toast

Without giving context getting error. But context is optional param.

======== 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.

Repeated "Null check operator used on a null value. Error thrown null" error

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.

Selection Handle Color

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,
          ),
        ),
        // ...

Expected Output

Color of the selection handle match with app theme color. (Dark blue)

Actual Output

Color of the selection handle changed to purple.
image

Causing Error, Doesn't Run

/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.

  • 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/flutter/packages/flutter/lib/src/widgets/binding.dart').
    Try accessing using ?. instead.
    data: MediaQueryData.fromWindow(WidgetsBinding.instance.window),
    ^^^^^^
    /C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_styled_toast-2.1.3/lib/src/styled_toast.dart:681:29: Error: Method 'addObserver' cannot be called on 'WidgetsBinding?' because it is potentially null.
  • 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/flutter/packages/flutter/lib/src/widgets/binding.dart').
    Try calling using ?. instead.
    WidgetsBinding.instance.addObserver(this);
    ^^^^^^^^^^^
    /C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_styled_toast-2.1.3/lib/src/styled_toast.dart:1559:29: Error: Method 'removeObserver' cannot be called on 'WidgetsBinding?' because it is potentially null.
  • 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/flutter/packages/flutter/lib/src/widgets/binding.dart').
    Try calling using ?. instead.
    WidgetsBinding.instance.removeObserver(this);

Upgrade dependencies to intl 0.18.0

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.

It is impossible to write independent reverse animation builder.

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?

Toast hides when keyboard is active.

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

Very difficult to use

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.

Should the BuildContext parameter in showToast really exist?

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:

  • Wrapped the whole app in StyledToast widget (StyledToast(child: MaterialApp(..)))
  • Calling 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.

Could you make StyledToastTheme visible outside of library?

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 with newest Flutter version breaks TextFields context menu

How to reproduce:

  1. Add StyledToast at top of the Material Widget, but not inside of a Material Widget.
  2. Open context menu on a TextField to paste or copy something
  3. App crashes with:

════════ 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 Doctor:

[✓] 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!

Workaround:

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 :)

error when build in ios

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.