Added [onTap] callback for the gradientButton

This commit is contained in:
Mariano Uvalle 2019-03-08 21:44:21 -06:00
parent 8918c67006
commit 3e44aa2fe4
2 changed files with 43 additions and 30 deletions

View file

@ -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: <Widget>[
Text(
'LOGIN',
style: TextStyle(
color: Colors.white,
fontSize: 15,
fontWeight: FontWeight.w600,
),
),
],
);
}
}

View file

@ -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)
]),
),
),
),
);