From efbb99b3c2429128dd2a748c9e9833b7919cac35 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 16 Dec 2022 06:41:17 -0600 Subject: [PATCH] Step 4: Ininite scrolling list Signed-off-by: Jeff Carr --- lib/main.dart | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/main.dart b/lib/main.dart index 19e1901..98d61d3 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -41,9 +41,27 @@ class _RandomWordsState extends State { @override Widget build(BuildContext context) { final wordPair = WordPair.random(); + + return ListView.builder( + padding: const EdgeInsets.all(16.0), + itemBuilder: /*1*/ (context, i) { + if (i.isOdd) return const Divider(); /*2*/ + + final index = i ~/ 2; /*3*/ + if (index >= _suggestions.length) { + _suggestions.addAll(generateWordPairs().take(10)); /*4*/ + } + return Text( + _suggestions[index].asPascalCase, + style: TextStyle(fontSize: 36, fontWeight: FontWeight.bold) + ); + }, + ); + return Text( wordPair.asPascalCase, - style: TextStyle(fontSize: 48, fontWeight: FontWeight.bold) + style: TextStyle(fontSize: 48, fontWeight: FontWeight.bold) ); } + }