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

[Question:] Why does the header loses its collapse-state on setState #3

Closed
ehhc opened this issue Apr 2, 2019 · 4 comments
Closed

Comments

@ehhc
Copy link

ehhc commented Apr 2, 2019

Hi,
I have the following app in which the default example is wrapped in an expandable-panel. Initially the panel is collapsed but i can expand it by clicking the header.
Now everytime i press the increment button, the panel gets collapsed again. How can i prevent that?

import 'package:flutter/material.dart';
import 'package:expandable/expandable.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: ExpandablePanel(
            initialExpanded: false,
            header: Text("Header"),
            expanded: Text('You have pushed the button this many times: $_counter')
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

@StefanLobbenmeier
Copy link
Contributor

StefanLobbenmeier commented Apr 5, 2019

Hi :) I had the same issue, so I created a pull request for this issue. I hope @aryzhov will pull this, but if you are impatient you can reference my repository in your pubspec.yaml like this:

dependencies:
  flutter:
    sdk: flutter
  expandable:
    git: https://github.com/StefanLobbenmeier/flutter-expandable

@aryzhov
Copy link
Owner

aryzhov commented Apr 5, 2019

@StefanLobbenmeier Thank you for working on this. I'll review your changes today. I wasn't getting notifications on the issues somehow, so I missed this and other questions. I'll catch up.

@aryzhov
Copy link
Owner

aryzhov commented Apr 5, 2019

@ehhc I just published version 2.1.0 that contains a fix for this issue. Thanks @StefanLobbenmeier.

@aryzhov aryzhov closed this as completed Apr 5, 2019
@ehhc
Copy link
Author

ehhc commented Apr 8, 2019

@StefanLobbenmeier @aryzhov thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants