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

Problem with StatefulWidgets in Version 0.5.6, #43

Closed
JulianKeppelerCP opened this issue Jun 26, 2020 · 7 comments
Closed

Problem with StatefulWidgets in Version 0.5.6, #43

JulianKeppelerCP opened this issue Jun 26, 2020 · 7 comments
Labels
bug Something isn't working

Comments

@JulianKeppelerCP
Copy link

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 :)

@Dn-a Dn-a added the bug Something isn't working label Jun 27, 2020
@cyrilcolinet
Copy link

Hello team,

I have the same problem, any update about it ?

@kendall-lu
Copy link

Facing the same issue, any updates?

@cyrilcolinet
Copy link

Same issue (with good workaround) on #38

@abdullahmaswadeh
Copy link

Same Issue

@cyrilcolinet
Copy link

Same Issue

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

@Dn-a Dn-a closed this as completed in 97e1228 Aug 5, 2020
Dn-a added a commit that referenced this issue Aug 5, 2020
@Dn-a
Copy link
Owner

Dn-a commented Aug 5, 2020

@JulianKeppelerCP @cyrilcolinet @abdullahmaswadeh try version 0.5.7+2

@cyrilcolinet
Copy link

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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants