Created with <3 with dartpad.dev.
Last active
May 16, 2023 18:14
-
-
Save plotsklapps/7d1feeb9713826ef7152a60d47627b2b to your computer and use it in GitHub Desktop.
Flutter Architecture #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| // MAIN | |
| void main() { | |
| runApp( | |
| MaterialApp( | |
| debugShowCheckedModeBanner: false, | |
| home: SplashPage(), | |
| ), | |
| ); | |
| } | |
| // PAGES | |
| class SplashPage extends StatefulWidget { | |
| @override | |
| SplashPageState createState() { | |
| return SplashPageState(); | |
| } | |
| } | |
| class SplashPageState extends State<SplashPage> | |
| with SingleTickerProviderStateMixin { | |
| // The SingleTickerProviderStateMixin mixin will provide this class | |
| // with the Ticker instance it needs; an AnimationController needs a | |
| // TickerProvider — the AnimationController constructor takes a required | |
| // parameter vsync that must implement a TickerProvider interface, | |
| // therefore we are implementing SingleTickerProviderStateMixin on this | |
| // class so it serves as the AnimationController's ticker provider. | |
| AnimationController? donutController; | |
| Animation<double>? rotationAnimation; | |
| @override | |
| void initState() { | |
| super.initState(); | |
| // vsync: the instance of the Ticker provider; in this case, the | |
| // existing instance (this) since we are implementing the | |
| // SingleTickerProviderStateMixin. Follow the instantiation by quickly | |
| // executing its repeat method by using the spread operator | |
| // (the two dots right after the instance; i.e. ..repeat()). | |
| // What this does is allow the animation to repeat in an infinite loop. | |
| donutController = | |
| AnimationController(duration: const Duration(seconds: 5), vsync: this) | |
| ..repeat(); | |
| rotationAnimation = Tween<double>( | |
| begin: 0, | |
| end: 1, | |
| ).animate( | |
| CurvedAnimation( | |
| parent: donutController!, | |
| curve: Curves.linear, | |
| ), | |
| ); | |
| } | |
| @override | |
| void dispose() { | |
| donutController!.dispose(); | |
| super.dispose(); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| // Future.delayed takes two parameters: a Duration object | |
| // with it's seconds property set to 2, and a callback. | |
| // When the 2 seconds have ellapsed, it will call the callback. | |
| Future.delayed(const Duration(seconds: 2), () { | |
| Navigator.of(context) | |
| .pushReplacement(MaterialPageRoute(builder: (context) { | |
| return DonutShopMain(); | |
| })); | |
| }); | |
| return Scaffold( | |
| backgroundColor: Utils.mainColor, | |
| body: Center( | |
| child: Column( | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| children: [ | |
| RotationTransition( | |
| turns: rotationAnimation!, | |
| child: Image.network( | |
| Utils.donutLogoWhiteNoText, | |
| width: 100, | |
| height: 100, | |
| ), | |
| ), | |
| Image.network( | |
| Utils.donutLogoWhiteText, | |
| width: 150, | |
| height: 150, | |
| ), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| class DonutShopMain extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return const Scaffold( | |
| body: Center( | |
| child: Text( | |
| 'Hello, Shay-Ann\'s Donut Shop!', | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| // UTILS | |
| class Utils { | |
| static const Color mainColor = Color(0xFFFF0F7E); | |
| static const Color mainDark = Color(0xFF980346); | |
| static const String donutLogoWhiteNoText = | |
| 'https://romanejaquez.github.io/flutter-codelab4/assets/donut_shop_logowhite_notext.png'; | |
| static const String donutLogoWhiteText = | |
| 'https://romanejaquez.github.io/flutter-codelab4/assets/donut_shop_text_reversed.png'; | |
| static const String donutLogoRedText = | |
| 'https://romanejaquez.github.io/flutter-codelab4/assets/donut_shop_text.png'; | |
| static const String donutTitleFavorites = | |
| 'https://romanejaquez.github.io/flutter-codelab4/assets/donut_favorites_title.png'; | |
| static const String donutTitleMyDonuts = | |
| 'https://romanejaquez.github.io/flutter-codelab4/assets/donut_mydonuts_title.png'; | |
| static const String donutPromo1 = | |
| 'https://romanejaquez.github.io/flutter-codelab4/assets/donut_promo1.png'; | |
| static const String donutPromo2 = | |
| 'https://romanejaquez.github.io/flutter-codelab4/assets/donut_promo2.png'; | |
| static const String donutPromo3 = | |
| 'https://romanejaquez.github.io/flutter-codelab4/assets/donut_promo3.png'; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Started over 15-05-2023 to refresh.