Skip to content

Commit c2cb1d0

Browse files
authored
Merge pull request #511 from EnsembleUI/datagrid-issue
Changed border styling of data grid view
2 parents 22accf8 + df10796 commit c2cb1d0

File tree

2 files changed

+109
-34
lines changed

2 files changed

+109
-34
lines changed

assets/schema/ensemble_schema.json

+86
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,92 @@
12381238
}
12391239
]
12401240
},
1241+
"DataGrid-payload": {
1242+
"type": "object",
1243+
"allOf": [
1244+
{
1245+
"$ref": "#/$defs/DataRow-Templated-payload"
1246+
},
1247+
{
1248+
"properties": {
1249+
"children": {
1250+
"$ref": "#/$defs/DataRow"
1251+
},
1252+
"styles": {
1253+
"allOf": [
1254+
{
1255+
"$ref": "#/$defs/baseStyles"
1256+
},
1257+
{
1258+
"$ref": "#/$defs/boxLayoutStyles"
1259+
},
1260+
{
1261+
"headingTextStyle": {
1262+
"type": "object",
1263+
"description": "Set the text style for the heading text",
1264+
"$ref": "#/$defs/TextStyle"
1265+
},
1266+
"dataTextStyle": {
1267+
"type": "object",
1268+
"description": "Set the text style for the data item text",
1269+
"$ref": "#/$defs/TextStyle"
1270+
}
1271+
}
1272+
]
1273+
},
1274+
"horizontalMargin": {
1275+
"type": "integer",
1276+
"description": "The leading and trailing gap for the DataGrid view.",
1277+
"minimum": 0
1278+
},
1279+
"dataRowHeight": {
1280+
"type": "integer",
1281+
"description": "Set the height of the data row item.",
1282+
"minimum": 0
1283+
},
1284+
"headingRowHeight": {
1285+
"type": "integer",
1286+
"description": "Set the height of the heading row item.",
1287+
"minimum": 0
1288+
},
1289+
"columnSpacing": {
1290+
"type": "number",
1291+
"description": "Set the padding for the column.",
1292+
"minimum": 0
1293+
}
1294+
}
1295+
}
1296+
]
1297+
},
1298+
"DataRow-Templated-payload": {
1299+
"type": "object",
1300+
"properties": {
1301+
"item-template": {
1302+
"type": "object",
1303+
"properties": {
1304+
"data": {
1305+
"type": "string",
1306+
"description": "Bind to an array of data from an API response or a variable"
1307+
},
1308+
"name": {
1309+
"type": "string",
1310+
"description": "Set the name to reference as you iterate through the array of data"
1311+
},
1312+
"template": {
1313+
"$ref": "#/$defs/DataRow",
1314+
"description": "The data row widget to render for each item"
1315+
}
1316+
}
1317+
}
1318+
}
1319+
},
1320+
"DataRow": {
1321+
"type": "array",
1322+
"description": "List of widgets",
1323+
"items": {
1324+
"$ref": "#/$defs/Widget"
1325+
}
1326+
},
12411327
"Stack-payload": {
12421328
"type": "object",
12431329
"required": ["children"],

lib/layout/data_grid.dart

+23-34
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,6 @@ class DataGrid extends StatefulWidget
6262
'DataColumns': (List cols) {
6363
this.cols = cols;
6464
},
65-
'headingTextStyle': (Map styles) {
66-
controller.headingTextController = TextController();
67-
TextUtils.setStyles(styles, controller.headingTextController!);
68-
},
69-
'dataTextStyle': (Map styles) {
70-
controller.dataTextController = TextController();
71-
TextUtils.setStyles(styles, controller.dataTextController!);
72-
},
7365
'horizontalMargin': (val) =>
7466
controller.horizontalMargin = Utils.optionalDouble(val),
7567
'dataRowHeight': (val) =>
@@ -80,29 +72,6 @@ class DataGrid extends StatefulWidget
8072
controller.columnSpacing = Utils.optionalDouble(val),
8173
'dividerThickness': (val) =>
8274
controller.dividerThickness = Utils.optionalDouble(val),
83-
'border': (Map val) {
84-
Map<String, dynamic> map = {};
85-
val.forEach((key, value) {
86-
if (value is Map) {
87-
Color color = Utils.getColor(value['color']) ?? Colors.black;
88-
double width = Utils.getDouble(value['width'], fallback: 1.0);
89-
map[key] = BorderSide(color: color, width: width);
90-
} else if (key == 'borderRadius') {
91-
double? radius = Utils.optionalDouble(value);
92-
map[key] = (radius == null)
93-
? BorderRadius.zero
94-
: BorderRadius.circular(radius);
95-
}
96-
});
97-
controller.border = TableBorder(
98-
top: map['top'] ?? BorderSide.none,
99-
right: map['right'] ?? BorderSide.none,
100-
bottom: map['bottom'] ?? BorderSide.none,
101-
left: map['left'] ?? BorderSide.none,
102-
horizontalInside: map['horizontalInside'] ?? BorderSide.none,
103-
verticalInside: map['verticalInside'] ?? BorderSide.none,
104-
borderRadius: map['borderRadius'] ?? BorderRadius.zero);
105-
},
10675
};
10776
}
10877
}
@@ -173,7 +142,7 @@ class EnsembleDataRowState extends State<EnsembleDataRow> {
173142
}
174143
}
175144

176-
class DataGridController extends WidgetController {
145+
class DataGridController extends BoxController {
177146
List<Widget>? children;
178147
double? horizontalMargin;
179148
TextController? headingTextController;
@@ -182,7 +151,22 @@ class DataGridController extends WidgetController {
182151
double? columnSpacing;
183152
TextController? dataTextController;
184153
double? dividerThickness;
185-
TableBorder border = const TableBorder();
154+
155+
@override
156+
Map<String, Function> getBaseSetters() {
157+
Map<String, Function> setters = super.getBaseSetters();
158+
setters.addAll({
159+
'headingText': (Map styles) {
160+
headingTextController = TextController();
161+
TextUtils.setStyles(styles, headingTextController!);
162+
},
163+
'dataText': (Map styles) {
164+
dataTextController = TextController();
165+
TextUtils.setStyles(styles, dataTextController!);
166+
},
167+
});
168+
return setters;
169+
}
186170
}
187171

188172
class DataGridState extends WidgetState<DataGrid> with TemplatedWidgetState {
@@ -317,7 +301,12 @@ class DataGridState extends WidgetState<DataGrid> with TemplatedWidgetState {
317301
dataTextStyle: dataTextStyle,
318302
columnSpacing: widget.controller.columnSpacing,
319303
dividerThickness: widget.controller.dividerThickness,
320-
border: widget.controller.border,
304+
border: TableBorder.all(
305+
color: widget.controller.borderColor ?? Colors.black,
306+
width: widget.controller.borderWidth?.toDouble() ?? 1.0,
307+
borderRadius:
308+
widget.controller.borderRadius?.getValue() ?? BorderRadius.zero,
309+
),
321310
);
322311
return SingleChildScrollView(
323312
scrollDirection: Axis.vertical,

0 commit comments

Comments
 (0)