Closed TouseefAQ closed 2 years ago
@TouseefAQ
I think that's not bug of swipable_stack
🤔
I had a similar situation, and I did the following :
sample code is like following (it's not full code):
class ModeSwitchingWidget extends StatelessWidget {
const ModeSwitchingWidget({ Key? key }) : super(key: key);
@override
Widget build(BuildContext context) {
if (isLoading) {
return CircularProgressIndicator();
}
if (mode === Mode.a) {
return ASwipableStack();
}
return BSwipableStack();
}
}
class ASwipableStack extends StatefulWidget {
const ASwipableStack({Key? key}) : super(key: key);
@override
State<ASwipableStack> createState() => _ASwipableStackState();
}
class _ASwipableStackState extends State<ASwipableStack> {
late final SwipableStackController _controller = SwipableStackController();
@override
Widget build(BuildContext context) {
return SwipableStack(
controller: _controller,
);
}
}
class BSwipableStack extends StatefulWidget {
const BSwipableStack({Key? key}) : super(key: key);
@override
State<ASwipableStack> createState() => _BSwipableStackState();
}
class _BSwipableStackState extends State<BSwipableStack> {
late final SwipableStackController _controller = SwipableStackController();
@override
Widget build(BuildContext context) {
return SwipableStack(
controller: _controller,
);
}
}
Thank you for your solution , I have used different approach , as i am using statemanagement , every time if switch the mode, i initialize the controller with initial index 0. is there any drawback of using my approach ?
resetControllerIndex() { _Swipecontroller = SwipableStackController(initialIndex: 0) ..addListener(notifyListeners); notifyListeners(); }
@TouseefAQ I feel your solution is not bad 🤔 But ‘SwipableStack’ internally uses unique GlobalKey, so that maybe it could be broken depending on frame updating timing.
So I recommend you to regenerate both controller and SwipableStack when replacing content.
Thank you very much.
I have two mode is my app with two differnt list. In mode 1 i swipe for example 3 profile but when i switch to mode 2 my builder index remains 2. I don't if it is an isssue but this is not working as it should be. It should build from index 0 every time new list is feed.