Repository navigation
ExpansionPanelCallback shows incorrect state while opening and closing ExpansionPanelList. #74114
Description
Hello, I might have found a bug/error in the framework. I describe how the actual results differ from the ones I expected.
(copied from where I posted this first https://stackoverflow.com/questions/65743515/flutter-expansionpanellist-radio-callback-returns-wrong-value)
The line I marked with the comment (in CAPS) doesn't do what it's expected to do.
console output when I toggle a certain ExpansionPanelRadio() (of language english for example):
- I open the
ExpansionPanelRadio(): flutter: english false (<-- should be true, right?) - I close the
ExpansionPanelRadio(): flutter: english true (<-- should be false, right?)
console output when language english is selected, and I click another one (for example mandarin):
- flutter: mandarin false (<--this one went from close to open, shouldn't it return
true??) - flutter: english false (<--this one went from open to close)
Why do they both say false, when obviously one opened and the other one closed? Both panels were in different states before, and also after the change.
With this information^^, HOW am I supposed to know WHICH ExpansionPanelRadio() just got tapped?
List<String> languages = Languages.languageToImagePath.keys.toList();
return SingleChildScrollView(
child: ExpansionPanelList.radio(
initialOpenPanelValue: targetLanguage, //see value in ExpansionPanelRadio
expansionCallback: (int panelIndex, bool isExpanded) {
print('${languages[panelIndex]} $isExpanded'); //<-- HEEEEEEERRREEEEE
},
children: languages.map<ExpansionPanel>((language) {
return ExpansionPanelRadio(
value: language,
headerBuilder: (context, bool isExpanded) { //and what's this bool for?
return Text(language);
},
body: Text('Choose writing system(s) todo...'),
);
}).toList(),
),
);
I think these might be errors/bugs in the framework, but I wanted to ask here on stackoverflow before reporting it.
Maybe I just don't understand how these Widgets are supposed to be used.
Any help is appreciated.
I first thought ExpansionPanelList.radio might be the perfect Widget for what I intend to do, but it looks like I just have to make my own custom Widget
Activity
iapicca commentedon Jan 16, 2021
@kuyaC
I've tried to reproduce the behavior myself code sample here and I agree with you
the docs for ExpansionPanelList state
which seems to make sense... except that it's inconsistent with other widgets
for example CheckBox's onChange
even the official code sample as this unusual approach
more than a
bug, I see this as afeature requestto make this widget's behavior consistent with the frameworkdarshankawar commentedon Jan 18, 2021
Opening and closing
ExpansionPanelListis showing wrong state, ie, expanding the panel list returnsfalsewhile closing it returnstrue:flutter doctor -v
[-]Possible bug/error in the framework? (ExpansionPanelList)[/-][+]ExpansionPanelCallback shows incorrect state while opening and closing ExpansionPanelList.[/+]lodgmar commentedon Jun 22, 2021
I've suffered this bug too.
Any news about fix?
lodgmar commentedon Jun 22, 2021
I've found the bug in
_ExpansionPanelListState._handlePressed(bool isExpanded, int index).It calls
expansionCallbackwith the state of the panel BEFORE it opens/closes.But then, this is what it does:
But, this is the state of the second panel AFTER closing. This is inconsistent with the opening/closing panel that fired the event. So, I receive two calls to
expansionCallback, both withexpanded = false, but one for the panel opening, and one for the panel closing, imposible to know what is each.Posible solution: change first line of this method, from:
to:
evanholt1 commentedon Jun 24, 2021
I am facing this issue as well.
I am trying to use ExpansionPanelList.radio and make use of it's expansionCallback,
but since clicking on a panel while another is open calls "expansionCallback" twice,
once with the panel that's going to open with the boolean 'false', and another time with the panel that's to close with also the boolean 'false' as it's to close - which is inconsistent -,
and thus it is impossible without managing external state for ExpansionCallback to know which is panel is to close and which is to open,
and kind of defeats the purpose of .radio, as by using external state for this issue, .radio doesn't do anything useful.
lodgmar commentedon Jun 25, 2021
The best behaviour would be to call
expansionCallbackfor the closing panel FIRST, and THEN for the opening panel. This is the correct way to implement a "radio": two panels cannot be opened at the same time, one panel has to close BEFORE another one can open; and the last event is that one panel has been opened, not closed.So, more changes to do in
_ExpansionPanelListState._handlePressed(bool isExpanded, int index).lodgmar commentedon Jun 25, 2021
This would do the trick:
86driver commentedon Jul 2, 2021
I've suffered this bug too.
andreadaoud commentedon Aug 13, 2022
Hello, any progress on this bug?
maheshj01 commentedon Jan 2, 2023
Reproducible on stable and the master channel incorrect expansion status (
isExpanded) is reported when closing and opening the ExpansionPanel.code sample
flutter doctor -v (mac)
2 remaining items
robpot95 commentedon Feb 17, 2023
2 years later and still having this issue
andreadaoud commentedon Feb 22, 2023
Hi, I think this is a very important issue, could you please fix it?
dleyba042 commentedon May 9, 2023
@darshankawar , @maheshmnj , could I be assigned this issue? I could have a PR up pretty quickly.
dleyba042 commentedon May 9, 2023
I made a PR if anyone can take a look. dleyba042#2
dleyba042 commentedon May 9, 2023
Here's what the behavior looks like:
ExpansionPanel isExpanded callback parameter (Ticket 74114) (#128082)
lodgmar commentedon Jun 10, 2023
Thanks!!!!
alierdogan7 commentedon Jun 22, 2023
Finally @dleyba042's fix was published in 3.12.0-7.0.pre. I changed my flutter version to it (despite being an unstable channel), and the problem has gone. Thanks.
github-actions commentedon Jul 6, 2023
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.ExpansionPanel isExpanded callback parameter (Ticket 74114) (#128082)