Skip to content
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

Adding and Removing pages in Swiper #20

Open
fvisticot opened this issue Oct 18, 2018 · 9 comments
Open

Adding and Removing pages in Swiper #20

fvisticot opened this issue Oct 18, 2018 · 9 comments

Comments

@fvisticot
Copy link

I need to add / remove page in the Swiper with an Action Button (button on the bottom of the page).
-> Action add: Add a page at the end of the Swiper and move the Swiper to the index of the new created page => seems OK
-> Action remove: Remove current page and display Swiper without the deleted page
=> OK but NOT when the last page of the Swiper is deleted (see exception in the traces)

Implementation used:

  • StreamController to control the pages to be displayted in the Swiper
  • The Swiper included as builder of the Stream controller is created each time page is removed/added

Traces when last page is removed:

flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ flutter: The following assertion was thrown building Swiper(state: _SwiperState#25085): flutter: ScrollController not attached to any scroll views. flutter: 'package:flutter/src/widgets/scroll_controller.dart': Failed assertion: line 110 pos 12: flutter: '_positions.isNotEmpty' flutter: flutter: Either the assertion indicates an error in the framework itself, or we should provide substantially flutter: more information in this error message to help you determine and fix the underlying cause. flutter: In either case, please report this assertion by filing a bug on GitHub: flutter: https://github.com/flutter/flutter/issues/new flutter: flutter: When the exception was thrown, this was the stack: flutter: #2 ScrollController.position (package:flutter/src/widgets/scroll_controller.dart:110:12) flutter: #3 PageController.animateToPage (package:flutter/src/widgets/page_view.dart:118:41) flutter: #4 _TransformerPageViewState.didUpdateWidget (package:transformer_page_view/transformer_page_view.dart:508:25) flutter: #5 StatefulElement.update (package:flutter/src/widgets/framework.dart:3820:58) flutter: #6 Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15) flutter: #7 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4521:32) flutter: #8 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4911:17) flutter: #9 Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15) flutter: #10 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3689:16) flutter: #11 Element.rebuild (package:flutter/src/widgets/framework.dart:3531:5) flutter: #12 StatefulElement.update (package:flutter/src/widgets/framework.dart:3835:5) flutter: #13 Element.updateChild (package:flutter/src/widgets/framework.dart:2729:15) flutter: #14 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3689:16) flutter: #15 Element.rebuild (package:flutter/src/widgets/framework.dart:3531:5) flutter: #16 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2273:33) flutter: #17 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:673:20) flutter: #18 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:208:5) flutter: #19 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15) flutter: #20 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9) flutter: #21 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5) flutter: #22 _invoke (dart:ui/hooks.dart:139:13) flutter: #23 _drawFrame (dart:ui/hooks.dart:128:3)

@sbesnard
Copy link

Same problem here ! You can avoid it by saving a reference to the SwiperController and call its previous method just before deleting the widget (Future.delayed() may come handy...)

@sbesnard
Copy link

Actually, the problem occurs when deleting the first element as well, and I have no solution for that yet.

@Xingefb
Copy link

Xingefb commented Jul 29, 2019

嵌套在CustomScrollView使用抛出异常,进行swiper count 判断,如果数量为空则不显示,数量不为空在显示 if (null == _swipers || _swipers.isEmpty) ? SizedBox() : _swiper() ;

@deimantasa
Copy link

Hey, was this issue fixed? As I face exactly same thing. I receive an error
ScrollController not attached to any scroll views. 'package:flutter/src/widgets/scroll_controller.dart': Failed assertion: line 110 pos 12: '_positions.isNotEmpty'
After I remove an item from Swiper.

Cheers

@yousifAlneamy
Copy link

Hey, I was able to solve this by dispose/recreate the wrapper widget of the swiper() by giving a UniqueKey each time I was going to pass data to the swiper.

the state is maintained in the parent widget, sample code:

MySwiperWrapper(key: UniqueKey(), images: images, ......)

class MySwiperWrapper extends StatefulWidget { ....... MySwiperWrapper ({ @required Key key, @required this.images, }) : super(key: key); ..... }

NOTE: it's not an efficient solution, but it works

@zeromaro, hope this helps you

@ZeroMoment
Copy link

Hey, I was able to solve this by dispose/recreate the wrapper widget of the swiper() by giving a UniqueKey each time I was going to pass data to the swiper.

the state is maintained in the parent widget, sample code:

MySwiperWrapper(key: UniqueKey(), images: images, ......)

class MySwiperWrapper extends StatefulWidget { ....... MySwiperWrapper ({ @required Key key, @required this.images, }) : super(key: key); ..... }

NOTE: it's not an efficient solution, but it works

@zeromaro, hope this helps you

it's worked,but i don't know why

@him123
Copy link

him123 commented Jan 10, 2020

Hey, I was able to solve this by dispose/recreate the wrapper widget of the swiper() by giving a UniqueKey each time I was going to pass data to the swiper.

the state is maintained in the parent widget, sample code:

MySwiperWrapper(key: UniqueKey(), images: images, ......)

class MySwiperWrapper extends StatefulWidget { ....... MySwiperWrapper ({ @required Key key, @required this.images, }) : super(key: key); ..... }

NOTE: it's not an efficient solution, but it works

It works....thank you so much

@holtalanm
Copy link

Hey, I was able to solve this by dispose/recreate the wrapper widget of the swiper() by giving a UniqueKey each time I was going to pass data to the swiper.

the state is maintained in the parent widget, sample code:

MySwiperWrapper(key: UniqueKey(), images: images, ......)

class MySwiperWrapper extends StatefulWidget { ....... MySwiperWrapper ({ @required Key key, @required this.images, }) : super(key: key); ..... }

NOTE: it's not an efficient solution, but it works

@zeromaro, hope this helps you

this fixed my issue, as well. thanks!

@tamnhoskins
Copy link

I am using the SwipperController with the Swiper object and calling the move function, which was causing the "ScrollController not attached to any scroll views" exception. Adding a unique key to my Swiper object did not resolve the exception. What finally fixed the problem for me was setting the animation field to false when move is called: swiperController.move(provider.getCurrentActiveIndex(), animation: false);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants