-
Notifications
You must be signed in to change notification settings - Fork 33
/
yaru_row.dart
125 lines (110 loc) · 3.87 KB
/
yaru_row.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
import 'package:flutter/material.dart';
class YaruRow extends StatelessWidget {
/// Creates a Yaru style [ListTile] similar widget.
///
/// for example:
/// ```dart
/// YaruRow(
/// trailingWidget: Text('trailingWidget'),
/// actionWidget: Text('actionWidget'),
/// description: 'description',
/// );
/// ```
const YaruRow({
Key? key,
this.leadingWidget,
required this.trailingWidget,
this.description,
required this.actionWidget,
required this.enabled,
this.width,
this.padding = const EdgeInsets.all(8.0),
this.mainAxisAlignment = MainAxisAlignment.spaceBetween,
this.mainAxisSize = MainAxisSize.max,
this.crossAxisAlignment = CrossAxisAlignment.center,
this.verticalDirection = VerticalDirection.down,
this.textDirection,
this.textBaseline,
}) : super(key: key);
/// The [Widget] placed at the leading position.
/// A widget to display before the [trailingWidget].
///
/// Typically an [Icon] or a [CircleAvatar] widget.
final Widget? leadingWidget;
/// The [Widget] placed at trailing position.
final Widget trailingWidget;
/// The Description placed below [trailingWidget].
final String? description;
/// The [Widget] placed after the [trailingWidget].
final Widget actionWidget;
/// Whether or not we can interact with the widget
final bool enabled;
/// The `width` of the [Widget], by default it will be 500.
final double? width;
/// The padding [EdgeInsets] which defaults to `EdgeInsets.all(8.0)`.
final EdgeInsets padding;
/// The [MainAxisAlignment] which defaults to [MainAxisAlignment.spaceBetween].
final MainAxisAlignment mainAxisAlignment;
/// The [MainAxisSize] which defaults to [MainAxisSize.max].
final MainAxisSize mainAxisSize;
/// The [CrossAxisAlignment] which defaults to [CrossAxisAlignment.center].
final CrossAxisAlignment crossAxisAlignment;
/// The optional [TextDirection].
final TextDirection? textDirection;
/// The [VerticalDirection] which defaults to [VerticalDirection.down].
final VerticalDirection verticalDirection;
/// The optional [TextBaseline].
final TextBaseline? textBaseline;
@override
Widget build(BuildContext context) {
return DefaultTextStyle(
style: TextStyle(
color: enabled
? Theme.of(context).textTheme.bodyLarge!.color
: Theme.of(context).disabledColor,
),
child: SizedBox(
width: width,
child: Padding(
padding: padding,
child: Row(
mainAxisAlignment: mainAxisAlignment,
mainAxisSize: mainAxisSize,
crossAxisAlignment: crossAxisAlignment,
textDirection: textDirection,
verticalDirection: verticalDirection,
textBaseline: textBaseline,
children: [
if (leadingWidget != null) ...[
leadingWidget!,
const SizedBox(width: 8)
],
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
trailingWidget,
if (description != null)
Padding(
padding: const EdgeInsets.only(top: 4.0),
child: Text(
description!,
style: enabled
? Theme.of(context).textTheme.bodySmall
: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).disabledColor,
),
),
),
],
),
),
actionWidget,
],
),
),
),
);
}
}