Skip to content

Controller error #154774

@chen-dong-sheng

Description

@chen-dong-sheng

Steps to reproduce

When I use ScrollController() as a controller in a ListView, Swiper using flutter_swiper_null_safety libraries in the same layout will be affected and ScrollController not will be displayed attached to any scroll views, when I use flutter_swiper_view everything works

Expected results

When I use ScrollController() as a controller in a ListView, Swiper using flutter_swiper_null_safety libraries in the same layout will be affected and ScrollController not will be displayed attached to any scroll views, when I use flutter_swiper_view everything works

Actual results

When I use ScrollController() as a controller in a ListView, Swiper using flutter_swiper_null_safety libraries in the same layout will be affected and ScrollController not will be displayed attached to any scroll views, when I use flutter_swiper_view everything works

Code sample

Column(
children: [
SizedBox(
// color: Colors.lightGreen,
height: KuanGao.setgao(650),
width: KuanGao.setkuan(1080),
// color: Colors.red,
child: Obx(
() => Swiper(
// 需要一个容器包裹,并设置容器高度,不然报错
pagination: const SwiperPagination(),
control: const SwiperControl(),
// 分页器
autoplay: true,
// 自动播放
loop: true,
// 循环播放
itemCount: controller.lunbo.length,
// 图片数量
itemBuilder: (BuildContext context, int index) {
print(controller.lunbo[index]);
return Image.network(
controller.lunbo[index],
fit: BoxFit.cover,
);
},
),
)),
Container(
height: KuanGao.setgao(1000),
child: ListView(
controller: ScrollController(),
children: const [
ListTile(
title: Text('首页'),
)
],
),
),
],
)

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

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 157 pos 12: '_positions.isNotEmpty'

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.yml

When the exception was thrown, this was the stack:
#2 ScrollController.position (package:flutter/src/widgets/scroll_controller.dart:157:12)
#3 PageController.animateToPage (package:flutter/src/widgets/page_view.dart:191:41)
#4 _TransformerPageViewState.onChangeNotifier (package:flutter_swiper_null_safety/src/transformer_page_view/transformer_page_view.dart:590:12)
#5 ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:433:24)
#6 IndexController.next (package:flutter_swiper_null_safety/src/transformer_page_view/index_controller.dart:30:5)
#7 _SwiperTimerMixin._onTimer (package:flutter_swiper_null_safety/src/swiper.dart:369:18)
#10 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
(elided 4 frames from class _AssertionError and class _Timer)
The SwiperController sending notification was: Instance of 'SwiperController'

Flutter Doctor output

Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
[√] Flutter (Channel stable, 3.16.9, on Microsoft Windows [版本 10.0.22631.4037], locale zh-CN)
• Flutter version 3.16.9 on channel stable at D:\flutter\flutter3.16
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 4145645 (8 months ago), 2024-01-25 10:06:23 -0800
• Engine revision f40e976bed
• Dart version 3.2.6
• DevTools version 2.28.5
• Pub download mirror https://pub.flutter-io.cn
• Flutter download mirror https://storage.flutter-io.cn

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
• Android SDK at D:\sdk
• Platform android-35, build-tools 35.0.0
• Java binary at: D:\Andorid\jbr\bin\java
• Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314)
• All Android licenses accepted.

[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop Windows apps
X Visual Studio not installed; this is necessary to develop Windows apps.
Download at https://visualstudio.microsoft.com/downloads/.
Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2024.1)
• Android Studio at D:\Andorid
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• android-studio-dir = D:\Andorid
• Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314)

[√] IntelliJ IDEA Ultimate Edition (version 2024.1)
• IntelliJ at D:\LDER\IntelliJ IDEA 2024.1.4
• Flutter plugin version 81.0.2
• Dart plugin version 241.18808

[√] Connected device (4 available)
• SM N9760 (mobile) • emulator-5554 • android-x64 • Android 9 (API 28)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [版本 10.0.22631.4037]
• Chrome (web) • chrome • web-javascript • Google Chrome 128.0.6613.120
• Edge (web) • edge • web-javascript • Microsoft Edge 128.0.2739.67

[√] Network resources
• All expected network resources are available.

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: invalidIssue is closed as not valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions