Skip to content

Commit cef4dc1

Browse files
Add fwe excerpt projects to examples workspace and fix lints (#13290)
Contributes to #13028 --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 7c873e7 commit cef4dc1

57 files changed

Lines changed: 190 additions & 270 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/fwe/birdle/.gitignore

Lines changed: 0 additions & 45 deletions
This file was deleted.

examples/fwe/birdle/.metadata

Lines changed: 0 additions & 45 deletions
This file was deleted.

examples/fwe/birdle/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
# birdle
1+
# Birdle app
22

3-
A new Flutter project.
3+
Code excerpts for the Birdle example app built in
4+
the [Flutter tutorial](https://docs.flutter.dev/learn/pathway/tutorial).

examples/fwe/birdle/analysis_options.yaml

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/fwe/birdle/lib/game.dart

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ enum HitType { none, hit, partial, miss, removed }
88

99
typedef Letter = ({String char, HitType type});
1010

11-
const legalWords = <String>["aback", "abase", "abate", "abbey", "abbot"];
11+
const legalWords = <String>['aback', 'abase', 'abate', 'abbey', 'abbot'];
1212

1313
/// Legal guesses minus legal wordles
1414
const legalGuesses = <String>[
15-
"aback",
16-
"abase",
17-
"abate",
18-
"abbey",
19-
"abbot",
20-
"abhor",
21-
"abide",
22-
"abled",
23-
"abode",
24-
"abort",
15+
'aback',
16+
'abase',
17+
'abate',
18+
'abbey',
19+
'abbot',
20+
'abhor',
21+
'abide',
22+
'abled',
23+
'abode',
24+
'abort',
2525
];
2626

2727
/// This class holds game state for a single round of Bulls and Cows,
2828
/// and exposes methods that a UI would need to manage the game state.
2929
///
30-
/// On it's own, this class won't manage a game. For example, it won't
31-
/// call [startGame] on it's own. It assumes that a client will use it's
32-
/// methods to progress through a game.
30+
/// On its own, this class won't manage a game.
31+
/// For example, it won't call [resetGame] on its own.
32+
/// It assumes that a client will use its methods to progress through a game.
3333
class Game {
3434
Game({this.numAllowedGuesses = defaultNumGuesses, this.seed}) {
3535
_wordToGuess = seed == null ? Word.random() : Word.fromSeed(seed!);
@@ -76,7 +76,7 @@ class Game {
7676
bool get didWin {
7777
if (_guesses.first.isEmpty) return false;
7878

79-
for (var letter in previousGuess) {
79+
for (final letter in previousGuess) {
8080
if (letter.type != HitType.hit) return false;
8181
}
8282

@@ -94,7 +94,7 @@ class Game {
9494
// Doesn't move the game forward, only executes match logic.
9595
Word matchGuessOnly(String guess) {
9696
// The hidden word will be used by subsequent guesses.
97-
var hiddenCopy = Word.fromString(_wordToGuess.toString());
97+
final hiddenCopy = Word.fromString(_wordToGuess.toString());
9898
return Word.fromString(guess).evaluateGuess(hiddenCopy);
9999
}
100100

@@ -112,16 +112,16 @@ class Word with IterableMixin<Letter> {
112112
}
113113

114114
factory Word.fromString(String guess) {
115-
var list = guess.toLowerCase().split('');
116-
var letters = list
117-
.map((String char) => (char: char, type: HitType.none))
115+
final list = guess.toLowerCase().split('');
116+
final letters = list
117+
.map((char) => (char: char, type: HitType.none))
118118
.toList();
119119
return Word(letters);
120120
}
121121

122122
factory Word.random() {
123-
var rand = Random();
124-
var nextWord = legalWords[rand.nextInt(legalWords.length)];
123+
final rand = Random();
124+
final nextWord = legalWords[rand.nextInt(legalWords.length)];
125125
return Word.fromString(nextWord);
126126
}
127127

@@ -148,7 +148,7 @@ class Word with IterableMixin<Letter> {
148148

149149
@override
150150
String toString() {
151-
return _letters.map((Letter c) => c.char).join().trim();
151+
return _letters.map((c) => c.char).join().trim();
152152
}
153153

154154
// Used to play game in the CLI implementation
@@ -168,7 +168,7 @@ extension WordUtils on Word {
168168
}
169169

170170
/// Compares two [Word] objects and returns a new [Word] that
171-
/// has the same letters as the [this], but each [Letter]
171+
/// has the same letters as this word, but each [Letter]
172172
/// has new a [HitType] of either [HitType.hit],
173173
/// [HitType.partial], or [HitType.miss].
174174
Word evaluateGuess(Word other) {
@@ -188,12 +188,12 @@ extension WordUtils on Word {
188188
for (var i = 0; i < other.length; i++) {
189189
// If a letter in the hidden word is already marked as "removed",
190190
// then it's already an exact match, so skip it
191-
Letter targetLetter = other[i];
191+
final targetLetter = other[i];
192192
if (targetLetter.type != HitType.none) continue;
193193

194194
// loop through the guessed word onces for each letter in the hidden word
195195
for (var j = 0; j < length; j++) {
196-
Letter guessedLetter = this[j];
196+
final guessedLetter = this[j];
197197
// skip letters that have already been marked as exact matches
198198
if (guessedLetter.type != HitType.none) continue;
199199
// If this letter, which must not be in the same position, is the same,

examples/fwe/birdle/lib/main.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
23
import 'game.dart';
34

45
void main() {
@@ -14,9 +15,12 @@ class MainApp extends StatelessWidget {
1415
return MaterialApp(
1516
home: Scaffold(
1617
appBar: AppBar(
17-
title: Align(alignment: Alignment.centerLeft, child: Text('Birdle')),
18+
title: const Align(
19+
alignment: Alignment.centerLeft,
20+
child: Text('Birdle'),
21+
),
1822
),
19-
body: Center(child: GamePage()),
23+
body: const Center(child: GamePage()),
2024
),
2125
);
2226
}
@@ -42,16 +46,16 @@ class _GamePageState extends State<GamePage> {
4246
spacing: 5.0,
4347
mainAxisAlignment: MainAxisAlignment.center,
4448
children: [
45-
for (var guess in _game.guesses)
49+
for (final guess in _game.guesses)
4650
Row(
4751
spacing: 5.0,
4852
mainAxisAlignment: MainAxisAlignment.center,
4953
children: [
50-
for (var letter in guess) Tile(letter.char, letter.type),
54+
for (final letter in guess) Tile(letter.char, letter.type),
5155
],
5256
),
5357
GuessInput(
54-
onSubmitGuess: (String guess) {
58+
onSubmitGuess: (guess) {
5559
setState(() {
5660
_game.guess(guess);
5761
});
@@ -98,7 +102,7 @@ class GuessInput extends StatelessWidget {
98102
controller: _textEditingController,
99103
autofocus: true,
100104
focusNode: _focusNode,
101-
onSubmitted: (String input) {
105+
onSubmitted: (input) {
102106
_onSubmit();
103107
},
104108
),

examples/fwe/birdle/lib/step1_main.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ignore_for_file: unused_import, unused_field, unused_local_variable, avoid_print, prefer_const_constructors_in_immutables, use_key_in_widget_constructors, sized_box_for_whitespace
21
import 'package:flutter/material.dart';
32

43
// #docregion main

examples/fwe/birdle/lib/step2_main.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// ignore_for_file: unused_import, unused_field, unused_local_variable, avoid_print, prefer_const_constructors_in_immutables, use_key_in_widget_constructors, sized_box_for_whitespace
1+
// ignore_for_file: prefer_const_constructors
2+
23
import 'package:flutter/material.dart';
4+
35
import 'game.dart';
46

57
void main() {

examples/fwe/birdle/lib/step2a_main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// ignore_for_file: unused_import, unused_field, unused_local_variable, avoid_print, prefer_const_constructors_in_immutables, use_key_in_widget_constructors, sized_box_for_whitespace
21
import 'package:flutter/material.dart';
2+
33
import 'game.dart';
44

55
// #docregion Tile

examples/fwe/birdle/lib/step2b_main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// ignore_for_file: unused_import, unused_field, unused_local_variable, avoid_print, prefer_const_constructors_in_immutables, use_key_in_widget_constructors, sized_box_for_whitespace
21
import 'package:flutter/material.dart';
2+
33
import 'game.dart';
44

55
// #docregion Tile

0 commit comments

Comments
 (0)