1. Explain
Recently, I encountered an error when writing the shuttle project:
The following assertion was thrown while handling a gesture:
ScrollController attached to multiple scroll views.
'package:flutter/src/widgets/scroll_controller.dart':
Failed assertion: line 109 pos 12: '_positions.length == 1'
Reasons for error reporting:
1 The drawing function added to the project needs to navigate to different pages through the menu items of the drawing
2. A bottom navigation bar is added to the home page to navigate to different pages through the pagecontroller
3. The project manages routing and status through geTx.
Description of the problem: navigate to the settings or other pages through the drawer, and then re-navigate to the home page through the drawer. Click the item item item of the BottomNavigationBar, and will appear the error messages:
Failed assertion: line 109 pos 12: ‘_positions.length == 1’
2. Solution:
1. Drawer navigation uses Get.offAndToNamed(‘12313’); to jump.
2. You need to reinitialize the pageController every time you jump to the homepage. Through the build method of GetView, the controller is reinitialized every time the homepage interface is redrawn.
Specific operation:
code for the navigation part of the drawer:
class AppRouteProvide {
Future onRouteTo(String routeName) {
switch (routeName) {
case Routes.Auth:
Get.toNamed(Routes.Auth);
break;
case Routes.Home:
Get.offAndToNamed(Routes.Home);
break;
case Routes.Help:
Get.offAndToNamed(Routes.Help);
break;
case Routes.Splash:
Get.toNamed(Routes.Splash);
break;
case Routes.Connect:
Get.offAndToNamed(Routes.Connect);
break;
case Routes.Setting:
Get.offAndToNamed(Routes.Setting);
break;
}
return Future.value();
}
}
Code of home page view:
class HomeScreen extends GetView<HomeController> {
@override
Widget build(BuildContext context) {
// print('HomeScreen build');
if (controller.pageController.hasClients) {
controller.onClose();
controller.onInit();
}
return AppbarWidgetScreen(
body: _buildBody(context),
bottomBar: _buildBottomNavigationBar(context),
);
}
Home page controller part code
class HomeController extends GetxController {
final ApiRepository apiRepository;
RxInt selectedIndex = 0.obs;
late PageController pageController;
RxList<Widget> widgetPage = <Widget>[
HomeMainScreen(),
HomeBuyScreen(),
HomeCertScreen(),
HomeSellScreen(),
HomeMineScreen(),
].obs;
HomeController({required this.apiRepository});
@override
void onReady() {
super.onReady();
}
@override
void onInit() {
print('HomeController onInit()');
pageController = PageController(
initialPage: selectedIndex.value,
keepPage: true,
);
super.onInit();
}
@override
void onClose() {
super.onClose();
}
Read More:
- [Solved] Failed assertion: line 3180 pos 12: ‘debugNeedsPaint‘: is not true
- flutter, Unable to buy item, Error response code: 7 & flutter_inapp_purchase
- How to Solve Project Upgrade to flutter2.5.0 Error
- [Solved] Flutter Error: No MediaQuery widget ancestor found.
- [Solved] Opencv Error: Error: Assertion failed (data) in cv::Mat::at, file … mat.inl.hpp, line 897(Accessed pixels of non-existent matrix)
- Klee Error: Assertion `userMainFn && “unable to get user main“‘ failed
- [Solved] Flutter package flutter build apk Error: permission-handle
- [Solved] Fragment not attached to an activity
- [Solved] Message from debugger: debug-server is x86_64 binary running in translation, attached failed.
- Flutter flutter doctor –android-licenses [How to Solve]
- [Solved] Flutter compile error: Failed to find Build Tools revision 29.0.2
- Solve Maven project running error Failed to clean project: Failed to delete
- [TensorRT] INTERNAL ERROR: Assertion failed: mem = nullpt
- [Solved] validateNewTexture:89: failed assertion `BytesPerRow of a buffer-backed texture with pixelFormat
- [Solved] Unity Error: Assertion failed on expression: ‘IsMatrixValid(matrix)‘…
- [Solved] Multiple Yum update error: Failed to set locale, defaulting to C
- Qt Error: Debug Assertion Failed [How to Solve]
- How to Solve Element Error: target is not existed: .page-component__scroll .el-scrollbar__wrap
- [Solved] OpenCv5 error: (-215:Assertion failed) !_descriptors.empty() in function ‘add‘
- Flutter Error: dump failed because resource AndroidManifest.xml not found [How to Solve]