-
Notifications
You must be signed in to change notification settings - Fork 26.7k
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
Stepper doesn't let's childs update their state ? #22033
Comments
Is this in a stateful or statless widget. Please also add the output of |
This is in a stateful widget. Because the method setState was working, and in the variable it was updating the value, but the UI would stay at the beginning state, not letting StarRating to refresh itself. class Demo extends StatefulWidget {
@override
_DemoState createState() => _DemoState();
}
class _DemoState extends State<Demo> {
int current_step = 0;
double rating = 0.0;
double rating2 = 0.0;
List<Step> questions = [
Step(
content: StarRating(
rating: rating,
color: Colors.orange,
borderColor: Colors.grey,
size: 50.0,
starCount: 5,
onRatingChanged: (rating) =>
setState(() {
this.rating = rating;
})),
title: Text('XX')),
Step(
content: StarRating(
rating: rating2,
color: Colors.orange,
borderColor: Colors.grey,
size: 50.0,
starCount: 5,
onRatingChanged: (rating) =>
setState(() {
this.rating2 = rating;
})),
title: Text('XX2')),
];
@override
Widget build(BuildContext context) {
return new Scaffold(
// Appbar
appBar: new AppBar(
// Title
title: new Text("Simple Material App"),
),
// Body
body: new Container(
child: new Stepper(
// Using a variable here for handling the currentStep
currentStep: this.current_step,
// List the steps you would like to have
steps: questions,
// Define the type of Stepper style
// StepperType.horizontal : Horizontal Style
// StepperType.vertical : Vertical Style
type: StepperType.vertical,
// Know the step that is tapped
onStepTapped: (step) {
// On hitting step itself, change the state and jump to that step
setState(() {
// update the variable handling the current step value
// jump to the tapped step
current_step = step;
});
// Log function call
print("onStepTapped : " + step.toString());
},
onStepCancel: () {
// On hitting cancel button, change the state
setState(() {
// update the variable handling the current step value
// going back one step i.e subtracting 1, until its 0
if (current_step > 0) {
current_step = current_step - 1;
} else {
current_step = 0;
}
});
// Log function call
print("onStepCancel : " + current_step.toString());
},
// On hitting continue button, change the state
onStepContinue: () {
setState(() {
// update the variable handling the current step value
// going back one step i.e adding 1, until its the length of the step
if (current_step < my_steps.length - 1) {
current_step = current_step + 1;
} else {
current_step = 0;
}
});
// Log function call
print("onStepContinue : " + current_step.toString());
},
)),
);
}
}
|
That's because List<Step> questions = [ makes Changing it to List<Step> get questions => [ should fix that already. |
Ups, didn't mean to close, but I think the question is answered anyway. Please consider asking support questions in one of the other channels listed at http://flutter.io/support . |
What's the difference between using a get and not using it ? never understood it. |
The difference is that with a getter the code after |
Thanks. I've tryed with your method, but it doesn't work. If i put a setState inside the step content, it wont refresh the UI. |
https://gist.github.com/zoechi/a8799b2f6d3321e4f91073018abbd714 seemed to work fine |
Oh, ok. So apparently my problem is when i try to make it dynamic. Do you know a method on how to make the list of steps dynamic ? |
Not sure what you mean. So it seems the whole question reduces to |
Actually my problem is this. So when the widget starts, i do have to make the list based on a series of widgets. https://gist.github.com/Nik99/5c65b0751e3948d5ec894791cd254e7c This is my code. As you can see, on the initState i compile the variable "domandeList" which is then used by get domande and after by the stepper. I think the problem stays here. I do have needs to dynamically generate the UI, but i also need to update the stepper. In your code, data is directly inserted in the initialization of the questions variable. Mine, is added after. |
The setState inside "inserisciRating" works, because i do see the prints on my console, but it just doesn't update the UI. |
If you added the getter here because of my suggestion above, then this won't have an effect here because after
You should just move
to Widgets with dynamic content need to be build in |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Hi everyone.
I'm trying to make a stepper with star rating inside every step, but while the values changes, the UI does not. It seems like it's not refreshing the content.
The plugin for rating is this: https://pub.dartlang.org/packages/flutter_rating
This is my test code:
If i take it outside of the stepper, it works and refreshes it self nicely.
The text was updated successfully, but these errors were encountered: