-
Notifications
You must be signed in to change notification settings - Fork 114
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
Q: onExpanded() callback? #44
Comments
I will add that in the next release. Thank you for reporting. |
@TomTom101 You can pass controller and add listener to controller. Then in |
What kind of controller? Can you give a quick example? Thanks! |
class MyItem extends StatefulWidget {
final ItemModel _item;
final bool expanded;
const MyItem(this._item, {this.expanded = false});
@override
_MyItemState createState() => _MyItemState();
}
class _MyItemState extends State<MyItem> {
ExpandableController _controller;
@override
void initState() {
super.initState();
_controller = new ExpandableController(initialExpanded: widget.expanded);
_controller.addListener(_onToggle);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
void didUpdateWidget(MyItem oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.expanded) {
_controller.expanded = true;
}
}
_onToggle(){
print("Is expanded: ${_controller.expanded}");
}
@override
Widget build(BuildContext context) =>
ExpandableTheme(
data: ExpandableThemeData(
headerAlignment: ExpandablePanelHeaderAlignment.center),
child: ExpandablePanel(
controller: _controller,
header: Text(widget._item.title, style: Themes.baseRegularGrey),
expanded: Text(widget._item.content)));
} |
ExpandableController not good idea for multi panel, |
Hey there, I have a question related to this. I am using the Provider package and I was trying to make it so that when an item is expanded it changes the parent's flex value for it's width. Below is essentially how I have it set up, but I keep getting the following error (Below the code): I am guessing that it is because it is trying to change the value/expand the parent but the expanding widget is animating to actually expand still (or something along these lines). Is there a way to know when it has completed the expanding, or to do what I am trying to do before the expanding begins? If there are any recommendations, I would greatly appreciate it. Thanks, This is part of the Provider notifier I am using for this. class ChangeLogDataProvider with ChangeNotifier {
bool _changeLogExpanded = false;
void setExpanded(bool expand) {
_changeLogExpanded = expand;
notifyListeners();
}
bool get isExpanded => _changeLogExpanded; This is part of the widget display for the expanding items where I am setting the expansion value based on the controller.expanded value. final changeLogData = Provider.of<ChangeLogDataProvider>(context);
builder: (context, collapsed, expanded) {
var controller = ExpandableController.of(context);
controller.expanded ? changeLogData.setExpanded(true) : changeLogData.setExpanded(false);
} This is part of the parent widget in which I am trying to set the flex value based on the value in the Provider notifier, which was set from the controller.expanded value above. final changeLogData = Provider.of<ChangeLogDataProvider>(context);
Flexible(
flex: (changeLogData.isExpanded) ? 3 : 1,
child: AnimatedSize(
curve: Curves.easeIn,
duration: new Duration(milliseconds: 300),
vsync: this,
child: ChangeLogList(),
)), The following assertion was thrown while dispatching notifications for ChangeLogDataProvider:
setState() or markNeedsBuild() called during build.
This _InheritedProviderScope<ChangeLogDataProvider> widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.
The widget on which setState() or markNeedsBuild() was called was: _InheritedProviderScope<ChangeLogDataProvider>
value: Instance of 'ChangeLogDataProvider'
listening to value
The widget which was currently being built when the offending call was made was: ExpandablePanel
dirty
dependencies: [_ExpandableControllerNotifier]
When the exception was thrown, this was the stack:
#0 Element.markNeedsBuild.<anonymous closure> (package:flutter/src/widgets/framework.dart:4171:11)
#1 Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:4186:6)
#2 _InheritedProviderScopeElement.markNeedsNotifyDependents (package:provider/src/inherited_provider.dart:426:5)
#3 ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:207:21)
#4 ChangeLogDataProvider.setWidth (package:searcher_installer_go/data/provider/changelog_provider.dart:20:5)
...
The ChangeLogDataProvider sending notification was: Instance of 'ChangeLogDataProvider'
════════════════════════════════════════════════════════════════════════════════════════════════════
|
Hi @aryzhov, can you provide an idea when this feature is coming up, |
it is November now but it is still not resolved :( |
Any news on this feature? |
I have create a PR about this because i need this functionality too. i can achieve this with listen to |
Hello Lucyfirst354,
I will review your PR and will get back to you. Thanks!
…On Sun, Mar 28, 2021 at 10:37 PM lucyfirst354 ***@***.***> wrote:
I have create a PR about this because i need this functionality too. i can
achieve this with listen to ExpandableController but when it comes to
List, i think that's a bad approach,.
#93 <#93>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#44 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEW6EW22VW5QS7XH5TJNK3TGAGY3ANCNFSM4KN46NHA>
.
|
I just wanted to let you know that without this callback this awesome library is useless. I spent a few hours to implement it in my code and now I have to migrate to flutter's Expansion list because this library is missing the callback. This callback is so essential and obvious that I thought you had implemented it when I red your Pub.dev page but then I realized I only wasted a few hours. |
As @TomTom101 suggested, this can be achieved with the controller
|
Is there some kind of callback to when an
ExpandablePanel
was expanded/toggled? AnonExpanded()
prop would be ideal for my use case.Thanks!
The text was updated successfully, but these errors were encountered: