Skip to content

Commit

Permalink
code refine & resolved sooxt98#69
Browse files Browse the repository at this point in the history
  • Loading branch information
18601673727 committed May 13, 2023
1 parent 76b561b commit 6278428
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 71 deletions.
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ packages:
path: ".."
relative: true
source: path
version: "5.0.7"
version: "5.0.8"
js:
dependency: transitive
description:
Expand Down
96 changes: 32 additions & 64 deletions lib/src/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Button extends StatefulWidget {
final double? textSize;

@override
_ButtonState createState() => _ButtonState();
createState() => _ButtonState();
}

class _ButtonState extends State<Button> with TickerProviderStateMixin {
Expand All @@ -70,9 +70,7 @@ class _ButtonState extends State<Button> with TickerProviderStateMixin {
super.initState();
_expanded = widget.active!;

expandController =
AnimationController(vsync: this, duration: widget.duration)
..addListener(() => setState(() {}));
expandController = AnimationController(vsync: this, duration: widget.duration)..addListener(() => setState(() {}));
}

@override
Expand All @@ -84,25 +82,19 @@ class _ButtonState extends State<Button> with TickerProviderStateMixin {

@override
Widget build(BuildContext context) {
var curveValue = expandController
.drive(CurveTween(
curve: _expanded ? widget.curve! : widget.curve!.flipped))
.value;
var _colorTween =
ColorTween(begin: widget.iconColor, end: widget.iconActiveColor);
var _colorTweenAnimation = _colorTween.animate(CurvedAnimation(
parent: expandController,
curve: _expanded ? Curves.easeInExpo : Curves.easeOutCirc));
var curveValue = expandController.drive(CurveTween(curve: _expanded ? widget.curve! : widget.curve!.flipped)).value;
var colorTween = ColorTween(begin: widget.iconColor, end: widget.iconActiveColor);
var colorTweenAnimation =
colorTween.animate(CurvedAnimation(parent: expandController, curve: _expanded ? Curves.easeInExpo : Curves.easeOutCirc));

_expanded = !widget.active!;
if (_expanded)
if (_expanded) {
expandController.reverse();
else
} else {
expandController.forward();
}

Widget icon = widget.leading ??
Icon(widget.icon,
color: _colorTweenAnimation.value, size: widget.iconSize);
Widget icon = widget.leading ?? Icon(widget.icon, color: colorTweenAnimation.value, size: widget.iconSize);

return Material(
type: MaterialType.transparency,
Expand All @@ -119,9 +111,7 @@ class _ButtonState extends State<Button> with TickerProviderStateMixin {
duration: widget.duration!,
decoration: BoxDecoration(
boxShadow: widget.shadow,
border: widget.active!
? (widget.activeBorder ?? widget.border)
: widget.border,
border: widget.active! ? (widget.activeBorder ?? widget.border) : widget.border,
gradient: widget.gradient,
color: _expanded
? widget.color!.withOpacity(0)
Expand All @@ -140,49 +130,27 @@ class _ButtonState extends State<Button> with TickerProviderStateMixin {
return Stack(
children: [
if (widget.text!.data != '')
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Opacity(
opacity: 0,
child: icon,
),
Container(
child: Container(
child: Align(
alignment: Alignment.centerRight,
widthFactor: curveValue,
child: Container(
child: Opacity(
opacity: _expanded
? pow(expandController.value,
13) as double
: expandController
.drive(CurveTween(
curve: Curves.easeIn))
.value,
child: Padding(
padding: EdgeInsets.only(
left: widget.gap! +
8 -
(8 *
expandController
.drive(CurveTween(
curve: Curves
.easeOutSine))
.value),
right: 8 *
expandController
.drive(CurveTween(
curve: Curves
.easeOutSine))
.value),
child: widget.text,
)),
)),
),
Row(mainAxisAlignment: MainAxisAlignment.end, children: [
Opacity(
opacity: 0,
child: icon,
),
Align(
alignment: Alignment.centerRight,
widthFactor: curveValue,
child: Opacity(
opacity: _expanded
? pow(expandController.value, 13) as double
: expandController.drive(CurveTween(curve: Curves.easeIn)).value,
child: Padding(
padding: EdgeInsets.only(
left: widget.gap! + 8 - (8 * expandController.drive(CurveTween(curve: Curves.easeOutSine)).value),
right: 8 * expandController.drive(CurveTween(curve: Curves.easeOutSine)).value),
child: widget.text,
),
]),
),
),
]),
Align(alignment: Alignment.centerLeft, child: icon),
],
);
Expand All @@ -195,7 +163,7 @@ class _ButtonState extends State<Button> with TickerProviderStateMixin {
child: Text(
widget.text!.data!,
style: TextStyle(
color: _colorTweenAnimation.value,
color: colorTweenAnimation.value,
fontSize: widget.textSize ?? 16,
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/gbutton.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class GButton extends StatefulWidget {
}) : super(key: key);

@override
_GButtonState createState() => _GButtonState();
createState() => _GButtonState();
}

class _GButtonState extends State<GButton> {
Expand Down
9 changes: 5 additions & 4 deletions lib/src/gnav.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ class _GNavState extends State<GNav> {
backgroundColor: t.backgroundColor ?? widget.tabBackgroundColor,
duration: widget.duration,
onPressed: () {
if (!context.mounted) return;
if (!clickable) return;
setState(() {
selectedIndex = widget.tabs.indexOf(t);
Expand All @@ -138,9 +137,11 @@ class _GNavState extends State<GNav> {
widget.onTabChange?.call(selectedIndex);

Future.delayed(widget.duration, () {
setState(() {
clickable = true;
});
if (context.mounted) {
setState(() {
clickable = true;
});
}
});
},
))
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: google_nav_bar
description: A modern google style nav bar which could be use as a bottom navigation bar or tabbar, the design strictly follows the cuberto UI/UX on dribbble.
version: 5.0.7
version: 5.0.8
homepage: https://github.com/sooxt98/google_nav_bar

environment:
Expand Down

0 comments on commit 6278428

Please sign in to comment.