I create a parent page contains a list about custom widgets, the list is variable so I can add or decrease the number of these custom widgets immediately.
The custom widgets are contained by
List<FoodContainer> _foods = [];
in parent page.
The custom widget looks like:
class FoodContainer extends StatefulWidget {
const FoodContainer({
Key? key,
}) : super(key: key);
@override
_FoodContainerState createState() => _FoodContainerState();
}
class _FoodContainerState extends State<FoodContainer> {
var _result;
@override
Widget build(BuildContext context) {
return Container(
child :TextField(
onSubmitted: (String s){
setState(() {
_result = Func(s);
});
},
),
);
}
}
Now I want to get the value of _result in every child widget,how can I get them?
I tried to do like this:
class FoodContainer extends StatefulWidget {
const FoodContainer({
Key? key,
required this.foodTextControl,
}) : super(key: key);
final TextEditingController foodTextControl;
The widget.foodTextControl.text can be read in parent page, but the Func(s) is a web request, I don’t want to request twice.
2
Answers
Thanks for Aswanath C K,I created a simple custom controller to get the child widget info.
When the _result changes,make
Now it's finished.
If you want the _result of all the children (FoodContainers) to the parent (ListView.builder).Then you can use
and when the onSubmitted is called you can use this like:
And on the parent(Listview) you can get the access by:
I hope this will resolve your issue.