Snipped of code
Hi Isosystem,
We are validating your query at our end and we will update further details in one business day on 28 Dec 2022. We appreciate your patience until then.
Regards,
Yuvaraj.
Hi Isosystem,
Flutter will compare the previous widget state with the new one before re-rendering. If the two widgets are of the same type, the old state will be preserved. In your sample, you are using a condition to switch between horizontal and vertical slider widgets, which are of the same type. To overcome this issue, you can assign different keys to the widgets. This will allow Flutter to distinguish between the two different types of widgets and prevent the preservation of the old state. We have modified your snippets based on this and shared them below for your reference.
Code snippet:
Key verticalKey = const Key('vertical'); Key horizontalKey = const Key('horizontal'); @override Widget build(BuildContext context) { return Scaffold( body: Center( child: BlocBuilder<MyBloc, MyState>( builder: (BuildContext context, MyState state) { Widget fn() { if (MediaQuery.of(context).orientation == Orientation.portrait) { return SizedBox( height: 700, width: 500, child: SfRangeSliderTheme( data: SfRangeSliderThemeData( // Other required properties ), child: SfSlider( key: horizontalKey, // Other required properties ), ), ); } else { return SizedBox( height: 500, width: 700, child: SfRangeSliderTheme( data: SfRangeSliderThemeData( // Other required properties ), child: SfSlider.vertical( key: verticalKey, // Other required properties ), ), ); } } return fn(); }, ), ), ); } |
Regards,
Yuvaraj
Thanks a lot!
The problem was solved.
Regards
Vadym
Most Welcome. Kindly get back to us if you have further queries. We are always happy to assist you.