Skip to content

Conversation

@Viper-Bit
Copy link

current status of InnerDrawer is missing, i think its good for implementing double press back button to back or exit

@Dn-a
Copy link
Owner

Dn-a commented Jan 12, 2020

@Viper-Bit this function is implemented

innerDrawerCallback: (a) => print(a), // return true (open) or false (close)

@Viper-Bit
Copy link
Author

@Dn-a thx for review, yea with callback i must save the state again in another variable and in some cases pass it to parent classes (my drawer is in another class and another file than WillPopScope widget).
this can help to detect the state after back button pressed in WillPopScope and make the drawer close

@override
Widget build(BuildContext context)
{
  return InnerDrawer(
    scaffold: Scaffold(
        body: WillPopScope(
          child: _myBody(),
          onWillPop: _onWillPop,
          .
          .
          .
        ),
    ),
    key: _innerDrawerKey,
    .
    .
    .
  );
}

DateTime _currentBackPressTime;
Future<bool> _onWillPop() {
  if (_innerDrawerKey.currentState.opened) {
    _innerDrawerKey.currentState.close();
    return Future.value(false);
  }

  DateTime now = DateTime.now();
  if (_currentBackPressTime == null ||
      now.difference(_currentBackPressTime) > Duration(seconds: 2)) {
    _currentBackPressTime = now;
    print('press again to exit');
    return Future.value(false);
  }
  return Future.value(true);
}

@TheMeanCanEHdian
Copy link

TheMeanCanEHdian commented Jul 30, 2021

I have a similar use case here is there a recommended way to do this if it's not the above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants