build method
- @override
- BuildContext context,
- ViewsModel model
override
Builds the UI according to the state in model
.
Implementation
@override
Widget build(BuildContext context, ViewsModel model) {
final childData = List<ResizableChild>.generate(
(model.views.length > 1) ? model.views.length : 0,
(index) => ResizableChild(
minSize: 100,
child: _ViewArea(model: model, index: index),
),
);
return switch (model.views.length) {
1 => Column(
children: [
Expanded(child: _ViewArea(model: model, index: 0)),
],
),
2 => ResizableContainer(
direction: switch (models.settings.dashboard.splitMode) {
SplitMode.horizontal => Axis.vertical,
SplitMode.vertical => Axis.horizontal,
},
divider: const ResizableDivider(thickness: 8, color: Colors.black),
controller: switch (models.settings.dashboard.splitMode) {
SplitMode.horizontal => model.verticalController,
SplitMode.vertical => model.horizontalController1,
},
children: childData.sublist(0, 2),
),
3 || 4 => ResizableContainer(
controller: model.verticalController,
direction: Axis.vertical,
divider: const ResizableDivider(thickness: 8, color: Colors.black),
children: [
ResizableChild(
minSize: 100,
child: ResizableContainer(
controller: model.horizontalController1,
divider: const ResizableDivider(thickness: 8, color: Colors.black),
direction: Axis.horizontal,
children: childData.sublist(0, 2),
),
),
if (model.views.length == 3)
childData[2]
else
ResizableChild(
minSize: 100,
child: ResizableContainer(
controller: model.horizontalController2,
direction: Axis.horizontal,
divider: const ResizableDivider(thickness: 8, color: Colors.black),
children: childData.sublist(2, 4),
),
),
],
),
8 => Row(
children: [
Expanded(
child: ResizableContainer(
controller: model.verticalController,
direction: Axis.vertical,
divider: const ResizableDivider(thickness: 8, color: Colors.black),
children: [
ResizableChild(
minSize: 100,
child: ResizableContainer(
controller: model.horizontalController1,
direction: Axis.horizontal,
divider: const ResizableDivider(thickness: 8, color: Colors.black),
children: childData.sublist(0, 2),
),
),
ResizableChild(
minSize: 100,
child: ResizableContainer(
controller: model.horizontalController2,
direction: Axis.horizontal,
divider: const ResizableDivider(thickness: 8, color: Colors.black),
children: childData.sublist(2, 4),
),
),
],
),
),
const VerticalDivider(
width: 8,
color: Colors.black,
thickness: 8,
),
Expanded(
child: ResizableContainer(
controller: model.verticalController2,
direction: Axis.vertical,
divider: const ResizableDivider(thickness: 8, color: Colors.black),
children: [
ResizableChild(
minSize: 100,
child: ResizableContainer(
controller: model.horizontalController3,
direction: Axis.horizontal,
divider: const ResizableDivider(thickness: 8, color: Colors.black),
children: childData.sublist(4, 6),
),
),
ResizableChild(
minSize: 100,
child: ResizableContainer(
controller: model.horizontalController4,
direction: Axis.horizontal,
divider: const ResizableDivider(thickness: 8, color: Colors.black),
children: childData.sublist(6, 8),
),
),
],
),
),
],
),
_ => throw StateError("Too many views: ${model.views.length}"),
};
}