5
5
import 'package:flutter/widgets.dart';
6
6
import 'package:flutter/painting.dart';
7
7
8
+ import 'divider_theme.dart';
8
9
import 'theme.dart';
9
10
10
11
// Examples can assume:
11
12
// BuildContext context;
12
13
13
- /// A one device pixel thick horizontal line, with padding on either
14
- /// side.
14
+ /// A thin horizontal line, with padding on either side.
15
15
///
16
16
/// In the material design language, this represents a divider. Dividers can be
17
17
/// used in lists, [Drawer]s, and elsewhere to separate content.
18
18
///
19
- /// To create a one-pixel divider between [ListTile] items, consider using
19
+ /// To create a divider between [ListTile] items, consider using
20
20
/// [ListTile.divideTiles], which is optimized for this case.
21
21
///
22
22
/// The box's total height is controlled by [height]. The appropriate
@@ -30,36 +30,56 @@ import 'theme.dart';
30
30
class Divider extends StatelessWidget {
31
31
/// Creates a material design divider.
32
32
///
33
- /// The height must be positive.
33
+ /// The [height], [thickness], [indent], and [endIndent] must be null or
34
+ /// non-negative.
34
35
const Divider({
35
36
Key key,
36
- this.height = 16.0,
37
- this.indent = 0.0,
38
- this.endIndent = 0.0,
37
+ this.height,
38
+ this.thickness,
39
+ this.indent,
40
+ this.endIndent,
39
41
this.color,
40
- }) : assert(height >= 0.0),
42
+ }) : assert(height == null || height >= 0.0),
43
+ assert(thickness == null || thickness >= 0.0),
44
+ assert(indent == null || indent >= 0.0),
45
+ assert(endIndent == null || endIndent >= 0.0),
41
46
super(key: key);
42
47
43
48
44
49
/// The divider's height extent.
45
50
///
46
- /// The divider itself is always drawn as one device pixel thick horizontal
47
- /// line that is centered within the height specified by this value.
51
+ /// The divider itself is always drawn as a horizontal line that is centered
52
+ /// within the height specified by this value.
48
53
///
49
- /// A divider with a [height] of 0.0 is always drawn as a line with a height
50
- /// of exactly one device pixel, without any padding around it .
54
+ /// If this is null, then the [DividerThemeData.space] is used. If that is
55
+ /// also null, then this defaults to 16.0 .
51
56
final double height;
52
57
53
- /// The amount of empty space to the left of the divider.
58
+ /// The thickness of the line drawn within the divider.
59
+ ///
60
+ /// A divider with a [thickness] of 0.0 is always drawn as a line with a
61
+ /// height of exactly one device pixel.
62
+ ///
63
+ /// If this is null, then the [DividerThemeData.dividerThickness] is used. If
64
+ /// that is also null, then this defaults to 0.0.
65
+ final double thickness;
66
+
67
+ /// The amount of empty space to the leading edge of the divider.
68
+ ///
69
+ /// If this is null, then the [DividerThemeData.indent] is used. If that is
70
+ /// also null, then this defaults to 0.0.
54
71
final double indent;
55
72
56
- /// The amount of empty space to the right of the divider.
73
+ /// The amount of empty space to the trailing edge of the divider.
74
+ ///
75
+ /// If this is null, then the [DividerThemeData.endIndent] is used. If that is
76
+ /// also null, then this defaults to 0.0.
57
77
final double endIndent;
58
78
59
79
/// The color to use when painting the line.
60
80
///
61
- /// Defaults to the current theme's divider color, given by
62
- /// [ThemeData.dividerColor].
81
+ /// If this is null, then the [DividerThemeData. color] is used. If that is
82
+ /// also null, then [ThemeData.dividerColor] is used .
63
83
///
64
84
/// {@tool sample}
65
85
///
@@ -76,7 +96,7 @@ class Divider extends StatelessWidget {
76
96
/// [ThemeData.dividerColor] specified in the ambient [Theme].
77
97
///
78
98
/// The `width` argument can be used to override the default width of the
79
- /// divider border, which is usually 0.0 (a hairline border).
99
+ /// divider border, which defaults to 0.0 (a hairline border).
80
100
///
81
101
/// {@tool sample}
82
102
///
@@ -96,25 +116,30 @@ class Divider extends StatelessWidget {
96
116
/// )
97
117
/// ```
98
118
/// {@end-tool}
99
- static BorderSide createBorderSide(BuildContext context, { Color color, double width = 0.0 }) {
100
- assert(width != null);
119
+ static BorderSide createBorderSide(BuildContext context, { Color color, double width }) {
101
120
return BorderSide(
102
- color: color ?? Theme.of(context).dividerColor,
103
- width: width,
121
+ color: color ?? DividerTheme.of(context).color ?? Theme.of(context).dividerColor,
122
+ width: width ?? DividerTheme.of(context).thickness ?? 0.0 ,
104
123
);
105
124
}
106
125
107
126
@override
108
127
Widget build(BuildContext context) {
128
+ final DividerThemeData dividerTheme = DividerTheme.of(context);
129
+ final double height = this.height ?? dividerTheme.space ?? 16.0;
130
+ final double thickness = this.thickness ?? dividerTheme.thickness ?? 0.0;
131
+ final double indent = this.indent ?? dividerTheme.indent ?? 0.0;
132
+ final double endIndent = this.endIndent ?? dividerTheme.endIndent ?? 0.0;
133
+
109
134
return SizedBox(
110
135
height: height,
111
136
child: Center(
112
137
child: Container(
113
- height: 0.0 ,
138
+ height: thickness ,
114
139
margin: EdgeInsetsDirectional.only(start: indent, end: endIndent),
115
140
decoration: BoxDecoration(
116
141
border: Border(
117
- bottom: createBorderSide(context, color: color),
142
+ bottom: createBorderSide(context, color: color, width: thickness ),
118
143
),
119
144
),
120
145
),
@@ -123,8 +148,7 @@ class Divider extends StatelessWidget {
123
148
}
124
149
}
125
150
126
- /// A one device pixel thick vertical line, with padding on either
127
- /// side.
151
+ /// A thin vertical line, with padding on either side.
128
152
///
129
153
/// In the material design language, this represents a divider. Vertical
130
154
/// dividers can be used in horizontally scrolling lists, such as a
@@ -138,37 +162,57 @@ class Divider extends StatelessWidget {
138
162
/// * [ListView.separated], which can be used to generate vertical dividers.
139
163
/// * <https://material.io/design/components/dividers.html>
140
164
class VerticalDivider extends StatelessWidget {
141
- /// Creates a material design divider.
165
+ /// Creates a material design vertical divider.
142
166
///
143
- /// The width must be positive.
167
+ /// The [width], [thickness], [indent], and [endIndent] must be null or
168
+ /// non-negative.
144
169
const VerticalDivider({
145
170
Key key,
146
- this.width = 16.0,
147
- this.indent = 0.0,
148
- this.endIndent = 0.0,
171
+ this.width,
172
+ this.thickness,
173
+ this.indent,
174
+ this.endIndent,
149
175
this.color,
150
- }) : assert(width >= 0.0),
176
+ }) : assert(width == null || width >= 0.0),
177
+ assert(thickness == null || thickness >= 0.0),
178
+ assert(indent == null || indent >= 0.0),
179
+ assert(endIndent == null || endIndent >= 0.0),
151
180
super(key: key);
152
181
153
182
/// The divider's width.
154
183
///
155
- /// The divider itself is always drawn as one device pixel thick
156
- /// line that is centered within the width specified by this value.
184
+ /// The divider itself is always drawn as a vertical line that is centered
185
+ /// within the width specified by this value.
157
186
///
158
- /// A divider with a [width] of 0.0 is always drawn as a line with a width
159
- /// of exactly one device pixel, without any padding around it .
187
+ /// If this is null, then the [DividerThemeData.space] is used. If that is
188
+ /// also null, then this defaults to 16.0 .
160
189
final double width;
161
190
191
+ /// The thickness of the line drawn within the divider.
192
+ ///
193
+ /// A divider with a [thickness] of 0.0 is always drawn as a line with a
194
+ /// width of exactly one device pixel.
195
+ ///
196
+ /// If this is null, then the [DividerThemeData.thickness] is used which
197
+ /// defaults to 0.0.
198
+ final double thickness;
199
+
162
200
/// The amount of empty space on top of the divider.
201
+ ///
202
+ /// If this is null, then the [DividerThemeData.indent] is used. If that is
203
+ /// also null, then this defaults to 0.0.
163
204
final double indent;
164
205
165
206
/// The amount of empty space under the divider.
207
+ ///
208
+ /// If this is null, then the [DividerThemeData.endIndent] is used. If that is
209
+ /// also null, then this defaults to 0.0.
166
210
final double endIndent;
167
211
168
212
/// The color to use when painting the line.
169
213
///
170
- /// Defaults to the current theme's divider color, given by
171
- /// [ThemeData.dividerColor].
214
+ /// If this is null, then the [DividerThemeData. color] is used. If that is
215
+ /// also null, then [ThemeData.dividerColor] is used .
172
216
///
173
217
/// {@tool sample}
174
218
///
@@ -182,15 +226,21 @@ class VerticalDivider extends StatelessWidget {
182
226
183
227
@override
184
228
Widget build(BuildContext context) {
229
+ final DividerThemeData dividerTheme = DividerTheme.of(context);
230
+ final double width = this.width ?? dividerTheme.space ?? 16.0;
231
+ final double thickness = this.thickness ?? dividerTheme.thickness ?? 0.0;
232
+ final double indent = this.indent ?? dividerTheme.indent ?? 0.0;
233
+ final double endIndent = this.endIndent ?? dividerTheme.endIndent ?? 0.0;
234
+
185
235
return SizedBox(
186
236
width: width,
187
237
child: Center(
188
238
child: Container(
189
- width: 0.0 ,
239
+ width: thickness ,
190
240
margin: EdgeInsetsDirectional.only(top: indent, bottom: endIndent),
191
241
decoration: BoxDecoration(
192
242
border: Border(
193
- left: Divider.createBorderSide(context, color: color),
243
+ left: Divider.createBorderSide(context, color: color, width: thickness ),
194
244
),
195
245
),
196
246
),
0 commit comments