flutter_inner_drawer icon indicating copy to clipboard operation
flutter_inner_drawer copied to clipboard

Problems in showing the content of the drawer in CuportinoScaffold

Open andreacimino opened this issue 5 years ago • 6 comments

Hello, thank you for the wonderful package!. I struggled a lot to make work the package under Cupertino. After some debugging i found the problem:

In line 267 you have

final RenderBox box = _drawerKey.currentContext?.findRenderObject(); The problem is that the drawerKey context is not always the context of the widget. I managed to solve by changing the signature of the method to:

void _updateWidth(BuildContext context) {
}

And then calling:

 @override
  Widget build(BuildContext context) {
    //assert(debugCheckHasMaterialLocalizations(context));

    /// initialize the correct width
    if (_initWidth == 400 ||
        MediaQuery.of(context).orientation != _orientation) {
      _updateWidth(context); <---- /*here the change*/
      _orientation = MediaQuery.of(context).orientation;
    }

I am not sending a pull request, since I don't know if this change would break something, thanks.

andreacimino avatar Apr 28 '20 07:04 andreacimino

Hi @andreacimino, I'll try to do some tests and let you know. Thanks

Dn-a avatar Apr 28 '20 09:04 Dn-a

@andreacimino specifically, is this the change you made?

void _updateWidth(BuildContext context) {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      //final RenderBox box = _drawerKey.currentContext.findRenderObject();
      final RenderBox box = context.findRenderObject();
      if (box != null && box.size != null)
        setState(() {
          _initWidth = box.size.width;
        });
    });
  }

Dn-a avatar Apr 28 '20 16:04 Dn-a

Almost yes, you can check the version I am using right now. I needed to handle the initState call, passing with null. Please look at the attached file.

inner_drawer.dart.zip

andreacimino avatar Apr 28 '20 16:04 andreacimino

@andreacimino the fix you recommended works correctly. I released a new version 0.5.5+1, try it and let me know. thanks

Dn-a avatar Apr 28 '20 18:04 Dn-a

@andreacimino I have done other tests and unfortunately your solution produces side effects. The code is again as before with the addition of a small modification. Small precautions: every time you update a package, before compiling, uninstall the app from the Android emulator.

Dn-a avatar Apr 29 '20 00:04 Dn-a

Thank you for the hints! I will try the latest version and see if everything works fine.

andreacimino avatar Apr 29 '20 07:04 andreacimino