From 2d3d08cff1e777bbc2319e5eb5284133cb1bc071 Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Tue, 26 Apr 2022 19:37:36 -0500 Subject: [PATCH 1/5] Update submodules with excerpter binary files fix --- examples/codelabs | 2 +- site-shared | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/codelabs b/examples/codelabs index cfdedfb1cb..8e17b10137 160000 --- a/examples/codelabs +++ b/examples/codelabs @@ -1 +1 @@ -Subproject commit cfdedfb1cb00fc0cc2a97d42899653b2a9c08dd6 +Subproject commit 8e17b1013701bb71ab80ff9575c41de6cf42a351 diff --git a/site-shared b/site-shared index 142de13347..f3fd1c5de3 160000 --- a/site-shared +++ b/site-shared @@ -1 +1 @@ -Subproject commit 142de133477bdede1746f992e656c4b43c4c7442 +Subproject commit f3fd1c5de3eb8fdfc1aefdc8032e4c78757f0b0f From f69a9135269087f84c6b3907501b156cbd8fee8a Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Tue, 26 Apr 2022 19:48:37 -0500 Subject: [PATCH 2/5] Update code excerpts --- src/get-started/codelab.md | 104 ++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 59 deletions(-) diff --git a/src/get-started/codelab.md b/src/get-started/codelab.md index 7b909efd0a..fe306d2bb9 100644 --- a/src/get-started/codelab.md +++ b/src/get-started/codelab.md @@ -498,7 +498,7 @@ lazily, on demand. ```dart class _RandomWordsState extends State { [!final _suggestions = [];!] - [!final _biggerFont = const TextStyle(fontSize: 18.0);!] + [!final _biggerFont = const TextStyle(fontSize: 18);!] // ยทยทยท } ``` @@ -521,7 +521,7 @@ lazily, on demand. ```dart - body: ListView.builder( + return ListView.builder( padding: const EdgeInsets.all(16.0), itemBuilder: /*1*/ (context, i) { if (i.isOdd) return const Divider(); /*2*/ @@ -537,7 +537,6 @@ lazily, on demand. ), ); }, - ), ``` {:.numbered-code-notes} @@ -580,27 +579,22 @@ lazily, on demand. ```dart @override Widget build(BuildContext context) { - [!return Scaffold(!] - [! appBar: AppBar(!] - [! title: const Text('Startup Name Generator'),!] - [! ),!] - [! body: 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 ListTile(!] - [! title: Text(!] - [! _suggestions[index].asPascalCase,!] - [! style: _biggerFont,!] - [! ),!] - [! );!] - [! },!] - [! ),!] + [!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 ListTile(!] + [! title: Text(!] + [! _suggestions[index].asPascalCase,!] + [! style: _biggerFont,!] + [! ),!] + [! );!] + [! },!] [!);!] } ``` @@ -613,57 +607,49 @@ lazily, on demand. ```diff --- step3_stateful_widget/lib/main.dart +++ step4_infinite_list/lib/main.dart - @@ -13,27 +13,43 @@ - const MyApp({Key? key}) : super(key: key); + @@ -14,12 +14,12 @@ @override Widget build(BuildContext context) { - - return MaterialApp( + return MaterialApp( - title: 'Welcome to Flutter', - - home: Scaffold( - - appBar: AppBar( - - title: const Text('Welcome to Flutter'), - - ), - - body: const Center( - - child: RandomWords(), - - ), - - ), - + return const MaterialApp( + title: 'Startup Name Generator', - + home: RandomWords(), - ); + home: Scaffold( + appBar: AppBar( + - title: const Text('Welcome to Flutter'), + + title: const Text('Startup Name Generator'), + ), + body: const Center( + child: RandomWords(), + ), + @@ -28,12 +28,30 @@ } } class _RandomWordsState extends State { + final _suggestions = []; - + final _biggerFont = const TextStyle(fontSize: 18.0); + + final _biggerFont = const TextStyle(fontSize: 18); + @override Widget build(BuildContext context) { - final wordPair = WordPair.random(); - return Text(wordPair.asPascalCase); - + return Scaffold( - + appBar: AppBar( - + title: const Text('Startup Name Generator'), - + ), - + body: ListView.builder( - + padding: const EdgeInsets.all(16.0), - + itemBuilder: /*1*/ (context, i) { - + if (i.isOdd) return const Divider(); /*2*/ + + 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 ListTile( - + title: Text( - + _suggestions[index].asPascalCase, - + style: _biggerFont, - + ), - + ); - + }, - + ), + + final index = i ~/ 2; /*3*/ + + if (index >= _suggestions.length) { + + _suggestions.addAll(generateWordPairs().take(10)); /*4*/ + + } + + return ListTile( + + title: Text( + + _suggestions[index].asPascalCase, + + style: _biggerFont, + + ), + + ); + + }, + ); } } From 7fe0ec5d39d44ac1ec4cc5490df80a7b14a98237 Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Tue, 26 Apr 2022 20:18:35 -0500 Subject: [PATCH 3/5] Adjust text for changes in codelab --- src/get-started/codelab.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/get-started/codelab.md b/src/get-started/codelab.md index fe306d2bb9..c126016858 100644 --- a/src/get-started/codelab.md +++ b/src/get-started/codelab.md @@ -517,7 +517,8 @@ lazily, on demand. This model allows the suggested list to continue growing as the user scrolls. - 2. Add a `ListView.builder` widget to the `build` method of the `_RandomWordsState` class: + 2. Return a `ListView` widget from the `build` method + of the `_RandomWordsState` class using the `ListView.builder` constructor: ```dart @@ -557,7 +558,8 @@ lazily, on demand. word pair. This function displays each new pair in a `ListTile`, which allows you to make the rows more attractive in the next step. - 3. Add a `ListTile` in the `itemBuilder` body of the `ListView.builder` in `_RandomWordsState`: + 3. Add a `ListTile` in the `itemBuilder` body + of the `ListView.builder` in `_RandomWordsState`: ```dart @@ -599,8 +601,8 @@ lazily, on demand. } ``` - 5. In the `MyApp` class, update the `build()` method by changing the title, - and changing the home to be a `RandomWords` widget: + 5. In the `MyApp` class, update the `build()` method + by changing the title of the `AppBar`: From 4774912a1ad2ecbbf7894ca94d8364b2ed76ad4c Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Tue, 26 Apr 2022 21:28:56 -0500 Subject: [PATCH 4/5] Update codelab to remove repeated instructions --- src/get-started/codelab.md | 40 ++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/get-started/codelab.md b/src/get-started/codelab.md index c126016858..9ac5e32f69 100644 --- a/src/get-started/codelab.md +++ b/src/get-started/codelab.md @@ -503,9 +503,9 @@ lazily, on demand. } ``` - Next, you'll add a `ListView.builder` widget to the - `_RandomWordsState` class. This method builds the - `ListView` that displays the suggested word pairing. + Next, you'll add a `ListView` widget to the + `_RandomWordsState` class with the `ListView.builder` constructor. + This method creates the `ListView` that displays the suggested word pairing. The `ListView` class provides a builder property, `itemBuilder`, that's a factory builder and callback function specified as an @@ -520,7 +520,7 @@ lazily, on demand. 2. Return a `ListView` widget from the `build` method of the `_RandomWordsState` class using the `ListView.builder` constructor: - + ```dart return ListView.builder( padding: const EdgeInsets.all(16.0), @@ -531,12 +531,7 @@ lazily, on demand. if (index >= _suggestions.length) { _suggestions.addAll(generateWordPairs().take(10)); /*4*/ } - return ListTile( - title: Text( - _suggestions[index].asPascalCase, - style: _biggerFont, - ), - ); + return Text(_suggestions[index].asPascalCase); }, ``` @@ -554,12 +549,14 @@ lazily, on demand. 4. If you've reached the end of the available word pairings, then generate 10 more and add them to the suggestions list. - The `ListView.builder` widget creates a `ListTile` once per - word pair. This function displays each new pair in a `ListTile`, + The `ListView.builder` constructor creates and displays + a `Text` widget once per word pairing. + In the next step, you'll instead return each new pair as a `ListTile`, which allows you to make the rows more attractive in the next step. - 3. Add a `ListTile` in the `itemBuilder` body - of the `ListView.builder` in `_RandomWordsState`: + 3. Replace the returned `Text` in the `itemBuilder` body + of the `ListView.builder` in `_RandomWordsState` + with a `ListTile` displaying the suggestion: ```dart @@ -570,12 +567,12 @@ lazily, on demand. ), ); ``` + + A `ListTile` is a fixed height row that contains text + as well as leading or trailing icons or other widgets. - 4. In the `_RandomWordsState` class, update the `build()` method to use - the `ListView.builder`, rather than directly calling the word - generation library. ([`Scaffold`][] - implements the basic Material Design visual layout.) - Replace the method body with the highlighted code: + 4. Once complete, the `build()` method in the `_RandomWordsState` class + should match the following highlighted code: ```dart @@ -601,8 +598,9 @@ lazily, on demand. } ``` - 5. In the `MyApp` class, update the `build()` method - by changing the title of the `AppBar`: + 5. To put it all together, update the displayed title of the app + by updating the `build()` method in the `MyApp` class + and changing the title of the `AppBar`: From 640ca587cbbbb2e547b5ef77e85f3595243e5c4c Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Tue, 26 Apr 2022 21:29:19 -0500 Subject: [PATCH 5/5] Update codelabs again --- examples/codelabs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/codelabs b/examples/codelabs index 8e17b10137..b100728476 160000 --- a/examples/codelabs +++ b/examples/codelabs @@ -1 +1 @@ -Subproject commit 8e17b1013701bb71ab80ff9575c41de6cf42a351 +Subproject commit b100728476af3ce59fcba53ebebff24d08e366a1