appinioGmbH / flutter_packages

Dart and Flutter plugins/packages used and maintained by @appinioGmbH
193 stars 224 forks source link

[appinio_swiper] Error when using controller after widget rebuild #157

Closed Nico04 closed 11 months ago

Nico04 commented 1 year ago

When using AppinioSwiper with a AppinioSwiperController, if parent widget is rebuilt (for instance with a StreamBuilder & a ValueKey), then using the controller will throw :

======== Exception caught by foundation library =================
The following assertion was thrown while dispatching notifications for AppinioSwiperController:
**This widget has been unmounted, so the State no longer has a context (and should be considered defunct).** 

Consider canceling any active work during "dispose" or using the "mounted" getter to determine if the State is still active.
When the exception was thrown, this was the stack: 
#0      State.context.<anonymous closure> (package:flutter/src/widgets/framework.dart:951:9)
#1      State.context (package:flutter/src/widgets/framework.dart:957:6)
#2      _AppinioSwiperState.initState.<anonymous closure> (package:appinio_swiper/appinio_swiper.dart:193:32)
#3      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:403:24)
#4      AppinioSwiperController.swipeRight (package:appinio_swiper/controllers.dart:24:5)
#5      _InkResponseState.handleTap (package:flutter/src/material/ink_well.dart:1154:21)
...
The AppinioSwiperController sending notification was: Instance of 'AppinioSwiperController'
=============================================================

I don't know if it's related to this, but in any case you should implement didUpdateWidget and/or didChangeDependencies to update the controller.

khanmujeeb687 commented 1 year ago

Hey @Nico04 , All the issues you have created will be resolved in the next version which will be available next week. Thank you so much for creating github issues.

bilalhamud commented 11 months ago

Fixed with version 2.1.0