Skip to content

Instantly share code, notes, and snippets.

@RobertApikyan
Created November 24, 2022 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertApikyan/51b5436d427be94de365f927b9d2b942 to your computer and use it in GitHub Desktop.
Save RobertApikyan/51b5436d427be94de365f927b9d2b942 to your computer and use it in GitHub Desktop.
class AppButton extends StatefulWidget {
const AppButton({
required this.text,
required this.styleBundle,
super.key,
this.onTap,
this.isDisabled = false,
});
final String text;
final AppButtonStyleBundle styleBundle;
final VoidCallback? onTap;
final bool isDisabled;
@override
State<AppButton> createState() => _AppButtonState();
}
class _AppButtonState extends State<AppButton> {
bool _isPressed = false;
AppButtonStyleBundle get bundle => widget.styleBundle;
final BorderRadius _borderRadius = const BorderRadius.all(
Radius.circular(AppSizes.buttonBorderRadius),
);
@override
Widget build(BuildContext context) => AnimatedContainer(
height: AppSizes.buttonHeight,
decoration: BoxDecoration(
border: bundle.borderColors != null
? Border.all(
color: bundle.borderColors!.define(
isPressed: _isPressed, isDisabled: widget.isDisabled),
width: 1.5)
: null,
color: bundle.backgroundColors
.define(isPressed: _isPressed, isDisabled: widget.isDisabled),
borderRadius: _borderRadius),
duration: const Duration(milliseconds: 190),
child: InkWell(
onTap: widget.isDisabled ? null : widget.onTap,
onTapDown: (_) => setState(() {
_isPressed = true;
}),
onTapUp: (_) => setState(() {
_isPressed = false;
}),
onTapCancel: () => setState(() {
_isPressed = false;
}),
child: Center(
child: Text(
widget.text,
style: TextStyle(
fontFamily: AppFonts.family,
fontSize: AppFontSizes.extraBig,
color: bundle.textColors.define(
isPressed: _isPressed, isDisabled: widget.isDisabled),
fontWeight: FontWeight.w500),
)),
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment