You can use ListView.builder
or GridView.builder
, just specify the number of items in the itemCount
field.
Example using GridView.builder
:
class MyHomePage extends StatelessWidget {
final List<String> notes = ["Lorem", "Ipsum", "Dolor"];
@override
Widget build(BuildContext context) {
return GridView.builder(
itemCount: notes.length,
itemBuilder: (context, index) {
return Padding(
padding: EdgeInsets.all(8),
child: Container(
width: 200,
height: 200,
color: Colors.blue,
child: Center(
child: Text(notes[index]),
),
),
);
},
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
),
);
}
}
Result:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…