Multi split view
A widget to provides horizontal or vertical multiple split view for Flutter.
MultiSplitView(children: [child1, child2, child3]);
MultiSplitView(axis: Axis.vertical, children: [child1, child2]);
MultiSplitView(axis: Axis.vertical, children: [
MultiSplitView(children: [child1, child2, child3]),
child4
]);
// setting 10% of weight for the first child
MultiSplitView(
children: [child1, child2, child3],
controller: MultiSplitViewController(weights: [0.1]));
MultiSplitView(axis: Axis.vertical, children: [
MultiSplitView(children: [child1, child2], minimalWeight: .40),
MultiSplitView(children: [child3, child4])
]);
Used if minimalWeight has not been set. The size will be converted into weight and will respect the limit defined by the MultiSplitView.defaultMinimalWeight constant, allowing all children to be visible.
MultiSplitView(axis: Axis.vertical, children: [
MultiSplitView(children: [child1, child2], minimalSize: 100),
MultiSplitView(children: [child3, child4])
]);
MultiSplitView(children: [child1, child2, child3], resizable: false);
MultiSplitView(
children: [child1, child2, child3, child4],
onSizeChange: (childIndex1, childIndex2) => print(
'Index of children whose size has changed: $childIndex1 and $childIndex2'));
The default color is NULL.
MultiSplitView(
children: [child1, child2], dividerColor: Colors.black);
MultiSplitView(
children: [child1, child2, child3], dividerThickness: 30);
var dividerPainter = (Axis axis, bool resizable, bool highlighted, Canvas canvas, Size size) {
var paint = Paint()
..style = PaintingStyle.stroke
..color = Colors.black
..isAntiAlias = true;
if (axis == Axis.vertical) {
double dashHeight = 9, dashSpace = 5, startY = 0;
while (startY < size.height) {
canvas.drawLine(Offset(size.width / 2, startY),
Offset(size.width / 2, startY + dashHeight), paint);
startY += dashHeight + dashSpace;
}
} else {
double dashWidth = 9, dashSpace = 5, startX = 0;
while (startX < size.width) {
canvas.drawLine(Offset(startX, size.height / 2),
Offset(startX + dashWidth, size.height / 2), paint);
startX += dashWidth + dashSpace;
}
}
};
MultiSplitView(
axis: Axis.vertical,
children: [
MultiSplitView(
children: [child1, child2, child3],
dividerThickness: 10,
dividerPainter: dividerPainter),
child4
],
dividerThickness: 10,
dividerPainter: dividerPainter);
Run this command:
With Flutter:
$ flutter pub add multi_split_view
This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get):
dependencies:
multi_split_view: ^1.6.0
Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:multi_split_view/multi_split_view.dart';
import 'dart:math';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:multi_split_view/multi_split_view.dart';
void main() => runApp(MultiSplitViewExampleApp());
class MultiSplitViewExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MultiSplitViewExample(),
);
}
}
class MultiSplitViewExample extends StatefulWidget {
final List<Color> _colors = [
Colors.red,
Colors.blue,
Colors.green,
Colors.purple,
Colors.brown,
Colors.pinkAccent
];
@override
_MultiSplitViewExampleState createState() => _MultiSplitViewExampleState();
}
class _MultiSplitViewExampleState extends State<MultiSplitViewExample> {
final int _max = 40;
int _horizontalVisibleWidgets = 3;
MultiSplitViewController controller =
MultiSplitViewController(weights: [0.01]);
@override
Widget build(BuildContext context) {
Widget buttons = Container(
child: Row(children: [
Text('Horizontal widgets: $_horizontalVisibleWidgets / $_max'),
SizedBox(width: 16),
ElevatedButton(child: Text('Add'), onPressed: _onAddButtonClick),
SizedBox(width: 16),
ElevatedButton(child: Text('Remove'), onPressed: _onRemoveButtonClick)
], crossAxisAlignment: CrossAxisAlignment.center),
color: Colors.white,
padding: EdgeInsets.all(8));
List<Widget> children = List.empty(growable: true);
for (int i = 0; i < _horizontalVisibleWidgets; i++) {
Widget view = Container(
child: Center(child: Text("View " + (i + 1).toString())),
color: widget._colors[i % widget._colors.length],
);
children.add(view);
}
MultiSplitView multiSplitView = MultiSplitView(
children: children,
controller: controller,
onSizeChange: _onSizeChange);
return Scaffold(
appBar: AppBar(title: Text('Multi Split View Example')),
body: Column(children: [buttons, Expanded(child: multiSplitView)])
// body: horizontal,
);
}
_onSizeChange(int childIndex1, int childIndex2) {
print('change - childIndex1: $childIndex1 - childIndex2: $childIndex2');
}
_onRemoveButtonClick() {
setState(() {
_horizontalVisibleWidgets = max(0, _horizontalVisibleWidgets - 1);
});
}
_onAddButtonClick() {
setState(() {
_horizontalVisibleWidgets = min(_max, _horizontalVisibleWidgets + 1);
});
}
}
Author: caduandrade
Official Website: https://github.com/caduandrade/multi_split_view