Line data Source code
1 : part of apptive_grid_form_widgets;
2 :
3 : /// Widget to display a [GridRow]
4 : /// Multiple of these in a Vertical Layout will display a full Grid
5 : class GridRowWidget extends StatelessWidget {
6 : /// Creates a new RowWidget
7 1 : const GridRowWidget({
8 : Key? key,
9 : required this.row,
10 : this.cellSize = const Size(150, 50),
11 : this.textStyle,
12 : this.color,
13 : this.padding = const EdgeInsets.symmetric(horizontal: 16),
14 : this.controller,
15 1 : }) : super(key: key);
16 :
17 : /// Row to be displayed
18 : final GridRow row;
19 :
20 : /// Size of the cell. [cellSize.width] will be used as the width of each cell [cellSize.height] will be used as the height of the complete row
21 : /// defaults to Size(150, 50)
22 : final Size cellSize;
23 :
24 : /// Text Style for the entries
25 : final TextStyle? textStyle;
26 :
27 : /// Background color of the row
28 : final Color? color;
29 :
30 : /// Padding of the row.
31 : /// defaults to a horizontal Padding of 16
32 : final EdgeInsets padding;
33 :
34 : /// ScrollController handling the horizontal scroll of the row
35 : /// It is recommended that this controller is part of a [LinkedScrollControllerGroup] to sync scrolling across the whole grid representation
36 : final ScrollController? controller;
37 :
38 1 : @override
39 : Widget build(BuildContext context) {
40 1 : return _GridRow(
41 8 : labels: row.entries.map((e) => e.data.value?.toString()).toList(),
42 1 : cellSize: cellSize,
43 1 : textStyle: textStyle,
44 1 : color: color,
45 1 : padding: padding,
46 1 : controller: controller,
47 : );
48 : }
49 : }
50 :
51 : /// Widget to display a Header Row for a [Grid] given the grids [fields]
52 : class HeaderRowWidget extends StatelessWidget {
53 : /// Creates a new RowWidget
54 1 : const HeaderRowWidget({
55 : Key? key,
56 : required this.fields,
57 : this.cellSize = const Size(150, 50),
58 : this.textStyle,
59 : this.color,
60 : this.padding = const EdgeInsets.symmetric(horizontal: 16),
61 : this.controller,
62 1 : }) : super(key: key);
63 :
64 : /// Fields that should be displayed
65 : final List<GridField> fields;
66 :
67 : /// Size of the cell. [cellSize.width] will be used as the width of each cell [cellSize.height] will be used as the height of the complete row
68 : /// defaults to Size(150, 50)
69 : final Size cellSize;
70 :
71 : /// Text Style for the entries
72 : /// Defaults to [FontWeight.bold] and a text color visible on the primaryColor of the App Theme
73 : final TextStyle? textStyle;
74 :
75 : /// Background color of the row
76 : /// Defaults to the primaryColor of the App Theme
77 : final Color? color;
78 :
79 : /// Padding of the row.
80 : /// defaults to a horizontal Padding of 16
81 : final EdgeInsets padding;
82 :
83 : /// ScrollController handling the horizontal scroll of the row
84 : /// It is recommended that this controller is part of a [LinkedScrollControllerGroup] to sync scrolling across the whole grid representation
85 : final ScrollController? controller;
86 :
87 1 : @override
88 : Widget build(BuildContext context) {
89 1 : final theme = Theme.of(context);
90 1 : return _GridRow(
91 5 : labels: fields.map((e) => e.name).toList(),
92 1 : cellSize: cellSize,
93 1 : textStyle: textStyle ??
94 1 : TextStyle(
95 : fontWeight: FontWeight.bold,
96 3 : color: theme.primaryTextTheme.headline1!.color,
97 : ),
98 2 : color: color ?? theme.primaryColor,
99 1 : padding: padding,
100 1 : controller: controller,
101 : );
102 : }
103 : }
104 :
105 : class _GridRow extends StatelessWidget {
106 1 : const _GridRow({
107 : Key? key,
108 : required this.labels,
109 : this.cellSize = const Size(150, 50),
110 : this.textStyle,
111 : this.color,
112 : this.padding = const EdgeInsets.symmetric(horizontal: 16),
113 : this.controller,
114 1 : }) : super(key: key);
115 :
116 : final List<String?> labels;
117 : final Size cellSize;
118 : final TextStyle? textStyle;
119 : final Color? color;
120 : final EdgeInsets padding;
121 : final ScrollController? controller;
122 :
123 1 : @override
124 : Widget build(BuildContext context) {
125 1 : return Container(
126 2 : height: cellSize.height,
127 1 : padding: padding,
128 1 : color: color,
129 1 : child: SingleChildScrollView(
130 1 : controller: controller,
131 : scrollDirection: Axis.horizontal,
132 1 : child: Row(
133 1 : children: labels
134 1 : .map(
135 2 : (label) => SizedBox(
136 2 : width: cellSize.width,
137 1 : child: Text(
138 : label ?? '',
139 1 : style: textStyle,
140 : maxLines: 1,
141 : overflow: TextOverflow.ellipsis,
142 : ),
143 : ),
144 : )
145 1 : .toList(),
146 : ),
147 : ),
148 : );
149 : }
150 : }
|