Skip to content

Commit 4ea91ee

Browse files
committed
wip
1 parent 347930e commit 4ea91ee

File tree

525 files changed

+19827
-209
lines changed

Some content is hidden

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

525 files changed

+19827
-209
lines changed

animations/codelab_rebuild.yaml

Lines changed: 54 additions & 209 deletions
Original file line numberDiff line numberDiff line change
@@ -988,16 +988,26 @@ steps:
988988
- name: Use PageRouteBuilder
989989
path: quiz/lib/home_screen.dart
990990
patch-u: |
991-
--- b/animations/step_05/lib/home_screen.dart
992-
+++ a/animations/step_05/lib/home_screen.dart
993-
@@ -25,13 +25,13 @@ class HomeScreen extends StatelessWidget {
991+
--- b/animations/step_05_a/lib/home_screen.dart
992+
+++ a/animations/step_05_a/lib/home_screen.dart
993+
@@ -24,14 +24,22 @@ class HomeScreen extends StatelessWidget {
994+
// Show the question screen to start the game
994995
Navigator.push(
995996
context,
996-
MaterialPageRoute(
997+
- MaterialPageRoute(
997998
- builder: (BuildContext context) {
998999
- return QuestionScreen();
999-
+ builder: (context) {
1000+
+ PageRouteBuilder(
1001+
+ pageBuilder: (context, animation, secondaryAnimation) {
10001002
+ return const QuestionScreen();
1003+
+ },
1004+
+ transitionsBuilder: (
1005+
+ context,
1006+
+ animation,
1007+
+ secondaryAnimation,
1008+
+ child,
1009+
+ ) {
1010+
+ return FadeTransition(opacity: animation, child: child);
10011011
},
10021012
),
10031013
);
@@ -1007,215 +1017,50 @@ steps:
10071017
),
10081018
],
10091019
),
1020+
- name: Remove step_05_a
1021+
rmdir: step_05_a
1022+
- name: Copy step_05_a
1023+
copydir:
1024+
from: quiz
1025+
to: step_05_a
1026+
- name: Use package:animations FadeThroughTransition
1027+
path: quiz/lib/home_screen.dart
1028+
patch-u: |
1029+
10101030
- name: Configure Predictive Back on Android
10111031
path: quiz/lib/main.dart
10121032
patch-u: |
1013-
--- b/animations/step_05/lib/main.dart
1014-
+++ a/animations/step_05/lib/main.dart
1015-
@@ -1,3 +1,4 @@
1016-
+import 'package:animations/animations.dart';
1017-
import 'package:flutter/material.dart';
1018-
1019-
import 'home_screen.dart';
1020-
@@ -16,6 +17,15 @@ class MainApp extends StatelessWidget {
1021-
theme: ThemeData(
1022-
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
1023-
useMaterial3: true,
1024-
+ pageTransitionsTheme: PageTransitionsTheme(
1025-
+ builders: {
1026-
+ TargetPlatform.android: PredictiveBackPageTransitionsBuilder(),
1027-
+ TargetPlatform.iOS: FadeThroughPageTransitionsBuilder(),
1028-
+ TargetPlatform.macOS: FadeThroughPageTransitionsBuilder(),
1029-
+ TargetPlatform.windows: FadeThroughPageTransitionsBuilder(),
1030-
+ TargetPlatform.linux: FadeThroughPageTransitionsBuilder(),
1031-
+ },
1032-
+ ),
1033-
),
1034-
home: HomeScreen(),
1035-
);
1033+
1034+
- name: Remove step_05_b
1035+
rmdir: step_05_b
1036+
- name: Copy step_05_b
1037+
copydir:
1038+
from: quiz
1039+
to: step_05_b
1040+
- name: Change back to MaterialPageRoute
1041+
path: quiz/lib/home_screen.dart
1042+
patch-u: |
1043+
10361044
- name: Use FadeThroughTransition
10371045
path: quiz/lib/question_screen.dart
10381046
patch-u: |
1039-
--- b/animations/step_05/lib/question_screen.dart
1040-
+++ a/animations/step_05/lib/question_screen.dart
1041-
@@ -1,3 +1,4 @@
1042-
+import 'package:animations/animations.dart';
1043-
import 'package:flutter/material.dart';
1044-
import 'flip_effect.dart';
1045-
import 'scoreboard.dart';
1046-
@@ -14,6 +15,7 @@ class _QuestionScreenState extends State<QuestionScreen> {
1047-
late final QuizViewModel viewModel = QuizViewModel(
1048-
onGameOver: _handleGameOver,
1049-
);
1050-
+ VoidCallback? _showGameOverScreen;
1051-
1052-
@override
1053-
Widget build(BuildContext context) {
1054-
@@ -37,7 +39,11 @@ class _QuestionScreenState extends State<QuestionScreen> {
1055-
body: Center(
1056-
child: Column(
1057-
children: [
1058-
- QuestionCard(question: viewModel.currentQuestion?.question),
1059-
+ QuestionCard(
1060-
+ onChangeOpenContainer: _handleChangeOpenContainer,
1061-
+ question: viewModel.currentQuestion?.question,
1062-
+ viewModel: viewModel,
1063-
+ ),
1064-
Spacer(),
1065-
AnswerCards(
1066-
onTapped: (index) {
1067-
@@ -58,24 +64,49 @@ class _QuestionScreenState extends State<QuestionScreen> {
1068-
);
1069-
}
1070-
1071-
+ void _handleChangeOpenContainer(VoidCallback openContainer) {
1072-
+ _showGameOverScreen = openContainer;
1073-
+ }
1074-
+
1075-
void _handleGameOver() {
1076-
- showDialog(
1077-
- barrierDismissible: false,
1078-
- context: context,
1079-
- builder: (context) {
1080-
- return AlertDialog(
1081-
- title: Text('Game Over!'),
1082-
- content: Text('Score: ${viewModel.score}'),
1083-
- actions: [
1084-
- TextButton(
1085-
+ if (_showGameOverScreen != null) {
1086-
+ _showGameOverScreen!();
1087-
+ }
1088-
+ }
1089-
+}
1090-
+
1091-
+class GameOverScreen extends StatelessWidget {
1092-
+ final QuizViewModel viewModel;
1093-
+ const GameOverScreen({required this.viewModel, super.key});
1094-
+
1095-
+ @override
1096-
+ Widget build(BuildContext context) {
1097-
+ return Scaffold(
1098-
+ appBar: AppBar(automaticallyImplyLeading: false),
1099-
+ body: Center(
1100-
+ child: Column(
1101-
+ mainAxisAlignment: MainAxisAlignment.center,
1102-
+ children: [
1103-
+ Scoreboard(
1104-
+ score: viewModel.score,
1105-
+ totalQuestions: viewModel.totalQuestions,
1106-
+ ),
1107-
+ Text('You Win!', style: Theme.of(context).textTheme.displayLarge),
1108-
+ Text(
1109-
+ 'Score: ${viewModel.score} / ${viewModel.totalQuestions}',
1110-
+ style: Theme.of(context).textTheme.displaySmall,
1111-
+ ),
1112-
+ ElevatedButton(
1113-
+ child: Text('OK'),
1114-
onPressed: () {
1115-
- Navigator.popUntil(context, (route) => route.isFirst);
1116-
+ Navigator.pop(context);
1117-
+ // Navigator.popUntil(
1118-
+ // context, (route) => route.isFirst);
1119-
},
1120-
- child: Text('OK'),
1121-
),
1122-
],
1123-
- );
1124-
- },
1125-
+ ),
1126-
+ ),
1127-
);
1128-
}
1129-
}
1130-
@@ -83,45 +114,53 @@ class _QuestionScreenState extends State<QuestionScreen> {
1131-
class QuestionCard extends StatelessWidget {
1132-
final String? question;
1133-
1134-
- const QuestionCard({required this.question, super.key});
1135-
+ const QuestionCard({
1136-
+ required this.onChangeOpenContainer,
1137-
+ required this.question,
1138-
+ required this.viewModel,
1139-
+ super.key,
1140-
+ });
1141-
+
1142-
+ final ValueChanged<VoidCallback> onChangeOpenContainer;
1143-
+ final QuizViewModel viewModel;
1144-
+
1145-
+ static const _backgroundColor = Color(0xfff2f3fa);
1146-
1147-
@override
1148-
Widget build(BuildContext context) {
1149-
- return AnimatedSwitcher(
1150-
- layoutBuilder: (Widget? currentChild, List<Widget> previousChildren) {
1151-
- return Stack(
1152-
- alignment: Alignment.topCenter,
1153-
- children: <Widget>[
1154-
- ...previousChildren,
1155-
- if (currentChild != null) currentChild,
1156-
- ],
1157-
- );
1158-
- },
1159-
- transitionBuilder: (Widget child, Animation<double> animation) {
1160-
- final curveAnimation = CurveTween(
1161-
- curve: Curves.easeInCubic,
1162-
- ).animate(animation);
1163-
- final offsetAnimation = Tween<Offset>(
1164-
- begin: Offset(-0.1, 0.0),
1165-
- end: Offset.zero,
1166-
- ).animate(curveAnimation);
1167-
- final fadeInAnimation = curveAnimation;
1168-
- return FadeTransition(
1169-
- opacity: fadeInAnimation,
1170-
- child: SlideTransition(position: offsetAnimation, child: child),
1171-
+ return PageTransitionSwitcher(
1172-
+ duration: const Duration(milliseconds: 200),
1173-
+ transitionBuilder: (Widget child, animation, secondaryAnimation) {
1174-
+ return FadeThroughTransition(
1175-
+ animation: animation,
1176-
+ secondaryAnimation: secondaryAnimation,
1177-
+ child: child,
1178-
);
1179-
},
1180-
- duration: const Duration(milliseconds: 300),
1181-
- child: Card(
1182-
+ child: OpenContainer(
1183-
key: ValueKey(question),
1184-
- elevation: 4,
1185-
- child: Padding(
1186-
- padding: const EdgeInsets.all(16.0),
1187-
- child: Text(
1188-
- question ?? "",
1189-
- style: Theme.of(context).textTheme.displaySmall,
1190-
- ),
1191-
+ tappable: false,
1192-
+ closedColor: _backgroundColor,
1193-
+ closedShape: const RoundedRectangleBorder(
1194-
+ borderRadius: BorderRadius.all(Radius.circular(12.0)),
1195-
),
1196-
+ closedElevation: 4,
1197-
+ closedBuilder: (context, openContainer) {
1198-
+ onChangeOpenContainer(openContainer);
1199-
+ return ColoredBox(
1200-
+ color: _backgroundColor,
1201-
+ child: Padding(
1202-
+ padding: const EdgeInsets.all(16.0),
1203-
+ child: Text(
1204-
+ question ?? "",
1205-
+ style: Theme.of(context).textTheme.displaySmall,
1206-
+ ),
1207-
+ ),
1208-
+ );
1209-
+ },
1210-
+ openBuilder: (context, closeContainer) {
1211-
+ return GameOverScreen(viewModel: viewModel);
1212-
+ },
1213-
),
1214-
);
1215-
}
1216-
- name: dart analyze
1217-
path: quiz
1218-
dart: analyze --fatal-infos
1047+
1048+
- name: Remove step_05_c
1049+
rmdir: step_05_c
1050+
- name: Copy step_05_c
1051+
copydir:
1052+
from: quiz
1053+
to: step_05_c
1054+
- name: Use OpenContainer
1055+
path: quiz/lib/question_screen.dart
1056+
patch-u: |
1057+
1058+
- name: Remove step_05_d
1059+
rmdir: step_05_d
1060+
- name: Copy step_05_d
1061+
copydir:
1062+
from: quiz
1063+
to: step_05_d
12191064
- name: Build Android app
12201065
platforms: [ macos ]
12211066
path: quiz
@@ -1246,4 +1091,4 @@ steps:
12461091
from: quiz
12471092
to: step_05
12481093
- name: Cleanup
1249-
rmdir: quiz
1094+
rmdir: quiz

animations/step_05_a/.gitignore

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.build/
9+
.buildlog/
10+
.history
11+
.svn/
12+
.swiftpm/
13+
migrate_working_dir/
14+
15+
# IntelliJ related
16+
*.iml
17+
*.ipr
18+
*.iws
19+
.idea/
20+
21+
# The .vscode folder contains launch configuration and tasks you configure in
22+
# VS Code which you may wish to be included in version control, so this line
23+
# is commented out by default.
24+
#.vscode/
25+
26+
# Flutter/Dart/Pub related
27+
**/doc/api/
28+
**/ios/Flutter/.last_build_id
29+
.dart_tool/
30+
.flutter-plugins
31+
.flutter-plugins-dependencies
32+
.pub-cache/
33+
.pub/
34+
/build/
35+
36+
# Symbolication related
37+
app.*.symbols
38+
39+
# Obfuscation related
40+
app.*.map.json
41+
42+
# Android Studio will place build artifacts here
43+
/android/app/debug
44+
/android/app/profile
45+
/android/app/release
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
analyzer:
4+
errors:
5+
unused_field: ignore
6+
7+
linter:
8+
rules:
9+
annotate_overrides: false
10+
prefer_const_constructors: false
11+
prefer_const_constructors_in_immutables: false
12+
prefer_const_declarations: false
13+
prefer_const_literals_to_create_immutables: false
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
gradle-wrapper.jar
2+
/.gradle
3+
/captures/
4+
/gradlew
5+
/gradlew.bat
6+
/local.properties
7+
GeneratedPluginRegistrant.java
8+
9+
# Remember to never publicly share your keystore.
10+
# See https://flutter.dev/to/reference-keystore
11+
key.properties
12+
**/*.keystore
13+
**/*.jks

0 commit comments

Comments
 (0)