From 578a461075af717d7eebf431c16aee2cdc164002 Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Mon, 15 May 2023 09:55:49 -0600 Subject: [PATCH] added rotating icon to splash loading --- lib/pages/animated_widgets/rotate_icon.dart | 12 +++--- lib/pages/splash_screen/splash_screen.dart | 45 ++++++++++++++------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/lib/pages/animated_widgets/rotate_icon.dart b/lib/pages/animated_widgets/rotate_icon.dart index d93f6b3..832cf54 100644 --- a/lib/pages/animated_widgets/rotate_icon.dart +++ b/lib/pages/animated_widgets/rotate_icon.dart @@ -1,8 +1,8 @@ import 'package:flutter/widgets.dart'; class RotateIconController { - VoidCallback? forward; - VoidCallback? reverse; + // VoidCallback? forward; + VoidCallback? repeat; VoidCallback? reset; } @@ -51,8 +51,8 @@ class _RotateIconState extends State ), ); - widget.controller?.forward = animationController.forward; - widget.controller?.reverse = animationController.reverse; + // widget.controller?.forward = animationController.forward; + widget.controller?.repeat = animationController.repeat; widget.controller?.reset = animationController.reset; super.initState(); @@ -61,8 +61,8 @@ class _RotateIconState extends State @override void dispose() { animationController.dispose(); - widget.controller?.forward = null; - widget.controller?.reverse = null; + // widget.controller?.forward = null; + widget.controller?.repeat = null; super.dispose(); } diff --git a/lib/pages/splash_screen/splash_screen.dart b/lib/pages/splash_screen/splash_screen.dart index 43fa189..9248b5f 100644 --- a/lib/pages/splash_screen/splash_screen.dart +++ b/lib/pages/splash_screen/splash_screen.dart @@ -1,7 +1,6 @@ -import 'dart:io'; - +import 'package:drifter/pages/animated_widgets/rotate_icon.dart'; +import 'package:drifter/pages/main_screen/main_screen_widget.dart'; import 'package:drifter/theme/app_colors.dart'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; @@ -15,18 +14,33 @@ class Splash extends StatefulWidget { } class _SplashState extends State { + late final RotateIconController _rotateIconController; + @override void initState() { - super.initState(); + _rotateIconController = RotateIconController(); + Future.delayed(const Duration(seconds: 3), () { Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => const MainScreenWidget())); }); + + super.initState(); + } + + @override + dispose() { + _rotateIconController.repeat = null; + _rotateIconController.reset = null; + + super.dispose(); } @override Widget build(BuildContext context) { - var isAndroid; + _rotateIconController.reset?.call(); + _rotateIconController.repeat?.call(); + return Scaffold( backgroundColor: AppColors.background, body: Center( @@ -53,17 +67,20 @@ class _SplashState extends State { ), ), const SizedBox( - height: 250, + height: 230, ), //replace with rotating drifter icon - if (Platform.isAndroid) - const CircularProgressIndicator( - color: AppColors.mainAccent, - ) - else - const CupertinoActivityIndicator( - radius: 20, - ) + RotateIcon( + icon: SvgPicture.asset( + Assets.svg.drifterIcon, + height: 45, + width: 45, + ), + curve: Curves.easeInOutSine, + animationDurationMultiplier: 1.2, + rotationPercent: 1.0, + controller: _rotateIconController, + ), ], ), ),