flow_builder icon indicating copy to clipboard operation
flow_builder copied to clipboard

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

Open billyandco opened this issue 4 years ago • 9 comments

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)

billyandco avatar Mar 05 '21 10:03 billyandco

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 avatar Mar 17 '21 23:03 chadrickman

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)

chadrickman avatar Mar 18 '21 13:03 chadrickman

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

felangel avatar Mar 18 '21 13:03 felangel

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,
    ),
  ),
);

jasonmcgraw avatar Mar 18 '21 15:03 jasonmcgraw

It would be my pleasure! Here you go @felangel

https://github.com/chadrickman/navigator_pop_issue

chadrickman avatar Mar 18 '21 15:03 chadrickman

I'm having the same issue!

magicleon94 avatar Apr 14 '21 15:04 magicleon94

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

felangel avatar Jun 29 '21 14:06 felangel

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.

jonathankao97 avatar Jul 16 '21 17:07 jonathankao97

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.

outlawz-dev avatar Jan 25 '24 10:01 outlawz-dev