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

Class 'Future<dynamic>' has no instance method show #31

Closed MrPresidentWhite closed 3 years ago

MrPresidentWhite commented 3 years ago

Hello I have the following problem, in my code I call the flushbar as follows:

onPressed: () => activeNotification ? setLetterGridState(index) : Flushbar(

and if the condition with

setLetterGridState(index)

is active, then the following error is displayed:

Performing hot reload...
Syncing files to device sdk gphone x86 arm...
Reloaded 1 of 1019 libraries in 532ms.

======== Exception caught by gesture ===============================================================
The following NoSuchMethodError was thrown while handling a gesture:
Class 'Future<dynamic>' has no instance method 'show'.
Receiver: Instance of 'Future<dynamic>'
Tried calling: show(Instance of 'SliverMultiBoxAdaptorElement')

When the exception was thrown, this was the stack: 
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:63:5)
#1      SettingsPageState.build.<anonymous closure>.<anonymous closure> (package:logo_dash/screens/settings.dart:496:30)
#2      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:989:21)
#3      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:193:24)
#4      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:608:11)
...
Handler: "onTap"
Recognizer: TapGestureRecognizer#d8ca8
  debugOwner: GestureDetector
  state: ready
  won arena
  finalPosition: Offset(208.8, 592.4)
  finalLocalPosition: Offset(27.2, 19.2)
  button: 1
  sent tap down
====================================================================================================

Despite the error, everything works as it should. How can I solve this so that this error doesn't come back?

cmdrootaccess commented 3 years ago

this is seems to be happening with your onTap event. and it has nothing to do with flushbar. maybe if you can provide a few lines of code i can help

MrPresidentWhite commented 3 years ago

because of NDA reasons i cant provide no more code

GridView.builder(
                      physics: NeverScrollableScrollPhysics(),
                      scrollDirection: Axis.vertical,
                      shrinkWrap: true,
                      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                        crossAxisCount: 5,
                        crossAxisSpacing: 12,
                        mainAxisSpacing: 12,
                        childAspectRatio: (itemWidth / itemHeight),
                      ),
                      itemCount: letters.length,
                      itemBuilder: (context, index,) {
                        return TextButton(
                          onPressed: () => activeNotification ? setLetterGridState(index) : Flushbar(
                            message: 'settings.section_notifications.deactivated_notification_snackbar_warning',
                            messageText: Text(
                              'settings.section_notifications.deactivated_notification_snackbar_warning',
                              style: TextStyle(
                                color: Colors.white,
                              ),
                            ).tr(),
                            margin: EdgeInsets.all(8),
                            borderRadius: BorderRadius.circular(8),
                            duration: Duration(seconds: 3),
                          )..show(context),
                          style: ButtonStyle(
                            backgroundColor: activeNotification ? _isSelectedLetterButtonGrid[index] ? MaterialStateProperty.all(Color.fromRGBO(19, 255, 128, 1)) : MaterialStateProperty.all(Colors.white) : MaterialStateProperty.all(Color.fromRGBO(126, 126, 126, 0.2)),
                            shape: MaterialStateProperty.all<RoundedRectangleBorder>(
                              RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(8),
                                side: BorderSide(
                                  color: activeNotification ? _isSelectedLetterButtonGrid[index] ? Color.fromRGBO(19, 255, 128, 1) : Color.fromRGBO(151, 151, 151, 1) : Color.fromRGBO(126, 126, 126, 0.2),
                                ),
                              ),
                            ),
                          ),
                          child: Text(
                            letters[index],
                            style: TextStyle(
                              color: activeNotification ? _isSelectedLetterButtonGrid[index] ? Colors.white : Color.fromRGBO(72, 69, 86, 1) : Color.fromRGBO(126, 126, 126, 0.4),
                              fontSize: 16,
                              fontWeight: FontWeight.w500,
                              letterSpacing: -0.3,
                            ),
                          ),
                        );
                      },
                    ),
cmdrootaccess commented 3 years ago

can you add this:

_showFlush(){
    if(activeNotification){
      setLetterGridState(index);
    } else {
      Flushbar(
        message: 'settings.section_notifications.deactivated_notification_snackbar_warning',
        messageText: Text(
          'settings.section_notifications.deactivated_notification_snackbar_warning',
          style: TextStyle(
            color: Colors.white,
          ),
        ).tr(),
        margin: EdgeInsets.all(8),
        borderRadius: BorderRadius.circular(8),
        duration: Duration(seconds: 3),
      )..show(context);
    }
  }

then replace your onPressed: () => with onPressed: (){ _showFlush(); }

MrPresidentWhite commented 3 years ago

it looks like it is working now. At least I don't get this error anymore. many thanks for the help