wemersonrv

Flutter Gradient Button

Dec 5th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.27 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. class GradientButton extends StatelessWidget {
  4.   final String label;
  5.   final double fontSize;
  6.   final Color backgroundColor;
  7.   final LinearGradient gradient;
  8.   final Color textColor;
  9.   final Color borderColor;
  10.   final double width;
  11.   final double height;
  12.   final IconData icon;
  13.   final Function onTap;
  14.   final double borderRadius;
  15.  
  16.   const GradientButton({
  17.     Key key,
  18.     this.label = "GraientButton",
  19.     this.fontSize,
  20.     this.backgroundColor,
  21.     this.gradient,
  22.     this.textColor = Colors.white,
  23.     this.borderColor,
  24.     this.width,
  25.     this.height = 50,
  26.     this.icon,
  27.     @required this.onTap,
  28.     this.borderRadius = 40,
  29.   }) : super(key: key);
  30.  
  31.   @override
  32.   Widget build(BuildContext context) {
  33.     return ClipRRect(
  34.       borderRadius: BorderRadius.circular(borderRadius),
  35.       child: Material(
  36.         color: backgroundColor ?? Theme.of(context).accentColor,
  37.         child: InkWell(
  38.           onTap: onTap,
  39.           child: Ink(
  40.             decoration: BoxDecoration(
  41.               borderRadius: BorderRadius.all(Radius.circular(borderRadius)),
  42.               gradient: gradient,
  43.               border:
  44.                   borderColor == null ? null : Border.all(color: borderColor),
  45.             ),
  46.             child: Container(
  47.               width: width,
  48.               height: height,
  49.               alignment: Alignment.center,
  50.               child: label == ''
  51.                   ? icon == null ? Container() : Icon(icon, color: textColor)
  52.                   : Row(
  53.                       mainAxisAlignment: MainAxisAlignment.center,
  54.                       children: <Widget>[
  55.                         icon == null
  56.                             ? Container()
  57.                             : Icon(icon, color: textColor),
  58.                         Container(width: icon == null ? 0 : 7),
  59.                         Text(
  60.                           label,
  61.                           style: TextStyle(
  62.                             color: textColor,
  63.                             fontWeight: FontWeight.bold,
  64.                             fontSize: fontSize,
  65.                           ),
  66.                         ),
  67.                       ],
  68.                     ),
  69.             ),
  70.           ),
  71.         ),
  72.       ),
  73.     );
  74.   }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment