flutter_swiper icon indicating copy to clipboard operation
flutter_swiper copied to clipboard

嵌套在CustomScrollView使用抛出异常

Open CrazyCoderShi opened this issue 6 years ago • 16 comments

RT: 我在CustomScrollView中的嵌套使用,在自动滚动的过程中会抛出如下异常:

flutter: Another exception was thrown: ScrollController not attached to any scroll views.

CrazyCoderShi avatar Jan 27 '19 03:01 CrazyCoderShi

image

CrazyCoderShi avatar Jan 27 '19 04:01 CrazyCoderShi

我在listview里面嵌套也是这个错

k3v1n-uncle avatar Mar 21 '19 12:03 k3v1n-uncle

不知道你的实际情况,说一下我的解决方案:如果是从网络请求的数据,请加上if...else...判断,在数据回来之前return一个Container @CrazyCoderShi @xuwankang

MeFelixWang avatar Mar 27 '19 06:03 MeFelixWang

Widget _widgetPlanList() { final controller = new SwiperController(); return Swiper( controller: controller, // index: _swiperIndex, itemBuilder: _swiperBuilder, itemCount: menuList.length, itemWidth: ScreenUtil().setHeight(750), itemHeight: ScreenUtil().setHeight(1040), scrollDirection: Axis.horizontal, onTap: (index) { print('onTap点击了第$index个'); }, onIndexChanged: (int i) { setState(() { _activeIndex = i; }); print('onIndexChanged点击了第$i个'); }); } 没有注释index:_swiperIndex前,我也是报一样的错误,注释掉就好了

跳转到指定索引:controller.move(index);

zhaowenxin avatar Apr 12 '19 07:04 zhaowenxin

@zhaowenxin 我压根没有使用这个属性...

CrazyCoderShi avatar Apr 12 '19 07:04 CrazyCoderShi

遇到了这个问题,求结局方案

MayIGetKepler avatar Apr 15 '19 08:04 MayIGetKepler

@MayIGetKepler 解决方案就是放弃这个repo,作者根本不关心issue

CrazyCoderShi avatar Apr 15 '19 08:04 CrazyCoderShi

@MayIGetKepler 解决方案就是放弃这个repo,作者根本不关心issue

有什么好的推荐吗

MayIGetKepler avatar Apr 15 '19 09:04 MayIGetKepler

同样问题在这里 Performing hot restart... Syncing files to device Redmi Note 7... Restarted application in 1,793ms. I/flutter (15332): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ I/flutter (15332): The following assertion was thrown building NotificationListener<ScrollNotification>: I/flutter (15332): ScrollController not attached to any scroll views. I/flutter (15332): 'package:flutter/src/widgets/scroll_controller.dart': Failed assertion: line 110 pos 12: I/flutter (15332): '_positions.isNotEmpty' I/flutter (15332): I/flutter (15332): Either the assertion indicates an error in the framework itself, or we should provide substantially I/flutter (15332): more information in this error message to help you determine and fix the underlying cause. I/flutter (15332): In either case, please report this assertion by filing a bug on GitHub: I/flutter (15332): https://github.com/flutter/flutter/issues/new?template=BUG.md I/flutter (15332): I/flutter (15332): When the exception was thrown, this was the stack: I/flutter (15332): #2 ScrollController.position (package:flutter/src/widgets/scroll_controller.dart:110:12) I/flutter (15332): #3 PageController.animateToPage (package:flutter/src/widgets/page_view.dart:120:41) I/flutter (15332): #4 _TransformerPageViewState.didUpdateWidget (package:transformer_page_view/transformer_page_view.dart:527:25) I/flutter (15332): #5 StatefulElement.update (package:flutter/src/widgets/framework.dart:3879:58) I/flutter (15332): #6 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:15) I/flutter (15332): #7 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3750:16) I/flutter (15332): #8 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5) I/flutter (15332): #9 StatelessElement.update (package:flutter/src/widgets/framework.dart:3796:5) I/flutter (15332): #10 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:15) I/flutter (15332): #11 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4601:32) I/flutter (15332): #12 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4992:17) I/flutter (15332): #13 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:15) I/flutter (15332): #14 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3750:16) I/flutter (15332): #15 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5) I/flutter (15332): #16 StatefulElement.update (package:flutter/src/widgets/framework.dart:3894:5) I/flutter (15332): #17 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:15) I/flutter (15332): #18 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4883:14) I/flutter (15332): #19 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:15) I/flutter (15332): #20 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4883:14) I/flutter (15332): #21 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:15) I/flutter (15332): #22 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3750:16) I/flutter (15332): #23 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5) I/flutter (15332): #24 StatelessElement.update (package:flutter/src/widgets/framework.dart:3796:5) I/flutter (15332): #25 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:15) I/flutter (15332): #26 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3750:16) I/flutter (15332): #27 Element.rebuild (package:flutter/src/widgets/framework.dart:3565:5) I/flutter (15332): #28 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2278:33) I/flutter (15332): #29 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:700:20) I/flutter (15332): #30 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:286:5) I/flutter (15332): #31 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1012:15) I/flutter (15332): #32 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:952:9) I/flutter (15332): #33 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:864:5) I/flutter (15332): #37 _invoke (dart:ui/hooks.dart:219:10) I/flutter (15332): #38 _drawFrame (dart:ui/hooks.dart:178:3) I/flutter (15332): (elided 5 frames from class _AssertionError and package dart:async) I/flutter (15332): ════════════════════════════════════════════════════════════════════════════════════════════════════ I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views. I/flutter (15332): Another exception was thrown: ScrollController not attached to any scroll views.

chenxianqi avatar May 13 '19 12:05 chenxianqi

@chenxianqi 同样的问题,请问解决了吗

yechaoa avatar May 28 '19 06:05 yechaoa

还没解决吗

apm29 avatar Jun 28 '19 07:06 apm29

I found the solution!! Your Swiper must be wrap with StreamBuilder or something that rebuild more than once Swiper. In my case, StreamBuilder( stream: slides, initialData: [], builder: (context, AsyncSnapshot snap) { List slideList = snap.data.toList(); return slideList.isNotEmpty ? Swiper( itemBuilder: (BuildContext context, int index) { return Image.network( slideList[index]['image'], fit: BoxFit.fill, ); }, Check the slideList not empty.

mario202k avatar Oct 09 '19 22:10 mario202k

If you want to use Swiper in other ScrollView ( like ListView ), consider boxing it using Container OR other Widget that could offer the certain size.

Container(
      constraints: BoxConstraints(maxHeight: 200, maxWidth: 200),
      child: Swiper()
)

The reason is described at Unbounded constraints.

ghost avatar Nov 13 '19 06:11 ghost

不知道你的实际情况,说一下我的解决方案:如果是从网络请求的数据,请加上if...else...判断,在数据回来之前return一个Container @CrazyCoderShi @xuwankang

多谢,你的回答解决了我的问题

leozhuo avatar Nov 23 '19 16:11 leozhuo

我是嵌套到ListView里面使用 Container( height: 154.0, child: Swiper() 我使用Container固定高度解决了这个问题

JamesGZM avatar Nov 25 '19 07:11 JamesGZM

If you want to use Swiper in other ScrollView ( like ListView ), consider boxing it using Container OR other Widget that could offer the certain size.

Container(
      constraints: BoxConstraints(maxHeight: 200, maxWidth: 200),
      child: Swiper()
)

The reason is described at Unbounded constraints.

I have this issue and i realized tha with a heighted Containter it works, but y have a Swipe whith variable heights, do you know to deal with that dinamic height?

Lucho1976 avatar Jun 04 '21 21:06 Lucho1976