Skip to content
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

Make compatible with hot reload #30

Open
saddy001 opened this issue Jun 7, 2019 · 8 comments
Open

Make compatible with hot reload #30

saddy001 opened this issue Jun 7, 2019 · 8 comments

Comments

@saddy001
Copy link

saddy001 commented Jun 7, 2019

I'd like to resurrect #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()));
@duytq94
Copy link
Owner

duytq94 commented Jun 10, 2019

Definitely need some help since I don't know why hot reload don't affect.
Any explanation is a great value.

@duytq94
Copy link
Owner

duytq94 commented Jun 12, 2019

I found this, maybe we stuck in this case:
image

Detail here

@saddy001
Copy link
Author

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.

@freitzzz
Copy link

freitzzz commented Aug 26, 2019

I found this, maybe we stuck in this case:
image

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

@deepss1
Copy link

deepss1 commented Aug 28, 2019

I found this, maybe we stuck in this case:
image
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 ?

@freitzzz
Copy link

I found this, maybe we stuck in this case:
image
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.

@deepss1
Copy link

deepss1 commented Aug 28, 2019

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 ?

@michael-markl
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants