flet-datatable2 0.1.0.dev1__py3-none-any.whl → 0.2.0.dev45__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of flet-datatable2 might be problematic. Click here for more details.

@@ -1,32 +1,23 @@
1
- import 'dart:convert';
2
-
3
- import 'package:collection/collection.dart';
4
1
  import 'package:data_table_2/data_table_2.dart';
5
2
  import 'package:flet/flet.dart' as ft;
6
3
  import 'package:flet/flet.dart';
7
4
  import 'package:flutter/material.dart';
8
5
 
6
+ import 'utils/datatable.dart';
7
+
9
8
  class DataTable2Control extends StatefulWidget {
10
- final Control? parent;
11
9
  final Control control;
12
- final List<Control> children;
13
- final bool parentDisabled;
14
- final FletControlBackend backend;
15
10
 
16
- const DataTable2Control(
17
- {super.key,
18
- this.parent,
19
- required this.control,
20
- required this.children,
21
- required this.parentDisabled,
22
- required this.backend});
11
+ const DataTable2Control({
12
+ super.key,
13
+ required this.control,
14
+ });
23
15
 
24
16
  @override
25
17
  State<DataTable2Control> createState() => _DataTable2ControlState();
26
18
  }
27
19
 
28
- class _DataTable2ControlState extends State<DataTable2Control>
29
- with FletStoreMixin {
20
+ class _DataTable2ControlState extends State<DataTable2Control> {
30
21
  //final ScrollController _horizontalController = ScrollController();
31
22
  //final ScrollController _controller = ScrollController();
32
23
 
@@ -39,271 +30,166 @@ class _DataTable2ControlState extends State<DataTable2Control>
39
30
 
40
31
  @override
41
32
  Widget build(BuildContext context) {
42
- debugPrint("DataTableControl build: ${widget.control.id}");
33
+ debugPrint("DataTable2Control build: ${widget.control.id}");
43
34
 
44
- bool tableDisabled = widget.control.isDisabled || widget.parentDisabled;
35
+ var bgColor = widget.control.getString("bgcolor");
36
+ var border = widget.control.getBorder("border", Theme.of(context));
37
+ var borderRadius = widget.control.getBorderRadius("border_radius");
38
+ var gradient = widget.control.getGradient("gradient", Theme.of(context));
39
+ var horizontalLines =
40
+ widget.control.getBorderSide("horizontal_lines", Theme.of(context));
41
+ var verticalLines =
42
+ widget.control.getBorderSide("vertical_lines", Theme.of(context));
43
+ var defaultDecoration =
44
+ Theme.of(context).dataTableTheme.decoration ?? const BoxDecoration();
45
45
 
46
- ColumnSize? parseSize(String? size, [ColumnSize? defValue]) {
47
- if (size == null) {
48
- return defValue;
49
- }
50
- return ColumnSize.values.firstWhereOrNull(
51
- (e) => e.name.toLowerCase() == size.toLowerCase()) ??
52
- defValue;
46
+ BoxDecoration? decoration;
47
+ if (bgColor != null ||
48
+ border != null ||
49
+ borderRadius != null ||
50
+ gradient != null) {
51
+ decoration = (defaultDecoration as BoxDecoration).copyWith(
52
+ color: parseColor(bgColor, Theme.of(context)),
53
+ border: border,
54
+ borderRadius: borderRadius,
55
+ gradient: gradient);
53
56
  }
54
57
 
55
- var datatable =
56
- withControls(widget.children.where((c) => c.isVisible).map((c) => c.id),
57
- (content, viewModel) {
58
- var emptyCtrls =
59
- widget.children.where((c) => c.name == "empty" && c.isVisible);
60
- Widget? empty = emptyCtrls.isNotEmpty
61
- ? createControl(
62
- widget.control, emptyCtrls.first.id, widget.control.isDisabled)
63
- : null;
64
- IconData? sortArrowIcon =
65
- parseIcon(widget.control.attrString("sortArrowIcon"));
66
- var bgColor = widget.control.attrString("bgColor");
67
- var border = parseBorder(Theme.of(context), widget.control, "border");
68
- var borderRadius = parseBorderRadius(widget.control, "borderRadius");
69
- var gradient =
70
- parseGradient(Theme.of(context), widget.control, "gradient");
71
- var horizontalLines =
72
- parseBorderSide(Theme.of(context), widget.control, "horizontalLines");
73
- var verticalLines =
74
- parseBorderSide(Theme.of(context), widget.control, "verticalLines");
75
- var defaultDecoration =
76
- Theme.of(context).dataTableTheme.decoration ?? const BoxDecoration();
77
- var checkboxAlignment = parseAlignment(
78
- widget.control, "checkboxAlignment", Alignment.center)!;
79
-
80
- BoxDecoration? decoration;
81
- if (bgColor != null ||
82
- border != null ||
83
- borderRadius != null ||
84
- gradient != null) {
85
- decoration = (defaultDecoration as BoxDecoration).copyWith(
86
- color: parseColor(Theme.of(context), bgColor),
87
- border: border,
88
- borderRadius: borderRadius,
89
- gradient: gradient);
90
- }
91
-
92
- TableBorder? tableBorder;
93
- if (horizontalLines != null || verticalLines != null) {
94
- tableBorder = TableBorder(
95
- horizontalInside: horizontalLines ?? BorderSide.none,
96
- verticalInside: verticalLines ?? BorderSide.none);
97
- }
98
-
99
- Clip clipBehavior =
100
- parseClip(widget.control.attrString("clipBehavior"), Clip.none)!;
101
-
102
- return withPageArgs((context, pageArgs) {
103
- return DataTable2(
104
- bottomMargin: widget.control.attrDouble("bottomMargin"),
105
- minWidth: widget.control.attrDouble("minWidth"),
106
- //horizontalScrollController: _horizontalController,
107
- //scrollController: _controller,
108
- decoration: decoration,
109
- border: tableBorder,
110
- empty: empty,
111
- isHorizontalScrollBarVisible:
112
- widget.control.attrBool("isHorizontalScrollBarVisible"),
113
- isVerticalScrollBarVisible:
114
- widget.control.attrBool("isVerticalScrollBarVisible"),
115
- fixedLeftColumns: widget.control.attrInt("fixedLeftColumns") ?? 0,
116
- fixedTopRows: widget.control.attrInt("fixedTopRows") ?? 1,
117
- fixedColumnsColor:
118
- widget.control.attrColor("fixedColumnsColor", context),
119
- fixedCornerColor:
120
- widget.control.attrColor("fixedCornerColor", context),
121
- smRatio: widget.control.attrDouble("smRatio") ?? 0.67,
122
- lmRatio: widget.control.attrDouble("lmRatio") ?? 1.2,
123
- clipBehavior: clipBehavior,
124
- sortArrowIcon: sortArrowIcon ?? Icons.arrow_upward,
125
- sortArrowAnimationDuration:
126
- parseDuration(widget.control, "sortArrowAnimationDuration") ??
127
- Duration(microseconds: 150),
128
- checkboxHorizontalMargin:
129
- widget.control.attrDouble("checkboxHorizontalMargin"),
130
- checkboxAlignment: checkboxAlignment,
131
- headingCheckboxTheme: parseCheckboxTheme(
132
- Theme.of(context),
133
- widget.control.attrString("headingCheckboxTheme") != null
134
- ? json.decode(
135
- widget.control.attrString("headingCheckboxTheme")!)
136
- : null),
137
- datarowCheckboxTheme: parseCheckboxTheme(
138
- Theme.of(context),
139
- widget.control.attrString("dataRowCheckboxTheme") != null
140
- ? json.decode(
141
- widget.control.attrString("dataRowCheckboxTheme")!)
142
- : null),
143
- showHeadingCheckBox:
144
- widget.control.attrBool("showHeadingCheckbox", true)!,
145
- columnSpacing: widget.control.attrDouble("columnSpacing"),
146
- dataRowColor: parseWidgetStateColor(
147
- Theme.of(context), widget.control, "dataRowColor"),
148
- dataRowHeight: widget.control.attrDouble("dataRowHeight"),
149
- //dataRowMinHeight: widget.control.attrDouble("dataRowMinHeight"),
150
- //dataRowMaxHeight: widget.control.attrDouble("dataRowMaxHeight"),
151
- dataTextStyle: parseTextStyle(
152
- Theme.of(context), widget.control, "dataTextStyle"),
153
- headingRowColor: parseWidgetStateColor(
154
- Theme.of(context), widget.control, "headingRowColor"),
155
- headingRowHeight: widget.control.attrDouble("headingRowHeight"),
156
- headingTextStyle: parseTextStyle(
157
- Theme.of(context), widget.control, "headingTextStyle"),
158
- headingRowDecoration: parseBoxDecoration(Theme.of(context),
159
- widget.control, "headingRowDecoration", pageArgs),
160
- dividerThickness: widget.control.attrDouble("dividerThickness"),
161
- horizontalMargin: widget.control.attrDouble("horizontalMargin"),
162
- showBottomBorder:
163
- widget.control.attrBool("showBottomBorder", false)!,
164
- showCheckboxColumn:
165
- widget.control.attrBool("showCheckboxColumn", false)!,
166
- sortAscending: widget.control.attrBool("sortAscending", false)!,
167
- sortColumnIndex: widget.control.attrInt("sortColumnIndex"),
168
- onSelectAll: widget.control.attrBool("onSelectAll", false)!
169
- ? (selected) {
170
- widget.backend.triggerControlEvent(
171
- widget.control.id,
172
- "select_all",
173
- selected != null ? selected.toString() : "");
174
- }
58
+ var datatable2 = DataTable2(
59
+ // scrollController: _controller,
60
+ // horizontalScrollController: _horizontalController,
61
+ decoration: decoration,
62
+ border: (horizontalLines != null || verticalLines != null)
63
+ ? TableBorder(
64
+ horizontalInside: horizontalLines ?? BorderSide.none,
65
+ verticalInside: verticalLines ?? BorderSide.none)
66
+ : null,
67
+ clipBehavior: widget.control.getClipBehavior("clip_behavior", Clip.none)!,
68
+ checkboxHorizontalMargin:
69
+ widget.control.getDouble("checkbox_horizontal_margin"),
70
+ columnSpacing: widget.control.getDouble("column_spacing"),
71
+ minWidth: widget.control.getDouble("min_width"),
72
+ bottomMargin: widget.control.getDouble("bottom_margin"),
73
+ empty: widget.control.buildWidget("empty"),
74
+ isHorizontalScrollBarVisible:
75
+ widget.control.getBool("visible_horizontal_scroll_bar"),
76
+ isVerticalScrollBarVisible:
77
+ widget.control.getBool("visible_vertical_scroll_bar"),
78
+ fixedLeftColumns: widget.control.getInt("fixed_left_columns", 0)!,
79
+ fixedTopRows: widget.control.getInt("fixed_top_rows", 1)!,
80
+ fixedColumnsColor:
81
+ widget.control.getColor("fixed_columns_color", context),
82
+ fixedCornerColor: widget.control.getColor("fixed_corner_color", context),
83
+ smRatio: widget.control.getDouble("sm_ratio", 0.67)!,
84
+ lmRatio: widget.control.getDouble("lm_ratio", 1.2)!,
85
+ sortArrowIcon:
86
+ widget.control.getIcon("sort_arrow_icon") ?? Icons.arrow_upward,
87
+ sortArrowAnimationDuration: widget.control.getDuration(
88
+ "sort_arrow_animation_duration", Duration(microseconds: 150))!,
89
+ checkboxAlignment:
90
+ widget.control.getAlignment("checkboxAlignment", Alignment.center)!,
91
+ headingCheckboxTheme: widget.control
92
+ .getCheckboxTheme("heading_checkbox_theme", Theme.of(context)),
93
+ datarowCheckboxTheme: widget.control
94
+ .getCheckboxTheme("data_row_checkbox_theme", Theme.of(context)),
95
+ showHeadingCheckBox:
96
+ widget.control.getBool("show_heading_checkbox", true)!,
97
+ dataRowColor: widget.control
98
+ .getWidgetStateColor("data_row_color", Theme.of(context)),
99
+ dataRowHeight: widget.control.getDouble("data_row_height"),
100
+ sortArrowIconColor:
101
+ widget.control.getColor("sort_arrow_icon_color", context),
102
+ dataTextStyle:
103
+ widget.control.getTextStyle("data_text_style", Theme.of(context)),
104
+ headingRowColor: widget.control
105
+ .getWidgetStateColor("heading_row_color", Theme.of(context)),
106
+ headingRowHeight: widget.control.getDouble("heading_row_height"),
107
+ headingTextStyle:
108
+ widget.control.getTextStyle("heading_text_style", Theme.of(context)),
109
+ headingRowDecoration:
110
+ widget.control.getBoxDecoration("heading_row_decoration", context),
111
+ dividerThickness: widget.control.getDouble("divider_thickness"),
112
+ horizontalMargin: widget.control.getDouble("horizontal_margin"),
113
+ showBottomBorder: widget.control.getBool("show_bottom_border", false)!,
114
+ showCheckboxColumn:
115
+ widget.control.getBool("show_checkbox_column", false)!,
116
+ sortAscending: widget.control.getBool("sort_ascending", false)!,
117
+ sortColumnIndex: widget.control.getInt("sort_column_index"),
118
+ onSelectAll: widget.control.getBool("on_select_all", false)!
119
+ ? (bool? selected) =>
120
+ widget.control.triggerEvent("select_all", selected)
121
+ : null,
122
+ columns: widget.control.children("columns").map((column) {
123
+ column.notifyParent = true;
124
+ var tooltip =
125
+ parseTooltip(column.get("tooltip"), context, const Placeholder());
126
+ return DataColumn2(
127
+ size: parseColumnSize(column.getString("size"), ColumnSize.S)!,
128
+ fixedWidth: column.getDouble("fixed_width"),
129
+ numeric: column.getBool("numeric", false)!,
130
+ tooltip: tooltip?.message,
131
+ headingRowAlignment:
132
+ column.getMainAxisAlignment("heading_row_alignment"),
133
+ onSort: column.getBool("on_sort", false)!
134
+ ? (columnIndex, ascending) => column
135
+ .triggerEvent("sort", {"ci": columnIndex, "asc": ascending})
175
136
  : null,
176
- columns: viewModel.controlViews
177
- .where((c) =>
178
- c.control.type == "datacolumn2" && c.control.isVisible)
179
- .map((column) {
180
- var labelCtrls = column.children
181
- .where((c) => c.name == "label" && c.isVisible);
182
- return DataColumn2(
183
- //size: ColumnSize.S,
184
- size: parseSize(
185
- column.control.attrString("size"), ColumnSize.S)!,
186
- fixedWidth: column.control.attrDouble("fixedWidth"),
187
- numeric: column.control.attrBool("numeric", false)!,
188
- tooltip: column.control.attrString("tooltip"),
189
- headingRowAlignment: parseMainAxisAlignment(
190
- column.control.attrString("headingRowAlignment")),
191
- //mouseCursor: WidgetStateMouseCursor.clickable,
192
- onSort: column.control.attrBool("onSort", false)!
193
- ? (columnIndex, ascending) {
194
- widget.backend.triggerControlEvent(
195
- column.control.id,
196
- "sort",
197
- json.encode({"i": columnIndex, "a": ascending}));
198
- }
199
- : null,
200
- label: ft.createControl(column.control, labelCtrls.first.id,
201
- column.control.isDisabled || tableDisabled));
202
- }).toList(),
203
- rows: viewModel.controlViews
204
- .where((c) => c.control.type == "datarow2" && c.control.isVisible)
205
- .map((row) {
206
- return DataRow2(
207
- key: ValueKey(row.control.id),
208
- selected: row.control.attrBool("selected", false)!,
209
- color: parseWidgetStateColor(
210
- Theme.of(context), row.control, "color"),
211
- specificRowHeight:
212
- row.control.attrDouble("specificRowHeight"),
213
- decoration: parseBoxDecoration(
214
- Theme.of(context), row.control, "decoration", pageArgs),
215
- onSelectChanged:
216
- row.control.attrBool("onSelectChanged", false)!
217
- ? (selected) {
218
- widget.backend.triggerControlEvent(
219
- row.control.id,
220
- "select_changed",
221
- selected != null ? selected.toString() : "");
222
- }
223
- : null,
224
- onLongPress: row.control.attrBool("onLongPress", false)!
225
- ? () {
226
- widget.backend.triggerControlEvent(
227
- row.control.id, "long_press");
228
- }
229
- : null,
230
- onDoubleTap: row.control.attrBool("onDoubleTap", false)!
231
- ? () {
232
- widget.backend.triggerControlEvent(
233
- row.control.id, "double_tap");
234
- }
235
- : null,
236
- onTap: row.control.attrBool("onTap", false)!
237
- ? () {
238
- widget.backend
239
- .triggerControlEvent(row.control.id, "tap");
240
- }
241
- : null,
242
- onSecondaryTap: row.control.attrBool("onSecondaryTap", false)!
243
- ? () {
244
- widget.backend.triggerControlEvent(
245
- row.control.id, "secondary_tap");
246
- }
247
- : null,
248
- onSecondaryTapDown:
249
- row.control.attrBool("onSecondaryTapDown", false)!
250
- ? (details) {
251
- widget.backend.triggerControlEvent(
252
- row.control.id, "secondary_tap_down");
253
- }
254
- : null,
255
- cells: row.children
256
- .where((c) => c.type == "datacell" && c.isVisible)
257
- .map((cell) => DataCell(
258
- ft.createControl(row.control, cell.childIds.first,
259
- row.control.isDisabled || tableDisabled),
260
- placeholder: cell.attrBool("placeholder", false)!,
261
- showEditIcon: cell.attrBool("showEditIcon", false)!,
262
- onDoubleTap: cell.attrBool("onDoubleTap", false)!
263
- ? () {
264
- widget.backend.triggerControlEvent(
265
- cell.id, "double_tap");
266
- }
267
- : null,
268
- onLongPress: cell.attrBool("onLongPress", false)!
269
- ? () {
270
- widget.backend.triggerControlEvent(
271
- cell.id, "long_press");
272
- }
273
- : null,
274
- onTap: cell.attrBool("onTap", false)!
275
- ? () {
276
- widget.backend
277
- .triggerControlEvent(cell.id, "tap");
278
- }
279
- : null,
280
- onTapCancel: cell.attrBool("onTapCancel", false)!
281
- ? () {
282
- widget.backend.triggerControlEvent(
283
- cell.id, "tap_cancel");
284
- }
285
- : null,
286
- onTapDown: cell.attrBool("onTapDown", false)!
287
- ? (details) {
288
- widget.backend.triggerControlEvent(
289
- cell.id,
290
- "tap_down",
291
- json.encode({
292
- "kind": details.kind?.name,
293
- "lx": details.localPosition.dx,
294
- "ly": details.localPosition.dy,
295
- "gx": details.globalPosition.dx,
296
- "gy": details.globalPosition.dy,
297
- }));
298
- }
299
- : null,
300
- ))
301
- .toList());
302
- }).toList());
303
- });
304
- });
137
+ label: column.buildTextOrWidget("label")!);
138
+ }).toList(),
139
+ rows: widget.control.children("rows").map((row) {
140
+ row.notifyParent = true;
141
+ return DataRow2(
142
+ key: ValueKey(row.id),
143
+ selected: row.getBool("selected", false)!,
144
+ color: row.getWidgetStateColor("color", Theme.of(context)),
145
+ specificRowHeight: row.getDouble("specific_row_height"),
146
+ decoration: row.getBoxDecoration("decoration", context),
147
+ onSelectChanged: row.getBool("on_select_change", false)!
148
+ ? (selected) => row.triggerEvent("select_change", selected)
149
+ : null,
150
+ onLongPress: row.getBool("on_long_press", false)!
151
+ ? () => row.triggerEvent("long_press")
152
+ : null,
153
+ onDoubleTap: row.getBool("on_double_tap", false)!
154
+ ? () => row.triggerEvent("double_tap")
155
+ : null,
156
+ onTap: row.getBool("on_tap", false)!
157
+ ? () => row.triggerEvent("tap")
158
+ : null,
159
+ onSecondaryTap: row.getBool("on_secondary_tap", false)!
160
+ ? () => row.triggerEvent("secondary_tap")
161
+ : null,
162
+ onSecondaryTapDown: row.getBool("on_secondary_tap_down", false)!
163
+ ? (details) =>
164
+ row.triggerEvent("secondary_tap_down", details.toMap())
165
+ : null,
166
+ cells: row.children("cells").map((cell) {
167
+ cell.notifyParent = true;
168
+ return DataCell(
169
+ cell.buildWidget("content")!,
170
+ placeholder: cell.getBool("placeholder", false)!,
171
+ showEditIcon: cell.getBool("show_edit_icon", false)!,
172
+ onDoubleTap: cell.getBool("on_double_tap", false)!
173
+ ? () => cell.triggerEvent("double_tap")
174
+ : null,
175
+ onLongPress: cell.getBool("on_long_press", false)!
176
+ ? () => cell.triggerEvent("long_press")
177
+ : null,
178
+ onTap: cell.getBool("on_tap", false)!
179
+ ? () => cell.triggerEvent("tap")
180
+ : null,
181
+ onTapCancel: cell.getBool("on_tap_cancel", false)!
182
+ ? () => cell.triggerEvent("tap_cancel")
183
+ : null,
184
+ onTapDown: cell.getBool("on_tap_down", false)!
185
+ ? (details) => cell.triggerEvent("tap_down", details.toMap())
186
+ : null,
187
+ );
188
+ }).toList(),
189
+ );
190
+ }).toList(),
191
+ );
305
192
 
306
- return constrainedControl(
307
- context, datatable, widget.parent, widget.control);
193
+ return ConstrainedControl(control: widget.control, child: datatable2);
308
194
  }
309
195
  }
@@ -0,0 +1,16 @@
1
+ import 'package:flet/flet.dart';
2
+ import 'package:flutter/widgets.dart';
3
+
4
+ import 'datatable2.dart';
5
+
6
+ class Extension extends FletExtension {
7
+ @override
8
+ Widget? createWidget(Key? key, Control control) {
9
+ switch (control.type) {
10
+ case "DataTable2":
11
+ return DataTable2Control(key: key, control: control);
12
+ default:
13
+ return null;
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,11 @@
1
+ import 'package:collection/collection.dart';
2
+ import 'package:data_table_2/data_table_2.dart';
3
+
4
+ ColumnSize? parseColumnSize(String? size, [ColumnSize? defValue]) {
5
+ if (size == null) {
6
+ return defValue;
7
+ }
8
+ return ColumnSize.values.firstWhereOrNull(
9
+ (e) => e.name.toLowerCase() == size.toLowerCase()) ??
10
+ defValue;
11
+ }