Skip to content

Commit 8bfb6ca

Browse files
committed
Simplify animations rebuild
1 parent 68880ee commit 8bfb6ca

File tree

19 files changed

+142
-170
lines changed

19 files changed

+142
-170
lines changed

animations/codelab_rebuild.yaml

Lines changed: 52 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,20 @@ steps:
1111
path: quiz/ios/Runner.xcodeproj/project.pbxproj
1212
- name: Remove README
1313
rm: quiz/README.md
14-
- name: Replace pubspec.yaml
14+
- name: Add deps
15+
path: quiz
16+
flutter: pub add animations
17+
- name: Patch pubspec.yaml
1518
path: quiz/pubspec.yaml
16-
replace-contents: |
17-
name: quiz
18-
description: A quiz app for demonstrating animation effects in Flutter
19-
publish_to: "none"
20-
version: 1.0.0
21-
22-
environment:
23-
sdk: ^3.8.0-0
24-
25-
dependencies:
26-
animations: ^2.0.0
27-
flutter:
28-
sdk: flutter
29-
30-
dev_dependencies:
31-
flutter_test:
32-
sdk: flutter
33-
flutter_lints: ^4.0.0
34-
35-
36-
flutter:
37-
uses-material-design: true
19+
patch-u: |
20+
--- b/animations/step_01/pubspec.yaml
21+
+++ a/animations/step_01/pubspec.yaml
22+
@@ -1,5 +1,5 @@
23+
name: quiz
24+
-description: "A new Flutter project."
25+
+description: "A quiz app for demonstrating animation effects in Flutter."
26+
publish_to: 'none'
27+
version: 0.1.0
3828
- name: Replace analysis_options.yaml
3929
path: quiz/analysis_options.yaml
4030
replace-contents: |
@@ -99,16 +89,16 @@ steps:
9989
path: quiz/lib/main.dart
10090
replace-contents: |
10191
import 'package:flutter/material.dart';
102-
92+
10393
import 'home_screen.dart';
104-
94+
10595
void main() {
10696
runApp(MainApp());
10797
}
108-
98+
10999
class MainApp extends StatelessWidget {
110100
const MainApp({super.key});
111-
101+
112102
@override
113103
Widget build(BuildContext context) {
114104
return MaterialApp(
@@ -180,7 +170,7 @@ steps:
180170
replace-contents: |
181171
import 'package:flutter/cupertino.dart';
182172
import 'model.dart';
183-
173+
184174
class QuizViewModel extends ChangeNotifier {
185175
final QuestionBank _questionBank = QuestionBank();
186176
final VoidCallback onGameOver;
@@ -190,34 +180,34 @@ steps:
190180
int score = 0;
191181
bool didAnswerQuestion = false;
192182
bool get hasNextQuestion => answeredQuestionCount < totalQuestions;
193-
183+
194184
QuizViewModel({required this.onGameOver}) {
195185
totalQuestions = _questionBank.remainingQuestions;
196186
getNextQuestion();
197187
}
198-
188+
199189
void getNextQuestion() {
200190
if (_questionBank.hasNextQuestion) {
201191
currentQuestion = _questionBank.getRandomQuestion();
202192
answeredQuestionCount++;
203193
}
204-
194+
205195
didAnswerQuestion = false;
206-
196+
207197
notifyListeners();
208198
}
209-
199+
210200
void checkAnswer(int selectedIndex) {
211201
if (!didAnswerQuestion && currentQuestion?.correctAnswer == selectedIndex) {
212202
score++;
213203
}
214-
204+
215205
didAnswerQuestion = true;
216-
206+
217207
if (!_questionBank.hasNextQuestion) {
218208
onGameOver();
219209
}
220-
210+
221211
notifyListeners();
222212
}
223213
}
@@ -464,7 +454,7 @@ steps:
464454
import 'package:flutter/material.dart';
465455
+import 'scoreboard.dart';
466456
import 'view_model.dart';
467-
457+
468458
class QuestionScreen extends StatefulWidget {
469459
@@ -159,13 +160,9 @@ class StatusBar extends StatelessWidget {
470460
child: Row(
@@ -589,9 +579,9 @@ steps:
589579
final Color _deactivatedColor = Colors.grey.shade400;
590580
final Color _activatedColor = Colors.yellow.shade700;
591581
+ final Curve _curve = Curves.elasticOut;
592-
582+
593583
AnimatedStar({super.key, required this.isActive});
594-
584+
595585
@@ -37,8 +38,10 @@ class AnimatedStar extends StatelessWidget {
596586
Widget build(BuildContext context) {
597587
return AnimatedScale(
@@ -618,7 +608,7 @@ steps:
618608
--- b/animations/step_03_a/lib/question_screen.dart
619609
+++ a/animations/step_03_a/lib/question_screen.dart
620610
@@ -85,13 +85,17 @@ class QuestionCard extends StatelessWidget {
621-
611+
622612
@override
623613
Widget build(BuildContext context) {
624614
- return Card(
@@ -703,7 +693,7 @@ steps:
703693
- name: Copy step_03_c
704694
copydir:
705695
from: quiz
706-
to: step_03_c
696+
to: step_03_c
707697

708698
- name: step_03_d
709699
steps:
@@ -825,7 +815,7 @@ steps:
825815
+import 'flip_effect.dart';
826816
import 'scoreboard.dart';
827817
import 'view_model.dart';
828-
818+
829819
@@ -148,21 +149,24 @@ class AnswerCards extends StatelessWidget {
830820
if (correctAnswer == index) {
831821
color = Theme.of(context).colorScheme.tertiaryContainer;
@@ -885,14 +875,14 @@ steps:
885875
final Widget child;
886876
final Duration duration;
887877
+ final double delayAmount;
888-
878+
889879
const CardFlipEffect({
890880
super.key,
891881
required this.child,
892882
required this.duration,
893883
+ required this.delayAmount,
894884
});
895-
885+
896886
@override
897887
- name: Patch lib/question_screen.dart
898888
path: quiz/lib/question_screen.dart
@@ -926,17 +916,17 @@ steps:
926916
late final AnimationController _animationController;
927917
Widget? _previousChild;
928918
+ late final Animation<double> _animationWithDelay;
929-
919+
930920
@override
931921
void initState() {
932922
@@ -29,7 +30,7 @@ class _CardFlipEffectState extends State<CardFlipEffect>
933-
923+
934924
_animationController = AnimationController(
935925
vsync: this,
936926
- duration: widget.duration,
937927
+ duration: widget.duration * (widget.delayAmount + 1),
938928
);
939-
929+
940930
_animationController.addListener(() {
941931
@@ -37,6 +38,15 @@ class _CardFlipEffectState extends State<CardFlipEffect>
942932
_animationController.reset();
@@ -952,7 +942,7 @@ steps:
952942
+ TweenSequenceItem(tween: Tween(begin: 0.0, end: 1.0), weight: 1.0),
953943
+ ]).animate(_animationController);
954944
}
955-
945+
956946
@override
957947
- name: Copy step_04_c
958948
copydir:
@@ -1039,7 +1029,7 @@ steps:
10391029
+import 'package:animations/animations.dart';
10401030
import 'package:flutter/material.dart';
10411031
import 'question_screen.dart';
1042-
1032+
10431033
@@ -30,8 +31,9 @@ class HomeScreen extends StatelessWidget {
10441034
},
10451035
transitionsBuilder:
@@ -1060,7 +1050,7 @@ steps:
10601050
@@ -1,3 +1,4 @@
10611051
+import 'package:animations/animations.dart';
10621052
import 'package:flutter/material.dart';
1063-
1053+
10641054
import 'home_screen.dart';
10651055
@@ -15,6 +16,15 @@ class MainApp extends StatelessWidget {
10661056
debugShowCheckedModeBanner: false,
@@ -1096,7 +1086,7 @@ steps:
10961086
-import 'package:animations/animations.dart';
10971087
import 'package:flutter/material.dart';
10981088
import 'question_screen.dart';
1099-
1089+
11001090
@@ -25,18 +24,10 @@ class HomeScreen extends StatelessWidget {
11011091
// Show the question screen to start the game
11021092
Navigator.push(
@@ -1129,7 +1119,7 @@ steps:
11291119
import 'flip_effect.dart';
11301120
import 'scoreboard.dart';
11311121
@@ -86,28 +87,15 @@ class QuestionCard extends StatelessWidget {
1132-
1122+
11331123
@override
11341124
Widget build(BuildContext context) {
11351125
- return AnimatedSwitcher(
@@ -1184,7 +1174,7 @@ steps:
11841174
onGameOver: _handleGameOver,
11851175
);
11861176
+ VoidCallback? _showGameOverScreen;
1187-
1177+
11881178
@override
11891179
Widget build(BuildContext context) {
11901180
@@ -38,7 +39,11 @@ class _QuestionScreenState extends State<QuestionScreen> {
@@ -1203,7 +1193,7 @@ steps:
12031193
@@ -58,24 +63,47 @@ class _QuestionScreenState extends State<QuestionScreen> {
12041194
);
12051195
}
1206-
1196+
12071197
+ void _handleChangeOpenContainer(VoidCallback openContainer) {
12081198
+ _showGameOverScreen = openContainer;
12091199
+ }
@@ -1263,7 +1253,7 @@ steps:
12631253
@@ -83,14 +111,22 @@ class _QuestionScreenState extends State<QuestionScreen> {
12641254
class QuestionCard extends StatelessWidget {
12651255
final String? question;
1266-
1256+
12671257
- const QuestionCard({required this.question, super.key});
12681258
+ const QuestionCard({
12691259
+ required this.onChangeOpenContainer,
@@ -1276,7 +1266,7 @@ steps:
12761266
+ final QuizViewModel viewModel;
12771267
+
12781268
+ static const _backgroundColor = Color(0xfff2f3fa);
1279-
1269+
12801270
@override
12811271
Widget build(BuildContext context) {
12821272
return PageTransitionSwitcher(
@@ -1335,28 +1325,28 @@ steps:
13351325
path: quiz
13361326
dart: analyze --fatal-infos
13371327
- name: Build Android app
1338-
platforms: [ macos ]
1328+
platforms: [macos]
13391329
path: quiz
13401330
flutter: build apk
13411331
- name: Build iOS app
1342-
platforms: [ macos ]
1332+
platforms: [macos]
13431333
path: quiz
13441334
flutter: build ios --simulator
13451335
- name: Build macOS app
1346-
platforms: [ macos ]
1336+
platforms: [macos]
13471337
path: quiz
13481338
flutter: build macos
13491339
- name: Build Linux app
1350-
platforms: [ linux ]
1340+
platforms: [linux]
13511341
path: quiz
13521342
flutter: build linux
13531343
- name: Build Windows app
1354-
platforms: [ windows ]
1344+
platforms: [windows]
13551345
path: quiz
13561346
flutter: build windows
13571347
- name: Build Web app
13581348
path: quiz
13591349
flutter: build web
13601350

13611351
- name: Cleanup
1362-
rmdir: quiz
1352+
rmdir: quiz

animations/step_01/pubspec.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
name: quiz
2-
description: A quiz app for demonstrating animation effects in Flutter
3-
publish_to: "none"
4-
version: 1.0.0
2+
description: "A quiz app for demonstrating animation effects in Flutter."
3+
publish_to: 'none'
4+
version: 0.1.0
55

66
environment:
77
sdk: ^3.8.0-0
88

99
dependencies:
10-
animations: ^2.0.0
1110
flutter:
1211
sdk: flutter
12+
animations: ^2.0.11
1313

1414
dev_dependencies:
1515
flutter_test:
1616
sdk: flutter
17-
flutter_lints: ^4.0.0
18-
17+
flutter_lints: ^5.0.0
1918

2019
flutter:
2120
uses-material-design: true

animations/step_02_a/pubspec.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
name: quiz
2-
description: A quiz app for demonstrating animation effects in Flutter
3-
publish_to: "none"
4-
version: 1.0.0
2+
description: "A quiz app for demonstrating animation effects in Flutter."
3+
publish_to: 'none'
4+
version: 0.1.0
55

66
environment:
77
sdk: ^3.8.0-0
88

99
dependencies:
10-
animations: ^2.0.0
1110
flutter:
1211
sdk: flutter
12+
animations: ^2.0.11
1313

1414
dev_dependencies:
1515
flutter_test:
1616
sdk: flutter
17-
flutter_lints: ^4.0.0
18-
17+
flutter_lints: ^5.0.0
1918

2019
flutter:
2120
uses-material-design: true

0 commit comments

Comments
 (0)