-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
Bug: Stateful widget with didUpdateWidget
is not called
#643
Comments
Right! It doesn't work and should not, because the
None of them change when you change the url in the browser url bar (of course, if you use the fragment url strategy, with a hash-tag sign in urls). |
So the only way to ensure that my widget can "refresh" is that the |
@karvulf Well, I'm not the author of this package, so.. I just can recommend you not to use this example of how to cook Beamer. You can use other examples that suppose to be working: |
This example fitted very well for my usecase because it the widget holds the beamer location in separated delegates (see
Only the third example is going to that what is solving my issues but unfortunately it seems harder to get this work if the locations are nested. @darkstarx |
@karvulf ok, that's not a problem, but you should not rely on class _AppScreenState extends State<AppScreen>
{
final routerDelegates = [
BeamerDelegate(
initialPath: '/books',
locationBuilder: (routeInformation, _) {
if ('${routeInformation.uri}'.contains('books')) {
return BooksLocation(routeInformation);
}
return NotFound(path: '${routeInformation.uri}');
},
),
BeamerDelegate(
initialPath: '/articles',
locationBuilder: (routeInformation, _) {
if ('${routeInformation.uri}'.contains('articles')) {
return ArticlesLocation(routeInformation);
}
return NotFound(path: '${routeInformation.uri}');
},
),
];
@override
void dispose()
{
delegate?.removeListener(_onBeamerChanged);
super.dispose();
}
@override
void didChangeDependencies()
{
super.didChangeDependencies();
final newDelegate = Beamer.of(context);
if (delegate != newDelegate) {
delegate?.removeListener(_onBeamerChanged);
delegate = newDelegate;
delegate?.addListener(_onBeamerChanged);
_updateCurrentIndex();
}
}
@override
Widget build(final BuildContext context)
{
return Scaffold(
body: IndexedStack(
index: _currentIndex,
children: [
Beamer(
routerDelegate: routerDelegates[0],
),
Beamer(
routerDelegate: routerDelegates[1],
),
],
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
items: const [
BottomNavigationBarItem(label: 'Books', icon: Icon(Icons.book)),
BottomNavigationBarItem(label: 'Articles', icon: Icon(Icons.article)),
],
onTap: (index) {
if (index != _currentIndex) {
setState(() => _currentIndex = index);
routerDelegates[_currentIndex].update(rebuild: false);
}
},
),
);
}
void _updateCurrentIndex()
{
_currentIndex = '${delegate!.configuration.uri}'.contains('books') ? 0 : 1;
}
void _onBeamerChanged() => setState(_updateCurrentIndex);
BeamerDelegate? delegate;
late int _currentIndex;
} But decisions like |
Ah I see, the listener could solve my issue, thank you, I will close the issue and try it with your proposed solution @darkstarx |
@karvulf Oh, I wouldn't close the issue, since the bug is still in the package documentation. |
As you wish :D @darkstarx |
@slovnicki Could you change the docs, to update the outdated code? |
@slovnicki could this isse be closed ?👆 |
Describe the bug
I have the following issue.
I will use the example
bottom_navigation_mulitple_beamers
for that.My
routerDelegate
contains oneBeamPage
that hasAppScreen
as child.AppScreen
expects one parameter (the current path aslcoation
).The
AppScreen
contains a BottomNavigationBar. Now I navigate to the second tab and back (at this pointdidUpdateWidget
is also not called).When I use the browsers back button, the widget
MyAppScreen
isn't called even though the path has changed and should update the widget because the parameter changed. That results into the issue that the tabs are not changed.Beamer version: (e.g.
2.0.0-dev.0
,master
, ...)master
(2.0.0-dev.0
) with commit-idc3795ab39197cc3429c54c5ec3fa6a1202ddba88
.To Reproduce
Update the code of an example in
main.dart
with the following. This example code is almost the same as in the example app inbottom_navigation_multiple_beamers
:Expected behavior
I would expect that the navigation works correctly with the back button and the widget gets updated when the path changed.
Desktop (please complete the following information):
Smartphone (please complete the following information):
The text was updated successfully, but these errors were encountered: