使用ListView和List.generated() 生成
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(
children: List.generate(100, (index) {
return ColoredBox(
color: index % 2 == 0 ? Colors.white : Colors.lightBlue,
child: Center(
heightFactor: 1.5,
child: Text(
index.toString(),
style: TextStyle(
color: index % 2 == 0 ? Colors.lightBlue : Colors.white,
),
),
),
);
}),
),
);
}
}