使用ListView.builder创建
import 'package:flutter/material.dart';
void main(List<String> args) {
runApp(
const MaterialApp(
home: HomePage(),
debugShowCheckedModeBanner: false,
),
);
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
itemCount: 100,
itemBuilder: (context, index) {
return ColoredBox(
color: index % 2 == 0 ? Colors.white : Colors.blue,
child: Center(
heightFactor: 1.5,
child: Text(
index.toString(),
style: TextStyle(
color: index % 2 == 0 ? Colors.blue : Colors.white,
),
),
),
);
},
),
);
}
}