-
Notifications
You must be signed in to change notification settings - Fork 32
/
yaru_selectable_container.dart
69 lines (59 loc) · 2.19 KB
/
yaru_selectable_container.dart
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
58
59
60
61
62
63
64
65
66
67
68
69
import 'package:flutter/material.dart';
import 'package:yaru_widgets/src/constants.dart';
import 'package:yaru_widgets/src/extensions/border_radius.dart';
class YaruSelectableContainer extends StatelessWidget {
/// Creates a Image Tile from the image path given in the path property.
const YaruSelectableContainer({
Key? key,
required this.child,
this.onTap,
required this.selected,
this.borderRadius,
this.radius = kDefaultContainerRadius,
this.padding,
this.selectionColor,
}) : super(key: key);
// The child which will be selected with [onTap]
final Widget child;
/// Current Value of the imageTile.
/// Based on the this value selection of the image can be managed.
/// If this value is `true` [Container] border will have color from [Theme.of(context).primaryColor]
/// else if the value is `false` the border color will be [Colors.transparent].
final bool selected;
/// Callback triggered when the [YaruSelectableContainer] is clicked.
final VoidCallback? onTap;
/// Optional custom radius for the corners which defaults to a 8.0 [BorderRadius]
final BorderRadius? borderRadius;
/// Optional double value used for a symmetric circular [BorderRadius] if [borderRadius]
/// is not specified.
final double radius;
/// Optional custom padding for the child which defaults to 6.0 on all sides.
final EdgeInsets? padding;
/// Optional custom [Color] which is used for the selection border.
final Color? selectionColor;
@override
Widget build(BuildContext context) {
final padding = this.padding ?? const EdgeInsets.all(6);
final borderRadius = this.borderRadius ?? BorderRadius.circular(radius);
return InkWell(
borderRadius: borderRadius,
onTap: onTap,
child: Container(
decoration: BoxDecoration(
borderRadius: borderRadius,
color: selected
? selectionColor ??
Theme.of(context).primaryColor.withOpacity(0.8)
: Colors.transparent,
),
child: Padding(
padding: padding,
child: ClipRRect(
borderRadius: borderRadius.inner(padding),
child: child,
),
),
),
);
}
}