how can i use forloop to generate values of data variable please help i am a beginner
class Mentions extends StatefulWidget {
const Mentions({
Key? key,
this.width,
this.height,
required this.fullname,
required this.username,
required this.photourl,
}) : super(key: key);
final double? width;
final double? height;
final List<String> fullname;
final List<String> username;
final List<String> photourl;
@override
_MentionsState createState() => _MentionsState();
}
class _MentionsState extends State<Mentions> {
List<Map<String, dynamic>> data = [];
void data1(
for(int i = 0; i< widget.fullname.length; i++) {
data.add({"Full Name": widget.fullname[i], "username": widget.username[i], "photourl" :widget.photourl[i] });
}
)
);
@override
Widget build(BuildContext context) {
return Container();
}
}
2
Answers
you can place your method inside
initState
try this:
then you can just use
widget.users
in _MentionsState. but you can even not set all this lists in widget constructor, do mapping to users before, and set to widget constructor just one list with users. and do you really need stateful widget instead of stateless?