cmdrootaccess / another-flushbar

A flexible widget for user notification. Customize your text, button, duration, animations and much more. For Android devs, it is made to replace Snackbars and Toasts.
https://pub.dev/packages/another_flushbar
MIT License
145 stars 89 forks source link

Fix type 'Null' is not a subtype of type 'FutureOr<bool>' #55

Closed Eimji closed 2 years ago

Eimji commented 2 years ago

Hello,

I would like to submit a fix for the bug when disposing Flusbar

══╡ EXCEPTION CAUGHT BY FOUNDATION LIBRARY ╞════════════════════════════════════════════════════════
The following _TypeError was thrown while dispatching notifications for OverlayEntry:
type 'Null' is not a subtype of type 'FutureOr<bool>'

When the exception was thrown, this was the stack:
#1      FlushbarRoute.dispose (package:another_flushbar/flushbar_route.dart:430:26)
#2      _RouteEntry.dispose.<anonymous closure> (package:flutter/src/widgets/navigator.dart:3165:19)
#3      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:308:24)
#4      OverlayEntry._updateMounted (package:flutter/src/widgets/overlay.dart:130:5)
#5      _OverlayEntryWidgetState.dispose (package:flutter/src/widgets/overlay.dart:200:18)
#6      StatefulElement.unmount (package:flutter/src/widgets/framework.dart:4895:11)
#7      _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1883:13)
#8      ListIterable.forEach (dart:_internal/iterable.dart:39:13)
#9      _InactiveElements._unmountAll (package:flutter/src/widgets/framework.dart:1892:25)
#10     BuildOwner.finalizeTree.<anonymous closure> (package:flutter/src/widgets/framework.dart:2879:27)
#11     BuildOwner.lockState (package:flutter/src/widgets/framework.dart:2510:15)
#12     BuildOwner.finalizeTree (package:flutter/src/widgets/framework.dart:2878:7)
#13     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:884:19)
#14     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1143:15)
#15     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1080:9)
(elided 4 frames from dart:async)

The OverlayEntry sending notification was:
  OverlayEntry#ed597(opaque: false; maintainState: false)
════════════════════════════════════════════════════════════════════════════════════════════════════

Thanks for keeping Flushbar alive.

cmdrootaccess commented 2 years ago

will make a test then merge. thank you

Eimji commented 2 years ago

Sorry, but you can forget my pull request. It introduced a regression bug when we want to dismiss a notification before displaying another one, e.g.

      if (_flush != null && !_flush!.isDismissed()) {
        await _flush!.dismiss();
      }

      _flush = Flushbar(
        backgroundColor: Application.infoModalColor,
        message: AppLocalizations.of(context)!.fileImported(success),
        icon: const Icon(
          MdiIcons.fileMoveOutline,
          size: 28.0,
          color: Color(0xff48dbfb),
        ),
        duration: const Duration(seconds: 5),
        margin: const EdgeInsets.all(8.0),
        borderRadius: BorderRadius.circular(8),
        onTap: (Flushbar f) {
          f.dismiss(false);
        },
      )..show(context);

Anyway, I can reproduce the bug I found, it seems to be fixed by the last update of the package.