Skip to content

Commit

Permalink
base windget refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
GreyLabsDev committed Jan 17, 2024
1 parent 840164b commit 7db470c
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 131 deletions.
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'pages/MusicReleasesPage.dart';
import 'package:threeactions_area/pages/TestPage.dart';

void main() {
runApp(MyApp());
Expand All @@ -10,7 +10,7 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'Threeactions',
home: MusicReleasePage(),
home: TestPage(),
);
}
}
129 changes: 0 additions & 129 deletions lib/pages/TestPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<AnimatedLogoState> _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<double>(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();
}
}
131 changes: 131 additions & 0 deletions lib/widgets/base/PageButton.dart
Original file line number Diff line number Diff line change
@@ -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<AnimatedLogoState> _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<double>(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();
}
}

0 comments on commit 7db470c

Please sign in to comment.