ListView

Dart, Flutter 2021. 12. 30. 18:25

728x90
class TestApp extends StatefulWidget {
	const TestApp({Key? key}) : super(key: key);

	@override
	_TestAppState createState() => _TestAppState();
}

class _TestAppState extends State<TestApp> {
	final List<String> entries = <String>["A", "B", "C"];
	final List<int> numbers = <int>[600, 500, 400];

	@override
	Widget build(BuildContext context) {
		return Scaffold(
			appBar: AppBar(
				title: const Text(
					"example",
				),
			),
			body: ListViewBuilder(entries: entries, numbers: numbers),
		);
	}
}

class ListViewBuilder extends StatelessWidget {
	const ListViewBuilder({Key? key, required this.entires, required this.numbers}) : super(key: key);
	final List<String> entries;
	final List<int> numbers;

	@override
	Widget build(BuildContext context) {
		return ListView.builder(
			itemCount: entries.length,
			itemBuilder: (BuildContext context, int index) {
				return Container(
					height: 50,
					color: Colors.amber[numbers[index]],
					child: Center(
						child: Text(
							"Entry ${entries[index]}",
						),
					),
				);
			}
		);
	}
}

 

 

반응형

댓글 0