Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
domesticmouse committed Nov 14, 2024
1 parent 347930e commit 4ea91ee
Show file tree
Hide file tree
Showing 525 changed files with 19,827 additions and 209 deletions.
263 changes: 54 additions & 209 deletions animations/codelab_rebuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -988,16 +988,26 @@ steps:
- name: Use PageRouteBuilder
path: quiz/lib/home_screen.dart
patch-u: |
--- b/animations/step_05/lib/home_screen.dart
+++ a/animations/step_05/lib/home_screen.dart
@@ -25,13 +25,13 @@ class HomeScreen extends StatelessWidget {
--- b/animations/step_05_a/lib/home_screen.dart
+++ a/animations/step_05_a/lib/home_screen.dart
@@ -24,14 +24,22 @@ class HomeScreen extends StatelessWidget {
// Show the question screen to start the game
Navigator.push(
context,
MaterialPageRoute(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return QuestionScreen();
+ builder: (context) {
+ PageRouteBuilder(
+ pageBuilder: (context, animation, secondaryAnimation) {
+ return const QuestionScreen();
+ },
+ transitionsBuilder: (
+ context,
+ animation,
+ secondaryAnimation,
+ child,
+ ) {
+ return FadeTransition(opacity: animation, child: child);
},
),
);
Expand All @@ -1007,215 +1017,50 @@ steps:
),
],
),
- name: Remove step_05_a
rmdir: step_05_a
- name: Copy step_05_a
copydir:
from: quiz
to: step_05_a
- name: Use package:animations FadeThroughTransition
path: quiz/lib/home_screen.dart
patch-u: |
- name: Configure Predictive Back on Android
path: quiz/lib/main.dart
patch-u: |
--- b/animations/step_05/lib/main.dart
+++ a/animations/step_05/lib/main.dart
@@ -1,3 +1,4 @@
+import 'package:animations/animations.dart';
import 'package:flutter/material.dart';
import 'home_screen.dart';
@@ -16,6 +17,15 @@ class MainApp extends StatelessWidget {
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
useMaterial3: true,
+ pageTransitionsTheme: PageTransitionsTheme(
+ builders: {
+ TargetPlatform.android: PredictiveBackPageTransitionsBuilder(),
+ TargetPlatform.iOS: FadeThroughPageTransitionsBuilder(),
+ TargetPlatform.macOS: FadeThroughPageTransitionsBuilder(),
+ TargetPlatform.windows: FadeThroughPageTransitionsBuilder(),
+ TargetPlatform.linux: FadeThroughPageTransitionsBuilder(),
+ },
+ ),
),
home: HomeScreen(),
);
- name: Remove step_05_b
rmdir: step_05_b
- name: Copy step_05_b
copydir:
from: quiz
to: step_05_b
- name: Change back to MaterialPageRoute
path: quiz/lib/home_screen.dart
patch-u: |
- name: Use FadeThroughTransition
path: quiz/lib/question_screen.dart
patch-u: |
--- b/animations/step_05/lib/question_screen.dart
+++ a/animations/step_05/lib/question_screen.dart
@@ -1,3 +1,4 @@
+import 'package:animations/animations.dart';
import 'package:flutter/material.dart';
import 'flip_effect.dart';
import 'scoreboard.dart';
@@ -14,6 +15,7 @@ class _QuestionScreenState extends State<QuestionScreen> {
late final QuizViewModel viewModel = QuizViewModel(
onGameOver: _handleGameOver,
);
+ VoidCallback? _showGameOverScreen;
@override
Widget build(BuildContext context) {
@@ -37,7 +39,11 @@ class _QuestionScreenState extends State<QuestionScreen> {
body: Center(
child: Column(
children: [
- QuestionCard(question: viewModel.currentQuestion?.question),
+ QuestionCard(
+ onChangeOpenContainer: _handleChangeOpenContainer,
+ question: viewModel.currentQuestion?.question,
+ viewModel: viewModel,
+ ),
Spacer(),
AnswerCards(
onTapped: (index) {
@@ -58,24 +64,49 @@ class _QuestionScreenState extends State<QuestionScreen> {
);
}
+ void _handleChangeOpenContainer(VoidCallback openContainer) {
+ _showGameOverScreen = openContainer;
+ }
+
void _handleGameOver() {
- showDialog(
- barrierDismissible: false,
- context: context,
- builder: (context) {
- return AlertDialog(
- title: Text('Game Over!'),
- content: Text('Score: ${viewModel.score}'),
- actions: [
- TextButton(
+ if (_showGameOverScreen != null) {
+ _showGameOverScreen!();
+ }
+ }
+}
+
+class GameOverScreen extends StatelessWidget {
+ final QuizViewModel viewModel;
+ const GameOverScreen({required this.viewModel, super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ appBar: AppBar(automaticallyImplyLeading: false),
+ body: Center(
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ Scoreboard(
+ score: viewModel.score,
+ totalQuestions: viewModel.totalQuestions,
+ ),
+ Text('You Win!', style: Theme.of(context).textTheme.displayLarge),
+ Text(
+ 'Score: ${viewModel.score} / ${viewModel.totalQuestions}',
+ style: Theme.of(context).textTheme.displaySmall,
+ ),
+ ElevatedButton(
+ child: Text('OK'),
onPressed: () {
- Navigator.popUntil(context, (route) => route.isFirst);
+ Navigator.pop(context);
+ // Navigator.popUntil(
+ // context, (route) => route.isFirst);
},
- child: Text('OK'),
),
],
- );
- },
+ ),
+ ),
);
}
}
@@ -83,45 +114,53 @@ class _QuestionScreenState extends State<QuestionScreen> {
class QuestionCard extends StatelessWidget {
final String? question;
- const QuestionCard({required this.question, super.key});
+ const QuestionCard({
+ required this.onChangeOpenContainer,
+ required this.question,
+ required this.viewModel,
+ super.key,
+ });
+
+ final ValueChanged<VoidCallback> onChangeOpenContainer;
+ final QuizViewModel viewModel;
+
+ static const _backgroundColor = Color(0xfff2f3fa);
@override
Widget build(BuildContext context) {
- return AnimatedSwitcher(
- layoutBuilder: (Widget? currentChild, List<Widget> previousChildren) {
- return Stack(
- alignment: Alignment.topCenter,
- children: <Widget>[
- ...previousChildren,
- if (currentChild != null) currentChild,
- ],
- );
- },
- transitionBuilder: (Widget child, Animation<double> animation) {
- final curveAnimation = CurveTween(
- curve: Curves.easeInCubic,
- ).animate(animation);
- final offsetAnimation = Tween<Offset>(
- begin: Offset(-0.1, 0.0),
- end: Offset.zero,
- ).animate(curveAnimation);
- final fadeInAnimation = curveAnimation;
- return FadeTransition(
- opacity: fadeInAnimation,
- child: SlideTransition(position: offsetAnimation, child: child),
+ return PageTransitionSwitcher(
+ duration: const Duration(milliseconds: 200),
+ transitionBuilder: (Widget child, animation, secondaryAnimation) {
+ return FadeThroughTransition(
+ animation: animation,
+ secondaryAnimation: secondaryAnimation,
+ child: child,
);
},
- duration: const Duration(milliseconds: 300),
- child: Card(
+ child: OpenContainer(
key: ValueKey(question),
- elevation: 4,
- child: Padding(
- padding: const EdgeInsets.all(16.0),
- child: Text(
- question ?? "",
- style: Theme.of(context).textTheme.displaySmall,
- ),
+ tappable: false,
+ closedColor: _backgroundColor,
+ closedShape: const RoundedRectangleBorder(
+ borderRadius: BorderRadius.all(Radius.circular(12.0)),
),
+ closedElevation: 4,
+ closedBuilder: (context, openContainer) {
+ onChangeOpenContainer(openContainer);
+ return ColoredBox(
+ color: _backgroundColor,
+ child: Padding(
+ padding: const EdgeInsets.all(16.0),
+ child: Text(
+ question ?? "",
+ style: Theme.of(context).textTheme.displaySmall,
+ ),
+ ),
+ );
+ },
+ openBuilder: (context, closeContainer) {
+ return GameOverScreen(viewModel: viewModel);
+ },
),
);
}
- name: dart analyze
path: quiz
dart: analyze --fatal-infos
- name: Remove step_05_c
rmdir: step_05_c
- name: Copy step_05_c
copydir:
from: quiz
to: step_05_c
- name: Use OpenContainer
path: quiz/lib/question_screen.dart
patch-u: |
- name: Remove step_05_d
rmdir: step_05_d
- name: Copy step_05_d
copydir:
from: quiz
to: step_05_d
- name: Build Android app
platforms: [ macos ]
path: quiz
Expand Down Expand Up @@ -1246,4 +1091,4 @@ steps:
from: quiz
to: step_05
- name: Cleanup
rmdir: quiz
rmdir: quiz
45 changes: 45 additions & 0 deletions animations/step_05_a/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.build/
.buildlog/
.history
.svn/
.swiftpm/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.pub-cache/
.pub/
/build/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
13 changes: 13 additions & 0 deletions animations/step_05_a/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
include: package:flutter_lints/flutter.yaml

analyzer:
errors:
unused_field: ignore

linter:
rules:
annotate_overrides: false
prefer_const_constructors: false
prefer_const_constructors_in_immutables: false
prefer_const_declarations: false
prefer_const_literals_to_create_immutables: false
13 changes: 13 additions & 0 deletions animations/step_05_a/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
gradle-wrapper.jar
/.gradle
/captures/
/gradlew
/gradlew.bat
/local.properties
GeneratedPluginRegistrant.java

# Remember to never publicly share your keystore.
# See https://flutter.dev/to/reference-keystore
key.properties
**/*.keystore
**/*.jks
Loading

0 comments on commit 4ea91ee

Please sign in to comment.