-
Notifications
You must be signed in to change notification settings - Fork 27.1k
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
The following assertion was thrown building NotificationListener<KeepAliveNotification>: Failed assertion: '_debugUltimatePreviousSiblingOf(after, equals: _firstChild)': is not true. #13581
Comments
For me error is comes when
This throws the error mentioned above. |
For me error is comes when |
I'm using a TabBarView and wanting to use a new instance of a Class for each view. I'm trying to pass variables to each instance to render a ListView.builder in the Class. It works for a short while but after calling setState I get the same error as above. The only way I have been able to reliably get my view to work is by duplicating the class and creating a new instance of each. Very frustrating and time consuming Flutter (Channel beta, v0.4.4, on Mac OS X 10.13.4 17E202, locale en-NZ) |
Duplicate of #11895. |
I get the similar problem when I use I had a home screen like this: class HomeScreen extends StatefulWidget {
@override
State<StatefulWidget> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
List<NavigationIconView> _navigationViews;
PageController _tabController;
int pageIndex = 0;
@override
void initState() {
super.initState();
_tabController = new PageController(initialPage: pageIndex);
_navigationViews = <NavigationIconView>[
NavigationIconView(
icon: const Icon(Icons.show_chart),
title: '路线',
page: HomeMainScreen(),
),
NavigationIconView(
icon: const Icon(Icons.group_work),
title: '约伴',
page: HomeTeamScreen(),
),
NavigationIconView(
icon: const Icon(Icons.book),
title: '发现',
page: TestScreen('发现'),
),
NavigationIconView(
icon: const Icon(Icons.settings),
title: '设置',
page: HomeMeScreen(),
),
];
}
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: PageView(
controller: _tabController,
physics: NeverScrollableScrollPhysics(),
onPageChanged: (int index) {
setState(() {
this.pageIndex = index;
});
},
children: _navigationViews
.map((navigationView) => navigationView.page)
.toList(),
),
bottomNavigationBar: BottomNavigationBar(
items: _navigationViews
.map((navigationView) => navigationView.item)
.toList(),
currentIndex: pageIndex,
type: BottomNavigationBarType.fixed,
onTap: (int index) => _tabController.jumpToPage(index),
),
);
}
} In this code, I used the following way to fix it. first, added this code into the file where it class _BottomNavigationBarContainer extends StatefulWidget {
final IndexedWidgetBuilder builder;
final _BottomNavigationBarController controller;
_BottomNavigationBarContainer(this.builder, this.controller);
@override
_BottomNavigationBarContainerState createState() => _BottomNavigationBarContainerState();
}
class _BottomNavigationBarContainerState extends State<_BottomNavigationBarContainer> {
@override
void initState() {
super.initState();
widget.controller.addListener(_onIndexChanged);
}
@override
void didUpdateWidget(_BottomNavigationBarContainer oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.controller != widget.controller) {
oldWidget.controller.removeListener(_onIndexChanged);
widget.controller.addListener(_onIndexChanged);
}
}
@override
void dispose() {
widget.controller.removeListener(_onIndexChanged);
super.dispose();
}
_onIndexChanged() => setState(() {});
@override
Widget build(BuildContext context) {
return widget.builder(context, widget.controller.index);
}
}
class _BottomNavigationBarController extends Listenable {
int _currentIndex = 0;
_BottomNavigationBarController({int initialIndex = 0}) : _currentIndex = initialIndex;
setIndex(int index) {
if (index == _currentIndex) return;
_currentIndex = index;
_notification();
}
get index {
return _currentIndex;
}
List<VoidCallback> listeners = [];
@override
void addListener(listener) {
listeners.add(listener);
}
@override
void removeListener(listener) {
listeners.remove(listener);
}
_notification() {
listeners.map((listener) {
listener();
});
}
} and then build bottomNavigationBar: _BottomNavigationBarContainer((BuildContext context, int index) {
return BottomNavigationBar(
items: _navigationViews.map((navigationView) => navigationView.item).toList(),
currentIndex: index,
type: BottomNavigationBarType.fixed,
onTap: (int index) {
_tabController.jumpToPage(index);
},
);
}, _bottomNavigationBarController), |
There are open issues with similar errors This one is closed since a while. If none of the open issues matches your problem it's probably better to create a new issue. |
你解决了吗 |
@pickupsb 解决了, 我忘了这个问题是怎么引起的了. 我的解决方式就是在 原先的 BottomNavigationBar 外面套了一层 我自己写的 _BottomNavigationBarController 看我上面的代码. _BottomNavigationBarContainer有一个_bottomNavigationBarController控制器, 在PageView的onPageChanged回调时调用 |
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 |
Steps to Reproduce
I'm not sure how to reproduce the issue with a smaller, simpler project but I'm trying to implement pagination in my application and I'm getting this error.
Project: Project which includes setup instructions for the SQLite DB
To hit the issue, all I have to do is scroll and when I hit the list item containing the ProgressBar, this happens. I think it may have something to do with the state being set once the query is complete and the list being reset but Flutter is expecting the row it was at but instead, it's brought back to the first row.
Logs
Flutter Doctor
The text was updated successfully, but these errors were encountered: