flutter_inner_drawer icon indicating copy to clipboard operation
flutter_inner_drawer copied to clipboard

add a getter for InnerDrawer status

Open Viper-Bit opened this issue 5 years ago • 3 comments

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

Viper-Bit avatar Jan 12 '20 19:01 Viper-Bit

@Viper-Bit this function is implemented

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

Dn-a avatar Jan 12 '20 20:01 Dn-a

@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);
}

Viper-Bit avatar Jan 12 '20 21:01 Viper-Bit

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

TheMeanCanEHdian avatar Jul 30 '21 13:07 TheMeanCanEHdian