From 3e44aa2fe425d6eb7cd9213d723318a7414da6fe Mon Sep 17 00:00:00 2001 From: AYM1607 Date: Fri, 8 Mar 2019 21:44:21 -0600 Subject: [PATCH] Added [onTap] callback for the gradientButton --- lib/src/screens/login_screen.dart | 24 +++++++++----- lib/src/widgets/gradient_button.dart | 49 +++++++++++++++------------- 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/lib/src/screens/login_screen.dart b/lib/src/screens/login_screen.dart index 2a534e4..83efce2 100644 --- a/lib/src/screens/login_screen.dart +++ b/lib/src/screens/login_screen.dart @@ -19,14 +19,7 @@ class LoginScreen extends StatelessWidget { Expanded( child: Center( child: GradientButton( - child: Text( - 'LOGIN', - style: TextStyle( - color: Colors.white, - fontSize: 15, - fontWeight: FontWeight.w600, - ), - ), + child: getButtonBody(), ), ), flex: 1, @@ -36,4 +29,19 @@ class LoginScreen extends StatelessWidget { ), ); } + + Widget getButtonBody() { + return Row( + children: [ + Text( + 'LOGIN', + style: TextStyle( + color: Colors.white, + fontSize: 15, + fontWeight: FontWeight.w600, + ), + ), + ], + ); + } } diff --git a/lib/src/widgets/gradient_button.dart b/lib/src/widgets/gradient_button.dart index 794ff2e..51bb937 100644 --- a/lib/src/widgets/gradient_button.dart +++ b/lib/src/widgets/gradient_button.dart @@ -7,38 +7,43 @@ class GradientButton extends StatelessWidget { final Widget child; final double height; final double width; + final VoidCallback onTap; GradientButton({ this.radius = 4, @required this.child, this.height, this.width, + this.onTap, }); Widget build(BuildContext context) { return ConstrainedBox( constraints: const BoxConstraints(minWidth: 88.0, minHeight: 36.0), - child: Container( - width: width, - height: height, - padding: EdgeInsets.all(5), - child: Center( - widthFactor: 1.0, - heightFactor: 1.0, - child: child, - ), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(radius), - gradient: LinearGradient( - begin: Alignment.topLeft, - end: Alignment.bottomRight, - stops: [ - 0, - 1.0 - ], - colors: [ - Color.fromRGBO(32, 156, 227, 1.0), - Color.fromRGBO(45, 83, 216, 1.0) - ]), + child: GestureDetector( + onTap: onTap, + child: Container( + width: width, + height: height, + padding: EdgeInsets.all(5), + child: Center( + widthFactor: 1.0, + heightFactor: 1.0, + child: child, + ), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(radius), + gradient: LinearGradient( + begin: Alignment.topLeft, + end: Alignment.bottomRight, + stops: [ + 0, + 1.0 + ], + colors: [ + Color.fromRGBO(32, 156, 227, 1.0), + Color.fromRGBO(45, 83, 216, 1.0) + ]), + ), ), ), );