-
Notifications
You must be signed in to change notification settings - Fork 717
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
swiper item can't be hot add? #64
Comments
I found the swiper.js has observer can update item, if the package can do it? |
I found that if the new itemCount is the same as the init count. it's will play normal |
Before setState,use method stopAutoplay and method move(0) of swiperController |
I have try, but it doesn't work and return the same error |
The following is what I write and it works Widget build(BuildContext context) { |
thanks a lot but it still does't work for me。if the itemCount changed the program will return the same error |
@zhouxting your solutions create swiper after list has value. however, i need to create swiper first when img download finished next to setState(); |
oh! ,i solve the problem by set different key . i will close the issue |
I suggested this should be added in Readme, It's easy to happen on hot loading and failed randomly. |
which widget i should set key |
我的解决方案是给Swiper设置一个key,当需要更新item的个数时,根据item的不同长度给Swiper使用不同的key就行,我使用的key是: ValueKey(items.length) |
I had the same problem and I solved it by same way. Thanks a lot ! |
Please what's mean about set diff key to solve this problem. I had the same problem |
please share the code |
My solution is to set a key for Swiper. When the number of items needs to be updated, use different keys for Swiper according to the different lengths of the items. The key I use is: ValueKey (items.length) |
Works!!! Awesome |
I download img from server then add the new item into the swiper items List.
next setState() but it give me an error like this.
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (21956): The following assertion was thrown building NotificationListener:
I/flutter (21956): ScrollController not attached to any scroll views.
I/flutter (21956): 'package:flutter/src/widgets/scroll_controller.dart': Failed assertion: line 110 pos 12:
I/flutter (21956): '_positions.isNotEmpty'
I/flutter (21956):
I/flutter (21956): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (21956): more information in this error message to help you determine and fix the underlying cause.
I/flutter (21956): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (21956): https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter (21956):
I/flutter (21956): When the exception was thrown, this was the stack:
I/flutter (21956): #2 ScrollController.position (package:flutter/src/widgets/scroll_controller.dart:110:12)
I/flutter (21956): #3 PageController.animateToPage (package:flutter/src/widgets/page_view.dart:119:41)
I/flutter (21956): #4 _TransformerPageViewState.didUpdateWidget (package:transformer_page_view/transformer_page_view.dart:511:25)
I/flutter (21956): #5 StatefulElement.update (package:flutter/src/widgets/framework.dart:3879:58)
I/flutter (21956): #6 Element.updateChild (package:flutter/src/widgets/framework.dart:2748:15)
I/flutter (21956): #7 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3747:16)
I/flutter (21956): #8 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5)
I/flutter (21956): #9 StatelessElement.update (package:flutter/src/widgets/framework.dart:3796:5)
I/flutter (21956): #10 Element.updateChild (package:flutter/src/widgets/framework.dart:2748:15)
I/flutter (21956): #11 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4601:32)
I/flutter (21956): #12 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4992:17)
I/flutter (21956): #13 Element.updateChild (package:flutter/src/widgets/framework.dart:2748:15)
I/flutter (21956): #14 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3747:16)
I/flutter (21956): #15 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5)
I/flutter (21956): #16 StatefulElement.update (package:flutter/src/widgets/framework.dart:3894:5)
I/flutter (21956): #17 Element.updateChild (package:flutter/src/widgets/framework.dart:2748:15)
I/flutter (21956): #18 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4601:32)
I/flutter (21956): #19 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4992:17)
I/flutter (21956): #20 Element.updateChild (package:flutter/src/widgets/framework.dart:2748:15)
I/flutter (21956): #21 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4883:14)
I/flutter (21956): #22 Element.updateChild (package:flutter/src/widgets/framework.dart:2748:15)
I/flutter (21956): #23 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3747:16)
I/flutter (21956): #24 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5)
I/flutter (21956): #25 StatelessElement.update (package:flutter/src/widgets/framework.dart:3796:5)
I/flutter (21956): #26 Element.updateChild (package:flutter/src/widgets/framework.dart:2748:15)
I/flutter (21956): #27 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3747:16)
I/flutter (21956): #28 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5)
I/flutter (21956): #29 ProxyElement.update (package:flutter/src/widgets/framework.dart:4006:5)
I/flutter (21956): #30 Element.updateChild (package:flutter/src/widgets/framework.dart:2748:15)
I/flutter (21956): #31 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3747:16)
I/flutter (21956): #32 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5)
I/flutter (21956): #33 ProxyElement.update (package:flutter/src/widgets/framework.dart:4006:5)
I/flutter (21956): #34 Element.updateChild (package:flutter/src/widgets/framework.dart:2748:15)
The text was updated successfully, but these errors were encountered: