felangel / flow_builder

Flutter Flows made easy! A Flutter package which simplifies navigation flows with a flexible, declarative API.
https://pub.dev/packages/flow_builder
MIT License
395 stars 65 forks source link

Android physic back button doesn't close showModalBottomSheet when is open #39

Open billyandco opened 3 years ago

billyandco commented 3 years ago

When i use showModalBottomSheet and pressed back button on Android, it pops the Flow pages instead of close ModalBottomSheet.

Navigator.pop(context ""bottomsheet context"") close the bottomsheet I tried to put a WillPopScope in the BottomSheet children and call Navigator.pop but it doesn't catch the event

Do you have any idea ?

My use case: MaterialApp > FlowBuilder > [FlowBuilder > BottomSheet] <== is poped (and not BottomSheet itself)

chadrickman commented 3 years ago

I believe we're having a similar issue with a webview. We open the webview and if we press the Android physical back button it does nothing.

The leading icon (in the appbar) does work until you press the physical button at which time that causes an exception to be thrown.

chadrickman commented 3 years ago

Here is the exception that is throws. I hope this helps.

E/flutter ( 3806): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 3815 pos 12: '!_debugLocked': is not true.
E/flutter ( 3806): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39)
E/flutter ( 3806): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)
E/flutter ( 3806): #2      NavigatorState.pop
package:flutter/…/widgets/navigator.dart:3815
E/flutter ( 3806): #3      NavigatorState.maybePop
package:flutter/…/widgets/navigator.dart:3781
E/flutter ( 3806): <asynchronous suspension>
E/flutter ( 3806): #4      Navigator.maybePop
package:flutter/…/widgets/navigator.dart:2018
E/flutter ( 3806): #5      BackButton.build.<anonymous closure>
package:flutter/…/material/back_button.dart:110
E/flutter ( 3806): #6      _InkResponseState._handleTap
package:flutter/…/material/ink_well.dart:993
E/flutter ( 3806): #7      _InkResponseState.build.<anonymous closure>
package:flutter/…/material/ink_well.dart:1111
E/flutter ( 3806): #8      GestureRecognizer.invokeCallback
package:flutter/…/gestures/recognizer.dart:183
E/flutter ( 3806): #9      TapGestureRecognizer.handleTapUp
package:flutter/…/gestures/tap.dart:598
E/flutter ( 3806): #10     BaseTapGestureRecognizer._checkUp
package:flutter/…/gestures/tap.dart:287
E/flutter ( 3806): #11     BaseTapGestureRecognizer.acceptGesture
package:flutter/…/gestures/tap.dart:259
E/flutter ( 3806): #12     GestureArenaManager.sweep
package:flutter/…/gestures/arena.dart:157
E/flutter ( 3806): #13     GestureBinding.handleEvent
package:flutter/…/gestures/binding.dart:362
E/flutter ( 3806): #14     GestureBinding.dispatchEvent
package:flutter/…/gestures/binding.dart:338
E/flutter ( 3806): #15     RendererBinding.dispatchEvent
package:flutter/…/rendering/binding.dart:267
E/flutter ( 3806): #16     GestureBinding._handlePointerEvent
package:flutter/…/gestures/binding.dart:295
E/flutter ( 3806): #17     GestureBinding._flushPointerEventQueue
package:flutter/…/gestures/binding.dart:240
E/flutter ( 3806): #18     GestureBinding._handlePointerDataPacket
package:flutter/…/gestures/binding.dart:213
E/flutter ( 3806): #19     _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter ( 3806): #20     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
felangel commented 3 years ago

Thanks @chadrickman 🙏 Are you able to provide a reproduction sample as well? I’ll be digging into this as soon as I can 👍

jasonmcgraw commented 3 years ago

For @chadrickman's problem, we found a temporary work around wrapping our Scaffold in a WillPopScope. It is also worth noting that the route was pushed using Navigator.of(context) from within a child of flow builder.

(This may be unrelated to the issue of OP)


return WillPopScope(
  onWillPop: () async {
    Navigator.pop(context);
    return true;
  },
  child: Scaffold(
    appBar: AppBar(
      title: Text('Title'),
    ),
    body: WebView(
      initialUrl: '',
      javascriptMode: JavascriptMode.unrestricted,
      debuggingEnabled: true,
    ),
  ),
);
chadrickman commented 3 years ago

It would be my pleasure! Here you go @felangel

https://github.com/chadrickman/navigator_pop_issue

magicleon94 commented 3 years ago

I'm having the same issue!

felangel commented 3 years ago

Sorry for the delay! I'll take a look at this asap 👍

jonathankao97 commented 3 years ago

The problem appears to stem from using Future.microtask() to handle navigation.

Future.microtask(() async {
  await Navigator.of(context).push(ExampleWebView.route());
});

Here's an easy fix (no progress indicator):

class _OnboardingUsageState extends State<OnboardingUsage> {
  @override
  Widget build(BuildContext context) {
    return ExampleWebView();
  }
}

If progress indicator is desired, something like this would work well.

outlawz-dev commented 8 months ago

When i use showModalBottomSheet and pressed back button on Android, it pops the Flow pages instead of close ModalBottomSheet.

Navigator.pop(context ""bottomsheet context"") close the bottomsheet I tried to put a WillPopScope in the BottomSheet children and call Navigator.pop but it doesn't catch the event

Do you have any idea ?

My use case: MaterialApp > FlowBuilder > [FlowBuilder > BottomSheet] <== is poped (and not BottomSheet itself)

Any update? i have the same problem without WebView.