Skip to content

Commit

Permalink
namer Aligning with the codelab text (flutter#1476)
Browse files Browse the repository at this point in the history
* `namer` Aligning with the codelab text

* Making the tests AWESOME aware
  • Loading branch information
domesticmouse authored Mar 16, 2023
1 parent 43122b2 commit 9429d30
Show file tree
Hide file tree
Showing 32 changed files with 134 additions and 114 deletions.
77 changes: 48 additions & 29 deletions namer/codelab_rebuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,14 @@ steps:
- name: Add button code
path: namer_app/lib/main.dart
patch-u: |
--- a/namer_app/lib/main.dart
+++ b/namer_app/lib/main.dart
@@ -39,6 +39,12 @@ class MyHomePage extends StatelessWidget {
--- b/namer/step_04_a_widget/lib/main.dart
+++ a/namer/step_04_a_widget/lib/main.dart
@@ -37,8 +37,14 @@ class MyHomePage extends StatelessWidget {
return Scaffold(
body: Column(
children: [
Text('A random idea:'),
- Text('A random idea:'),
+ Text('A random AWESOME idea:'),
Text(appState.current.asLowerCase),
+ ElevatedButton(
+ onPressed: () {
Expand All @@ -159,6 +162,19 @@ steps:
],
),
);
- name: Patch test/widget_test.dart
path: namer_app/test/widget_test.dart
patch-u: |
--- b/namer/step_04_a_widget/test/widget_test.dart
+++ a/namer/step_04_a_widget/test/widget_test.dart
@@ -5,6 +5,6 @@ import 'package:namer_app/main.dart';
void main() {
testWidgets('App starts', (WidgetTester tester) async {
await tester.pumpWidget(const MyApp());
- expect(find.text('A random idea:'), findsOneWidget);
+ expect(find.text('A random AWESOME idea:'), findsOneWidget);
});
}
- name: Copy step_04_a_widget
copydir:
from: namer_app
Expand Down Expand Up @@ -206,7 +222,7 @@ steps:
@@ -6,5 +7,45 @@
testWidgets('App starts', (WidgetTester tester) async {
await tester.pumpWidget(const MyApp());
expect(find.text('A random idea:'), findsOneWidget);
expect(find.text('A random AWESOME idea:'), findsOneWidget);
+ });
+
+ testWidgets('Tapping button changes word pair', (WidgetTester tester) async {
Expand All @@ -216,7 +232,7 @@ steps:
+ final wordPairTextWidget = tester
+ // Get all Text widgets...
+ .widgetList<Text>(find.byType(Text))
+ // ... skip one ('A random idea:') ...
+ // ... skip one ('A random AWESOME idea:') ...
+ .skip(1)
+ // ... and take the first after it.
+ .first;
Expand Down Expand Up @@ -260,8 +276,8 @@ steps:
- name: Introduce pair variable
path: namer_app/lib/main.dart
patch-u: |
--- a/namer_app/lib/main.dart
+++ b/namer_app/lib/main.dart
--- b/namer/step_05_a_pair/lib/main.dart
+++ a/namer/step_05_a_pair/lib/main.dart
@@ -38,12 +38,13 @@ class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
Expand All @@ -271,7 +287,7 @@ steps:
return Scaffold(
body: Column(
children: [
Text('A random idea:'),
Text('A random AWESOME idea:'),
- Text(appState.current.asLowerCase),
+ Text(pair.asLowerCase),
ElevatedButton(
Expand All @@ -288,12 +304,12 @@ steps:
- name: Extract BigCard
path: namer_app/lib/main.dart
patch-u: |
--- a/namer_app/lib/main.dart
+++ b/namer_app/lib/main.dart
--- b/namer/step_05_b_extract/lib/main.dart
+++ a/namer/step_05_b_extract/lib/main.dart
@@ -44,7 +44,7 @@ class MyHomePage extends StatelessWidget {
body: Column(
children: [
Text('A random idea:'),
Text('A random AWESOME idea:'),
- Text(pair.asLowerCase),
+ BigCard(pair: pair),
ElevatedButton(
Expand All @@ -306,9 +322,9 @@ steps:
+
+class BigCard extends StatelessWidget {
+ const BigCard({
+ Key? key,
+ super.key,
+ required this.pair,
+ }) : super(key: key);
+ });
+
+ final WordPair pair;
+
Expand All @@ -329,7 +345,7 @@ steps:
- final wordPairTextWidget = tester
- // Get all Text widgets...
- .widgetList<Text>(find.byType(Text))
- // ... skip one ('A random idea:') ...
- // ... skip one ('A random AWESOME idea:') ...
- .skip(1)
- // ... and take the first after it.
- .first;
Expand Down Expand Up @@ -382,7 +398,7 @@ steps:
@override
Widget build(BuildContext context) {
+ var theme = Theme.of(context);
+ final theme = Theme.of(context);
+
return Card(
+ color: theme.colorScheme.primary,
Expand All @@ -405,8 +421,8 @@ steps:
@@ -68,12 +68,15 @@ class BigCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
var theme = Theme.of(context);
+ var style = theme.textTheme.displayMedium!.copyWith(
final theme = Theme.of(context);
+ final style = theme.textTheme.displayMedium!.copyWith(
+ color: theme.colorScheme.onPrimary,
+ );
Expand Down Expand Up @@ -435,8 +451,8 @@ steps:
@@ -68,15 +68,19 @@ class BigCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
var theme = Theme.of(context);
var style = theme.textTheme.displayMedium!.copyWith(
final theme = Theme.of(context);
final style = theme.textTheme.displayMedium!.copyWith(
color: theme.colorScheme.onPrimary,
);
Expand Down Expand Up @@ -464,15 +480,15 @@ steps:
- name: Center column vertically
path: namer_app/lib/main.dart
patch-u: |
--- a/namer_app/lib/main.dart
+++ b/namer_app/lib/main.dart
--- b/namer/step_05_g_center_vertical/lib/main.dart
+++ a/namer/step_05_g_center_vertical/lib/main.dart
@@ -42,6 +42,7 @@ class MyHomePage extends StatelessWidget {
return Scaffold(
body: Column(
+ mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('A random idea:'),
Text('A random AWESOME idea:'),
BigCard(pair: pair),
- name: Copy step_05_g_center_vertical
copydir:
Expand All @@ -485,16 +501,16 @@ steps:
- name: Center column horizontally
path: namer_app/lib/main.dart
patch-u: |
--- a/namer_app/lib/main.dart
+++ b/namer_app/lib/main.dart
--- b/namer/step_05_h_center_horizontal/lib/main.dart
+++ a/namer/step_05_h_center_horizontal/lib/main.dart
@@ -41,18 +41,20 @@ class MyHomePage extends StatelessWidget {
var pair = appState.current;
return Scaffold(
- body: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Text('A random idea:'),
- Text('A random AWESOME idea:'),
- BigCard(pair: pair),
- ElevatedButton(
- onPressed: () {
Expand All @@ -507,7 +523,7 @@ steps:
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ Text('A random idea:'),
+ Text('A random AWESOME idea:'),
+ BigCard(pair: pair),
+ ElevatedButton(
+ onPressed: () {
Expand Down Expand Up @@ -537,7 +553,7 @@ steps:
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
- Text('A random idea:'),
- Text('A random AWESOME idea:'),
BigCard(pair: pair),
+ SizedBox(height: 10),
ElevatedButton(
Expand All @@ -552,7 +568,7 @@ steps:
void main() {
testWidgets('App starts', (WidgetTester tester) async {
await tester.pumpWidget(const MyApp());
- expect(find.text('A random idea:'), findsOneWidget);
- expect(find.text('A random AWESOME idea:'), findsOneWidget);
+ expect(find.text('Next'), findsOneWidget);
});
Expand Down Expand Up @@ -1156,6 +1172,9 @@ steps:
platforms: [ windows ]
path: namer_app
flutter: build windows
- name: Add cupertino_icons for web build
path: namer_app
flutter: pub add cupertino_icons
- name: Build Web app
path: namer_app
flutter: build web
Expand Down
2 changes: 1 addition & 1 deletion namer/step_04_a_widget/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MyHomePage extends StatelessWidget {
return Scaffold(
body: Column(
children: [
Text('A random idea:'),
Text('A random AWESOME idea:'),
Text(appState.current.asLowerCase),
ElevatedButton(
onPressed: () {
Expand Down
2 changes: 1 addition & 1 deletion namer/step_04_a_widget/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import 'package:namer_app/main.dart';
void main() {
testWidgets('App starts', (WidgetTester tester) async {
await tester.pumpWidget(const MyApp());
expect(find.text('A random idea:'), findsOneWidget);
expect(find.text('A random AWESOME idea:'), findsOneWidget);
});
}
2 changes: 1 addition & 1 deletion namer/step_04_b_behavior/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MyHomePage extends StatelessWidget {
return Scaffold(
body: Column(
children: [
Text('A random idea:'),
Text('A random AWESOME idea:'),
Text(appState.current.asLowerCase),
ElevatedButton(
onPressed: () {
Expand Down
4 changes: 2 additions & 2 deletions namer/step_04_b_behavior/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:namer_app/main.dart';
void main() {
testWidgets('App starts', (WidgetTester tester) async {
await tester.pumpWidget(const MyApp());
expect(find.text('A random idea:'), findsOneWidget);
expect(find.text('A random AWESOME idea:'), findsOneWidget);
});

testWidgets('Tapping button changes word pair', (WidgetTester tester) async {
Expand All @@ -16,7 +16,7 @@ void main() {
final wordPairTextWidget = tester
// Get all Text widgets...
.widgetList<Text>(find.byType(Text))
// ... skip one ('A random idea:') ...
// ... skip one ('A random AWESOME idea:') ...
.skip(1)
// ... and take the first after it.
.first;
Expand Down
2 changes: 1 addition & 1 deletion namer/step_05_a_pair/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MyHomePage extends StatelessWidget {
return Scaffold(
body: Column(
children: [
Text('A random idea:'),
Text('A random AWESOME idea:'),
Text(pair.asLowerCase),
ElevatedButton(
onPressed: () {
Expand Down
4 changes: 2 additions & 2 deletions namer/step_05_a_pair/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:namer_app/main.dart';
void main() {
testWidgets('App starts', (WidgetTester tester) async {
await tester.pumpWidget(const MyApp());
expect(find.text('A random idea:'), findsOneWidget);
expect(find.text('A random AWESOME idea:'), findsOneWidget);
});

testWidgets('Tapping button changes word pair', (WidgetTester tester) async {
Expand All @@ -16,7 +16,7 @@ void main() {
final wordPairTextWidget = tester
// Get all Text widgets...
.widgetList<Text>(find.byType(Text))
// ... skip one ('A random idea:') ...
// ... skip one ('A random AWESOME idea:') ...
.skip(1)
// ... and take the first after it.
.first;
Expand Down
6 changes: 3 additions & 3 deletions namer/step_05_b_extract/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MyHomePage extends StatelessWidget {
return Scaffold(
body: Column(
children: [
Text('A random idea:'),
Text('A random AWESOME idea:'),
BigCard(pair: pair),
ElevatedButton(
onPressed: () {
Expand All @@ -59,9 +59,9 @@ class MyHomePage extends StatelessWidget {

class BigCard extends StatelessWidget {
const BigCard({
Key? key,
super.key,
required this.pair,
}) : super(key: key);
});

final WordPair pair;

Expand Down
2 changes: 1 addition & 1 deletion namer/step_05_b_extract/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:namer_app/main.dart';
void main() {
testWidgets('App starts', (WidgetTester tester) async {
await tester.pumpWidget(const MyApp());
expect(find.text('A random idea:'), findsOneWidget);
expect(find.text('A random AWESOME idea:'), findsOneWidget);
});

testWidgets('Tapping button changes word pair', (WidgetTester tester) async {
Expand Down
6 changes: 3 additions & 3 deletions namer/step_05_c_card_padding/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MyHomePage extends StatelessWidget {
return Scaffold(
body: Column(
children: [
Text('A random idea:'),
Text('A random AWESOME idea:'),
BigCard(pair: pair),
ElevatedButton(
onPressed: () {
Expand All @@ -59,9 +59,9 @@ class MyHomePage extends StatelessWidget {

class BigCard extends StatelessWidget {
const BigCard({
Key? key,
super.key,
required this.pair,
}) : super(key: key);
});

final WordPair pair;

Expand Down
2 changes: 1 addition & 1 deletion namer/step_05_c_card_padding/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:namer_app/main.dart';
void main() {
testWidgets('App starts', (WidgetTester tester) async {
await tester.pumpWidget(const MyApp());
expect(find.text('A random idea:'), findsOneWidget);
expect(find.text('A random AWESOME idea:'), findsOneWidget);
});

testWidgets('Tapping button changes word pair', (WidgetTester tester) async {
Expand Down
8 changes: 4 additions & 4 deletions namer/step_05_d_theme/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MyHomePage extends StatelessWidget {
return Scaffold(
body: Column(
children: [
Text('A random idea:'),
Text('A random AWESOME idea:'),
BigCard(pair: pair),
ElevatedButton(
onPressed: () {
Expand All @@ -59,15 +59,15 @@ class MyHomePage extends StatelessWidget {

class BigCard extends StatelessWidget {
const BigCard({
Key? key,
super.key,
required this.pair,
}) : super(key: key);
});

final WordPair pair;

@override
Widget build(BuildContext context) {
var theme = Theme.of(context);
final theme = Theme.of(context);

return Card(
color: theme.colorScheme.primary,
Expand Down
2 changes: 1 addition & 1 deletion namer/step_05_d_theme/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:namer_app/main.dart';
void main() {
testWidgets('App starts', (WidgetTester tester) async {
await tester.pumpWidget(const MyApp());
expect(find.text('A random idea:'), findsOneWidget);
expect(find.text('A random AWESOME idea:'), findsOneWidget);
});

testWidgets('Tapping button changes word pair', (WidgetTester tester) async {
Expand Down
Loading

0 comments on commit 9429d30

Please sign in to comment.