-
Notifications
You must be signed in to change notification settings - Fork 32
/
yaru_banner.dart
199 lines (181 loc) · 6.11 KB
/
yaru_banner.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import 'package:flutter/material.dart';
import 'package:yaru_widgets/src/extensions/inner_border_radius.dart';
import 'package:yaru_widgets/yaru_widgets.dart';
/// A colorable [Card] with a border which is tap-able via an [onTap] callback.
class YaruBanner extends StatelessWidget {
const YaruBanner({
Key? key,
this.onTap,
this.surfaceTintColor,
this.watermark = false,
required this.name,
this.summary,
this.url,
this.icon,
required this.fallbackIconData,
this.nameTextOverflow,
this.summaryTextOverflow,
this.bannerWidth,
this.subtitleWidget,
}) : super(key: key);
/// The name of the card
final String name;
final Widget? subtitleWidget;
/// A summary string shown in the second line.
final String? summary;
/// The url to include a [YaruSafeImage].
final String? url;
/// An optional callback
final Function()? onTap;
/// The color used for the soft background tint.
/// If null [Theme]'s background color is used.
final Color? surfaceTintColor;
/// If true the [icon] will be displayed a second time, with small opacity.
final bool watermark;
/// The [Widget] used as the trailing icon.
final Widget? icon;
/// If the icon is not loaded this fallback icon is displayed.
final IconData fallbackIconData;
final TextOverflow? nameTextOverflow;
/// Optional [TextOverflow]
final TextOverflow? summaryTextOverflow;
/// Optional width for the banner - if null it defaults to 370.
final double? bannerWidth;
@override
Widget build(BuildContext context) {
final borderRadius = BorderRadius.circular(10);
bool light = Theme.of(context).brightness == Brightness.light;
return Material(
color: Colors.transparent,
child: InkWell(
onTap: onTap,
borderRadius: borderRadius,
hoverColor: Theme.of(context).colorScheme.onSurface.withOpacity(0.1),
child: surfaceTintColor != null
? Stack(
children: [
_Banner(
subtitleWidget: subtitleWidget,
width: bannerWidth,
borderRadius: borderRadius,
color: surfaceTintColor!,
title: name,
summary: summary,
elevation: light ? 4 : 6,
icon: icon ??
YaruSafeImage(
url: url,
fallBackIconData: fallbackIconData,
),
titleTextOverflow:
nameTextOverflow ?? TextOverflow.ellipsis,
subTitleTextOverflow:
summaryTextOverflow ?? TextOverflow.fade,
mouseCursor:
onTap != null ? SystemMouseCursors.click : null,
),
if (watermark == true)
Padding(
padding: const EdgeInsets.only(right: 20),
child: Align(
alignment: Alignment.centerRight,
child: Opacity(
opacity: 0.1,
child: SizedBox(
height: 130,
child: YaruSafeImage(
url: url,
fallBackIconData: fallbackIconData,
),
),
),
),
),
],
)
: _Banner(
subtitleWidget: subtitleWidget,
width: bannerWidth,
borderRadius: borderRadius,
color: light
? Theme.of(context).backgroundColor
: Theme.of(context).colorScheme.onSurface.withOpacity(0.01),
elevation: light ? 2 : 1,
icon: icon ??
YaruSafeImage(
url: url,
fallBackIconData: fallbackIconData,
iconSize: 50,
),
title: name,
summary: summary,
titleTextOverflow: nameTextOverflow ?? TextOverflow.ellipsis,
subTitleTextOverflow:
summaryTextOverflow ?? TextOverflow.ellipsis,
mouseCursor: onTap != null ? SystemMouseCursors.click : null,
),
),
);
}
}
class _Banner extends StatelessWidget {
const _Banner({
Key? key,
required this.color,
required this.title,
this.summary,
required this.elevation,
required this.icon,
required this.borderRadius,
required this.subTitleTextOverflow,
this.mouseCursor,
required this.titleTextOverflow,
this.width,
this.subtitleWidget,
}) : super(key: key);
final Color color;
final String title;
final String? summary;
final double elevation;
final Widget icon;
final BorderRadius borderRadius;
final TextOverflow subTitleTextOverflow;
final TextOverflow titleTextOverflow;
final MouseCursor? mouseCursor;
final double? width;
final Widget? subtitleWidget;
@override
Widget build(BuildContext context) {
return Card(
shadowColor: Colors.transparent,
surfaceTintColor: color,
elevation: elevation,
shape: RoundedRectangleBorder(
borderRadius: borderRadius
.inner(const EdgeInsets.all(4.0)), // 4 is the default margin
side: BorderSide(color: Theme.of(context).dividerColor, width: 1),
),
child: Align(
alignment: Alignment.centerLeft,
child: SizedBox(
width: width ?? 370,
child: ListTile(
mouseCursor: mouseCursor,
subtitle: subtitleWidget ??
(summary != null
? Text(summary!, overflow: subTitleTextOverflow)
: null),
title: Text(
title,
style: TextStyle(fontSize: 20, overflow: titleTextOverflow),
),
leading: SizedBox(
width: 60,
child: icon,
),
),
),
),
);
}
}