How can i assign final String blog_id; value that we get from const KidneyDiseaseBody({Key? key, required this.blog_id}) : super(key: key); in String query = ; in class _KidneyDiseaseBodyState
Asked
Active
Viewed 31 times
0

Gazihan Alankus
- 11,256
- 7
- 46
- 57

HARI OM SONI
- 11
-
Refer my answer [here](https://stackoverflow.com/a/68620675/13997210) hope it's helpful to you – Ravindra S. Patil Aug 14 '21 at 10:18
2 Answers
2
You can do
@override
void initState() {
super.initState();
query = widget.blog_id; // or whatever way you want to use it
}
you cannot do
String query = widget.blog_id;
since widget is assigned after State is created.

Gazihan Alankus
- 11,256
- 7
- 46
- 57
0
You can use it as widget.blog_id
.

Shreyansh Sharma
- 1,588
- 2
- 17
- 42
-
But not during construction, because the state's widget field is not assigned until afterwards. Use initState() as advised in Gazihan Alankus' answer. – realh Feb 28 '22 at 16:45