primary_button.dart
1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import 'package:doublefeel_flutter/core/theme/app_colors.dart';
import 'package:doublefeel_flutter/core/util/size_extensions.dart';
import 'package:flutter/material.dart';
class PrimaryButton extends StatelessWidget {
const PrimaryButton({
super.key,
required this.label,
required this.enabled,
required this.loading,
required this.onTap,
this.backgroundColor = AppColors.primary,
this.disabledColor,
});
final String label;
final bool enabled;
final bool loading;
final VoidCallback onTap;
final Color backgroundColor;
final Color? disabledColor;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: enabled ? onTap : null,
behavior: HitTestBehavior.opaque,
child: Container(
height: 48.h,
decoration: BoxDecoration(
color: enabled
? backgroundColor
: disabledColor ?? backgroundColor.withValues(alpha: 0.35),
borderRadius: BorderRadius.circular(24.dp),
),
alignment: Alignment.center,
child: loading
? const SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
)
: Text(
label,
style: const TextStyle(
color: Colors.white,
fontSize: 14,
fontWeight: FontWeight.w500,
),
),
),
);
}
}