flutter-intro-slider
flutter-intro-slider copied to clipboard
Make compatible with hot reload
I'd like to resurrect https://github.com/duytq94/flutter-intro-slider/issues/18 because indeed hot reload would be very useful. For me, it's not working even when I use the suggested
Navigator.pushReplacement(
context, MaterialPageRoute(builder: (context) => IntroScreen()));
Definitely need some help since I don't know why hot reload don't affect. Any explanation is a great value.
I'm using it within a PostFrameCallback where I async call a
Future<Null> checkIsFirstLaunch() async {
...
Navigator.of(context).pushNamed('/intro');
}
to additionally ask a isFirstLaunch variable (SharedPreferences). Maybe hot reload is lost somewhere on the path. However, I don't know of another way to check if it's the first launch, where we usually want to have intro slides, I guess.
I found this, maybe we stuck in this case:
Detail here
As @duytq94 said, neither hot-reload and setState are possible to change IntroSlider widget as widgets are computed on IntroSlider initState. In order to achieve this, this would require to change all widgets computation to build method instead of initState. Also a workaround for setState is to create a new IntroSlider object and assign it to your widget
I found this, maybe we stuck in this case:
Detail here
As @duytq94 said, neither hot-reload and setState are possible to change IntroSlider widget as widgets are computed on IntroSlider initState. In order to achieve this, this would require to change all widgets computation to build method instead of initState. Also a workaround for setState is to create a new IntroSlider object and assign it to your widget
Can you please give a detailed resolution or workaround ?
I found this, maybe we stuck in this case:
Detail here
As @duytq94 said, neither hot-reload and setState are possible to change IntroSlider widget as widgets are computed on IntroSlider initState. In order to achieve this, this would require to change all widgets computation to build method instead of initState. Also a workaround for setState is to create a new IntroSlider object and assign it to your widget
Can you please give a detailed resolution or workaround ?
In Flutter there are two type of widgets, Stateless and Stateful Widgets.
Stateless Widgets, as the name indicate, dont have a state. This means that you cannot change the widget state, and in this way not indicate the framework that its required to render the widget again. A Stateful Widget has various states throughout its lifecycle and allows to change its state. By changing the widget state, you indicate the framework that is required to render widget again, or at least compute new widget values.
This plugin widget (IntroSlider
) is a StatefulWidget, yet by changing its state using setState
the widget is rendered the same way as it was previously. This is due to all IntroSlider widget computations are done in initState
method. When setState
is called, framework will call the widget build
method, as this method has the responsibility to tell the framework which widget should be rendered on the device screen.
In order to fix this problem, all computation that is done in initState
method should be moved to build
method.
As I said in my last reply, a workaround would be creating a new IntroSlider each time you want to change that state of the widget.
It will be really helpful to me and to others if you can share your piece of code where you render IntroSlider. I have completely moved initState computation in build method before it renders anything.
But by creating new IntroSlider, will we lose the previous IntroSlider's state ?
If you are using initState, you should also implement onDidUpdateWidget (to reflect changes of the widget on the Intro Slider state). Otherwise, you also prohibit a switch of light/dark mode or a change of the system language to be reflected.