Dn-a / flutter_inner_drawer

Inner Drawer is an easy way to create an internal side section (left/right) where you can insert a list-menu or other.
https://pub.dartlang.org/packages/flutter_inner_drawer
MIT License
514 stars 129 forks source link

Problem with StatefulWidgets in Version 0.5.6, #43

Closed JulianKeppelerCP closed 4 years ago

JulianKeppelerCP commented 4 years ago

Hello there! I noticed some unexpected behaviour after version 0.5.5 when using a StatefulWidget inside the InnerDrawer. Specifically the state of the widget is lost after swiping to the left or right (initState will be called).

bug

Here is a small code example to reproduce this behaviour.

import 'package:flutter/material.dart';
import 'package:flutter_inner_drawer/inner_drawer.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: Wrapper(),
    );
  }
}

class Wrapper extends StatefulWidget {
  @override
  _WrapperState createState() => _WrapperState();
}

class _WrapperState extends State<Wrapper> {
  final GlobalKey<InnerDrawerState> _innerDrawerKey =
      GlobalKey<InnerDrawerState>();

  @override
  Widget build(BuildContext context) {
    return InnerDrawer(
      offset: IDOffset.only(left: 0.7, right: 0.7),
      key: _innerDrawerKey,

      leftChild: Scaffold(
        body: Container(
          color: Colors.red,
        ),
      ),
      scaffold: StatefulPage(
        key: ValueKey("statefulPage"),
      ),
    );
  }
}

class StatefulPage extends StatefulWidget {
  StatefulPage({Key key}) : super(key: key);

  @override
  _StatefulPageState createState() => _StatefulPageState();
}

class _StatefulPageState extends State<StatefulPage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Any help would be appreciated Thank you :)

cyrilcolinet commented 4 years ago

Hello team,

I have the same problem, any update about it ?

kendall-lu commented 4 years ago

Facing the same issue, any updates?

cyrilcolinet commented 4 years ago

Same issue (with good workaround) on #38

abdullahmaswadeh commented 4 years ago

Same Issue

cyrilcolinet commented 4 years ago

Same Issue

If you want some updates about this bug, subscribe to issue referenced before

Dn-a commented 4 years ago

@JulianKeppelerCP @cyrilcolinet @abdullahmaswadeh try version 0.5.7+2

cyrilcolinet commented 4 years ago

Hello, If you want to fix this issue by an other way, you can juste add tapScaffoldEnabled: true into your InnerDrawer() widget. The issue seem fixed 👍