-
-
Notifications
You must be signed in to change notification settings - Fork 647
Expand file tree
/
Copy pathgf_card.dart
More file actions
188 lines (160 loc) · 6.01 KB
/
gf_card.dart
File metadata and controls
188 lines (160 loc) · 6.01 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
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
import 'package:flutter/material.dart';
import 'package:getwidget/getwidget.dart';
/// A material design card. A card has slightly rounded corners and a shadow.
///
/// A card is a sheet of [Material] used to represent some related information,
/// for example an album, a geographical location, a meal, contact details, etc.
class GFCard extends StatelessWidget {
/// Creates a material design card.
///
/// The [elevation] must be null or non-negative. The [borderOnForeground]
/// must not be null.
const GFCard({
Key? key,
this.color,
this.elevation,
this.shape,
this.borderOnForeground = true,
this.padding = const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
this.margin,
this.clipBehavior,
this.semanticContainer,
this.title,
this.content,
this.image,
this.showImage = false,
this.showOverlayImage = false,
this.buttonBar,
this.imageOverlay,
this.titlePosition,
this.borderRadius,
this.border,
this.boxFit,
this.colorFilter,
this.height,
this.gradient,
}) : assert(elevation == null || elevation >= 0.0),
assert(
color == null || gradient == null,
'Cannot provide both a color and a decoration\n'
'The color argument is just a shorthand for "decoration: new BoxDecoration(color: color)".',
),
super(key: key);
/// defines the card's height
final double? height;
/// [GFPosition] titlePosition helps to set titlebar at top of card
final GFPosition? titlePosition;
/// The card's background color.
final Color? color;
/// The z-coordinate at which to place this card. This controls the size of the shadow below the card.
final double? elevation;
/// The shape of the card's [Material].
final ShapeBorder? shape;
/// Whether to paint the [shape] border in front of the child.
final bool borderOnForeground;
/// If this property is null then [CardTheme.clipBehavior] is used.
final Clip? clipBehavior;
/// The empty space that surrounds the card. Defines the card's outer [Container.margin].
final EdgeInsetsGeometry? margin;
/// The empty space that surrounds the card. Defines the card's outer [Container.padding]..
final EdgeInsetsGeometry padding;
/// Whether this widget represents a single semantic container, or if false
/// a collection of individual semantic nodes.
final bool? semanticContainer;
/// The title to display inside the GFTitleBar. see GFTitleBar
final GFListTile? title;
/// widget can be used to define content
final Widget? content;
final bool showImage;
final bool showOverlayImage;
/// image widget can be used
final Image? image;
/// overlay image [GFImageOverlay] widget can be used
/// to display image with shaded overlay
final ImageProvider? imageOverlay;
/// widget can be used to define buttons bar, see [GFButtonBar]
final GFButtonBar? buttonBar;
/// How the image should be inscribed into the box.
/// The default is [BoxFit.scaleDown] if centerSlice is null, and
/// [BoxFit.fill] if centerSlice is not null.
/// [boxFit] for only [GFImageOverlay]
final BoxFit? boxFit;
/// A color filter to apply to the image before painting it.
final ColorFilter? colorFilter;
/// The corners of this [GFCard] are rounded by this [BorderRadius].
final BorderRadiusGeometry? borderRadius;
/// A border to draw above the [GFCard].
final Border? border;
/// defines the gradient background
final LinearGradient? gradient;
static const double _defaultElevation = 1;
static const Clip _defaultClipBehavior = Clip.none;
@override
Widget build(BuildContext context) {
final cardTheme = CardTheme.of(context);
final Widget cardChild = Padding(
padding: padding,
child: Column(
children: <Widget>[
titlePosition == GFPosition.start
? title ?? Container()
: showImage != false
? ClipRRect(
// ignore: avoid_as
borderRadius: borderRadius as BorderRadius? ??
const BorderRadius.vertical(top: Radius.circular(4)),
child: image,
)
: Container(),
titlePosition == GFPosition.start
? showImage != false
? Container(child: image)
: Container()
: title ?? Container(),
Padding(padding: padding, child: content ?? Container()),
buttonBar ?? Container(),
],
),
);
final Widget overlayImage = GFImageOverlay(
width: MediaQuery.of(context).size.width,
child: cardChild,
color: color ?? cardTheme.color ?? Theme.of(context).cardColor,
image: imageOverlay,
boxFit: boxFit,
colorFilter: colorFilter,
border: border,
borderRadius: borderRadius ?? const BorderRadius.all(Radius.circular(4)),
);
return Container(
height: height,
margin: margin ?? cardTheme.margin ?? const EdgeInsets.all(16),
decoration: gradient != null
? BoxDecoration(
gradient: gradient,
borderRadius:
borderRadius ?? const BorderRadius.all(Radius.circular(4)),
)
: null,
child: gradient == null
? Material(
type: MaterialType.card,
color: color ?? cardTheme.color ?? Theme.of(context).cardColor,
elevation: elevation ?? cardTheme.elevation ?? _defaultElevation,
shape: shape ??
cardTheme.shape ??
const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
),
borderOnForeground: borderOnForeground,
clipBehavior: clipBehavior ??
cardTheme.clipBehavior ??
_defaultClipBehavior,
child: showOverlayImage == false ? cardChild : overlayImage,
)
: showOverlayImage == false
? cardChild
: overlayImage,
);
}
}