dev
dart 66 lines 1.78 KB
Raw
1 import 'package:flutter/material.dart';
2 import 'package:flutter/services.dart';
3
4 class ActionButton extends StatelessWidget {
5 ActionButton({
6 required this.image,
7 required this.title,
8 this.route,
9 this.onClick,
10 this.alignment = Alignment.center,
11 this.textColor,
12 super.key,
13 });
14
15 final Image image;
16 final String title;
17 final String? route;
18 final Alignment alignment;
19 final VoidCallback? onClick;
20 final Color? textColor;
21
22 @override
23 Widget build(BuildContext context) {
24 return TextButton(
25 style: TextButton.styleFrom(
26 padding: EdgeInsets.zero,
27 minimumSize: Size.zero,
28 tapTargetSize: MaterialTapTargetSize.shrinkWrap,
29 ),
30 onPressed: () {
31 if (route?.isNotEmpty ?? false) {
32 Navigator.of(context, rootNavigator: true).pushNamed(route!);
33 } else {
34 onClick?.call();
35 }
36 },
37 child: SizedBox.expand(
38 child: Container(
39 color: Colors.transparent,
40 alignment: alignment,
41 child: Column(
42 mainAxisAlignment: MainAxisAlignment.center,
43 mainAxisSize: MainAxisSize.min,
44 crossAxisAlignment: CrossAxisAlignment.center,
45 children: <Widget>[
46 image,
47 const SizedBox(height: 4),
48 Flexible(
49 child: Text(
50 title,
51 maxLines: 1,
52 overflow: TextOverflow.fade,
53 softWrap: false,
54 textAlign: TextAlign.center,
55 style: Theme.of(context).textTheme.labelSmall?.copyWith(
56 color: textColor ?? Theme.of(context).colorScheme.onSurface,
57 ),
58 ),
59 ),
60 ],
61 ),
62 ),
63 ),
64 );
65 }
66 }