FlutterToast icon indicating copy to clipboard operation
FlutterToast copied to clipboard

fix: Demo Unhandled Exception: Null check operator used on a null value Close #29

Open jixiaoyong opened this issue 3 years ago • 0 comments

[PROBLEM]

The official demo will throw the error Unhandled Exception: Null check operator used on a null value when showing toast.

see: Issue#29

[REASON]

  1. Toast.show need invoke ToastView.createView which need overlayState from its ancestor widget.
  2. The official demo initial the ToastContext in MyApp.build, which ancestor element is RenderObjectToWidgetElement -> StatelessElement ,so Overlay.of can't find overlayState.
  3. Meanwhile the MaterialApp already insert an overlayState for us

[SOLUTION]

Use the context of MyHomePage instead of MyApp.

[TEST]

Work with Flutter (Channel stable, 2.10.5, on Microsoft Windows [Version 10.0.19043.1766], locale en-US)

image

jixiaoyong avatar Jun 26 '22 08:06 jixiaoyong