ente/lib/ui/common/gradient_button.dart

89 lines
2.2 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2022-11-22 03:41:34 +00:00
import 'package:photos/theme/ente_theme.dart';
class GradientButton extends StatelessWidget {
final List<Color> linearGradientColors;
final Function? onTap;
2022-07-04 04:45:32 +00:00
// text is ignored if child is specified
final String text;
2022-07-04 04:45:32 +00:00
// nullable
final IconData? iconData;
2022-07-04 04:45:32 +00:00
// padding between the text and icon
final double paddingValue;
const GradientButton({
Key? key,
2022-07-04 04:45:32 +00:00
this.linearGradientColors = const [
Color(0xFF2CD267),
Color(0xFF1DB954),
],
this.onTap,
2022-09-21 08:01:00 +00:00
this.text = '',
2022-07-04 04:45:32 +00:00
this.iconData,
this.paddingValue = 0.0,
}) : super(key: key);
@override
Widget build(BuildContext context) {
2022-07-04 04:45:32 +00:00
Widget buttonContent;
if (iconData == null) {
2022-07-04 04:45:32 +00:00
buttonContent = Text(
text,
2022-07-04 06:02:17 +00:00
style: const TextStyle(
2022-07-04 04:45:32 +00:00
color: Colors.white,
fontWeight: FontWeight.w600,
fontFamily: 'Inter-SemiBold',
fontSize: 18,
),
);
} else {
buttonContent = Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
iconData,
size: 20,
2022-07-04 04:45:32 +00:00
color: Colors.white,
),
const Padding(padding: EdgeInsets.symmetric(horizontal: 6)),
2022-07-04 04:45:32 +00:00
Text(
text,
2022-07-04 06:02:17 +00:00
style: const TextStyle(
2022-07-04 04:45:32 +00:00
color: Colors.white,
fontWeight: FontWeight.w600,
fontFamily: 'Inter-SemiBold',
fontSize: 18,
),
),
],
);
}
return InkWell(
onTap: onTap as void Function()?,
child: Container(
height: 56,
decoration: BoxDecoration(
gradient: LinearGradient(
2022-07-04 06:02:17 +00:00
begin: const Alignment(0.1, -0.9),
end: const Alignment(-0.6, 0.9),
2022-11-22 03:41:34 +00:00
colors: onTap != null
? linearGradientColors
: [
getEnteColorScheme(context).fillMuted,
getEnteColorScheme(context).fillMuted
],
),
borderRadius: BorderRadius.circular(8),
),
2022-07-04 04:45:32 +00:00
child: Center(child: buttonContent),
),
);
}
}