Flutter 解决SwiperController: ScrollController not attached to any scroll views.

1. Error message

 The following assertion was thrown while dispatching
 notifications for SwiperController:
 ScrollController not attached to any scroll views.
 'package:flutter/src/widgets/scroll_controller.dart':
 Failed assertion: line 107 pos 12: '_positions.isNotEmpty'

2. Reason Analysis

Flutter Swiper is a carousel component, and the content has a pull-down refresh control. When the number of carousels changes when the pull-down is refreshed and the carousel is in the last view. There will be such an abnormal situation that causes the carousel to not slide or other errors such as red screens.

As shown below:

3. Solutions

It can be solved by adding a LocalKey to Swiper. I added a UniqueKey here, which belongs to a LocalKey.

Fourth, expand knowledge.

Understand the role of the key value in flutter rendering refresh

Guess you like

Origin blog.csdn.net/hzqit520/article/details/128799757