JackJonson / flutter_styled_toast

A Styled Toast Flutter package.
Apache License 2.0
76 stars 41 forks source link

Exception with newest Flutter version breaks TextFields context menu #7

Closed krille-chan closed 4 years ago

krille-chan commented 4 years ago

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

JackJonson commented 4 years ago

A new version 1.3.1 has been released, upgrade flutter_styled_toast to 1.3.1 should fix this problem.

ghost commented 4 years ago

Seems to be fixed, haven't experienced this issue since!

cyrilcolinet commented 4 years ago

Seems to be fixed, haven't experienced this issue since!

No issues since this update! Thanks @JackJonson