Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
billyandco opened this issue Mar 5, 2021 · 9 comments
Assignees
Labels
question Further information is requested

Comments

@billyandco
Copy link

billyandco commented Mar 5, 2021

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)

@felangel felangel self-assigned this Mar 5, 2021
@felangel felangel added the bug Something isn't working label Mar 5, 2021
@chadrickman
Copy link

chadrickman commented Mar 17, 2021

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
Copy link

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
Copy link
Owner

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

@jasonmcgraw
Copy link

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
Copy link

It would be my pleasure! Here you go @felangel

https://github.com/chadrickman/navigator_pop_issue

@magicleon94
Copy link

I'm having the same issue!

@felangel
Copy link
Owner

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

@felangel felangel added the investigating Investigating a reported issue label Jun 29, 2021
@jonathankao97
Copy link

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.

@felangel felangel assigned jonathankao97 and unassigned felangel Jul 16, 2021
@felangel felangel added question Further information is requested and removed investigating Investigating a reported issue bug Something isn't working labels Jul 16, 2021
@outlawz-dev
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

7 participants