From 7db470cf376b373dff890328221fbbb4c9c1a967 Mon Sep 17 00:00:00 2001 From: GreyLabsDev Date: Thu, 18 Jan 2024 00:41:55 +0300 Subject: [PATCH] base windget refactoring --- lib/main.dart | 4 +- lib/pages/TestPage.dart | 129 ------------------------------ lib/widgets/base/PageButton.dart | 131 +++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+), 131 deletions(-) create mode 100644 lib/widgets/base/PageButton.dart diff --git a/lib/main.dart b/lib/main.dart index 983f0e0..64d6e5c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'pages/MusicReleasesPage.dart'; +import 'package:threeactions_area/pages/TestPage.dart'; void main() { runApp(MyApp()); @@ -10,7 +10,7 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( title: 'Threeactions', - home: MusicReleasePage(), + home: TestPage(), ); } } diff --git a/lib/pages/TestPage.dart b/lib/pages/TestPage.dart index 02f551f..88d3d8a 100644 --- a/lib/pages/TestPage.dart +++ b/lib/pages/TestPage.dart @@ -3,7 +3,6 @@ import 'package:threeactions_area/widgets/base/TextContent.dart'; import 'package:threeactions_area/widgets/base/TextSubtitle.dart'; import 'package:threeactions_area/widgets/base/TextTitle.dart'; -import '../widgets/base/AnimatedLogo.dart'; import '../widgets/base/MainPageInfoButton.dart'; import '../widgets/base/SocialButton.dart'; import 'base/BaseInfoPage.dart'; @@ -202,132 +201,4 @@ class TestPageState extends State { ), ); } -} - -class PageButton extends StatefulWidget { - final int number; - final String title; - final String bgImageAsset; - final String logoBaseImageAsset; - final String logoMovingPartImageAssetTop; - final String logoMovingPartImageAssetBottom; - double logoPartsExtraPadding = 0.0; - - PageButton( - {Key? key, - required this.number, - required this.title, - required this.bgImageAsset, - required this.logoBaseImageAsset, - required this.logoMovingPartImageAssetTop, - required this.logoMovingPartImageAssetBottom, - this.logoPartsExtraPadding = 0.0}) - : super(key: key); - - @override - PageButtonState createState() { - return PageButtonState( - number, - title, - bgImageAsset, - logoBaseImageAsset, - logoMovingPartImageAssetTop, - logoMovingPartImageAssetBottom, - logoPartsExtraPadding); - } -} - -class PageButtonState extends State with SingleTickerProviderStateMixin { - late AnimationController controller; - late Animation opacityAcnimation; - final GlobalKey _logoStateKey = GlobalKey(); - - final int number; - final String title; - final String bgImageAsset; - final String logoBaseImageAsset; - final String logoMovingPartImageAssetTop; - final String logoMovingPartImageAssetBottom; - double logoPartsExtraPadding = 0.0; - - PageButtonState( - this.number, - this.title, - this.bgImageAsset, - this.logoBaseImageAsset, - this.logoMovingPartImageAssetTop, - this.logoMovingPartImageAssetBottom, - [this.logoPartsExtraPadding = 0.0]); - - @override - void initState() { - super.initState(); - - controller = - AnimationController(vsync: this, duration: Duration(milliseconds: 200)) - ..addListener(() { - setState(() {}); - }); - opacityAcnimation = Tween(begin: 0.0, end: 1.0).animate(controller); - } - - @override - Widget build(BuildContext context) { - return Expanded( - child: InkWell( - onTap: () {}, - onHover: (isHovered) { - if (isHovered) { - _animateShow(); - _logoStateKey.currentState?.animate(); - } else { - _animateHide(); - _logoStateKey.currentState?.animate(); - } - }, - child: Container( - decoration: BoxDecoration( - image: DecorationImage( - image: AssetImage(bgImageAsset), - fit: BoxFit.cover, - opacity: opacityAcnimation.value)), - padding: - EdgeInsets.only(left: 32.0, right: 32.0, bottom: 32.0, top: 16.0), - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Align( - alignment: Alignment.centerRight, - child: TextSubtitle( - text: "$number", - ), - ), - AnimatedLogo( - key: _logoStateKey, - baseImageAsset: logoBaseImageAsset, - movingPartImageAssetTop: logoMovingPartImageAssetTop, - movingPartImageAssetBottom: logoMovingPartImageAssetBottom, - extraPadding: logoPartsExtraPadding), - TextSubtitle( - text: title, - ), - ], - ), - ), - )); - } - - @override - void dispose() { - super.dispose(); - controller.dispose(); - } - - void _animateShow() { - controller.forward(); - } - - void _animateHide() { - controller.reverse(); - } } \ No newline at end of file diff --git a/lib/widgets/base/PageButton.dart b/lib/widgets/base/PageButton.dart new file mode 100644 index 0000000..a47f675 --- /dev/null +++ b/lib/widgets/base/PageButton.dart @@ -0,0 +1,131 @@ +import 'package:flutter/material.dart'; +import 'package:threeactions_area/widgets/base/AnimatedLogo.dart'; +import 'package:threeactions_area/widgets/base/TextSubtitle.dart'; + +class PageButton extends StatefulWidget { + final int number; + final String title; + final String bgImageAsset; + final String logoBaseImageAsset; + final String logoMovingPartImageAssetTop; + final String logoMovingPartImageAssetBottom; + double logoPartsExtraPadding = 0.0; + + PageButton( + {Key? key, + required this.number, + required this.title, + required this.bgImageAsset, + required this.logoBaseImageAsset, + required this.logoMovingPartImageAssetTop, + required this.logoMovingPartImageAssetBottom, + this.logoPartsExtraPadding = 0.0}) + : super(key: key); + + @override + PageButtonState createState() { + return PageButtonState( + number, + title, + bgImageAsset, + logoBaseImageAsset, + logoMovingPartImageAssetTop, + logoMovingPartImageAssetBottom, + logoPartsExtraPadding); + } +} + +class PageButtonState extends State with SingleTickerProviderStateMixin { + late AnimationController controller; + late Animation opacityAcnimation; + final GlobalKey _logoStateKey = GlobalKey(); + + final int number; + final String title; + final String bgImageAsset; + final String logoBaseImageAsset; + final String logoMovingPartImageAssetTop; + final String logoMovingPartImageAssetBottom; + double logoPartsExtraPadding = 0.0; + + PageButtonState( + this.number, + this.title, + this.bgImageAsset, + this.logoBaseImageAsset, + this.logoMovingPartImageAssetTop, + this.logoMovingPartImageAssetBottom, + [this.logoPartsExtraPadding = 0.0]); + + @override + void initState() { + super.initState(); + + controller = + AnimationController(vsync: this, duration: Duration(milliseconds: 200)) + ..addListener(() { + setState(() {}); + }); + opacityAcnimation = Tween(begin: 0.0, end: 1.0).animate(controller); + } + + @override + Widget build(BuildContext context) { + return Expanded( + child: InkWell( + onTap: () {}, + onHover: (isHovered) { + if (isHovered) { + _animateShow(); + _logoStateKey.currentState?.animate(); + } else { + _animateHide(); + _logoStateKey.currentState?.animate(); + } + }, + child: Container( + decoration: BoxDecoration( + image: DecorationImage( + image: AssetImage(bgImageAsset), + fit: BoxFit.cover, + opacity: opacityAcnimation.value)), + padding: + EdgeInsets.only(left: 32.0, right: 32.0, bottom: 32.0, top: 16.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Align( + alignment: Alignment.centerRight, + child: TextSubtitle( + text: "$number", + ), + ), + AnimatedLogo( + key: _logoStateKey, + baseImageAsset: logoBaseImageAsset, + movingPartImageAssetTop: logoMovingPartImageAssetTop, + movingPartImageAssetBottom: logoMovingPartImageAssetBottom, + extraPadding: logoPartsExtraPadding), + TextSubtitle( + text: title, + ), + ], + ), + ), + )); + } + + @override + void dispose() { + super.dispose(); + controller.dispose(); + } + + void _animateShow() { + controller.forward(); + } + + void _animateHide() { + controller.reverse(); + } +} \ No newline at end of file