I have this two arrays and want to generate Column Widget like below.
class ProfileWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
List<FaIcon> infoIcon = [
FaIcon(FontAwesomeIcons.idCard),
FaIcon(FontAwesomeIcons.at),
];
List infoText = [
'AAA',
'[email protected]',
];
return Column(
children: [
// divider box
Center(
child: Container(
child: Row(
children: <Widget>[
Expanded(
child: Divider(
color: Colors.orange,
height: 40,
thickness: 2,
indent: 30,
endIndent: 10,
),
),
Text(
"Info",
style: TextStyle(
color: Colors.lightGreen, fontWeight: FontWeight.bold),
),
Expanded(
child: Divider(
color: Colors.blue,
height: 40,
indent: 10,
endIndent: 30,
thickness: 2,
),
),
],
),
),
),
List<Widget>.generate(infoIcon.length, (index) {
return Padding(
padding: const EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 5.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 120,
child: Center(
child: FaIcon(
infoIcon[index],
),
),
),
Container(
width: 175,
child: Text(
infoText[index],
overflow: TextOverflow.ellipsis,
style: notNotDefaultStyle,
),
)
],
),
);
}),
],
);
}
}
I get an error like
The element type 'List<Widget>' can't be assigned to the list type 'Widget'
So, I changed to dynamic and then I also receive Generates a list of values. Creates a list with [length] positions and fills it with values created by calling [generator] for each index in the range 0 .. length - 1 in increasing order.
I even delete <> but then, still it does not work. How can I generate widgets with two arrays using List.generate() in flutter?