splitPanel method
- @action
- required String panelId,
- String? tabId,
- Axis axis = Axis.horizontal,
- TabPosition? position,
Splits the current panel in two, moving the tabs to the one specified by position
Implementation
@action
void splitPanel({
required String panelId,
String? tabId,
Axis axis = Axis.horizontal,
TabPosition? position,
}) {
final newPanel =
TabPanel(parent: this as TabPanel, defaultPage: defaultPage);
// If the panel has a parent with the same axis as the one requested,
// we insert a new panel into the parent instead of splitting this one
if (parent != null &&
parent?.axis == axis &&
(parent?.panels.isNotEmpty ?? false)) {
newPanel.parent = parent;
final index = parent!.panels.indexWhere((element) => element.id == id);
if (index == -1) {
parent!.panels.add(newPanel);
} else {
parent!.panels.insert(index, newPanel);
}
return;
}
if (panels.isEmpty) {
this.axis = axis;
// Create a copy of the current panel, and update its tabs to point to the new panel
final oldPanel = TabPanel(
parent: this as TabPanel,
tabs: tabs,
defaultPage: defaultPage,
);
oldPanel.tabs.forEach((element) => element.panel = oldPanel);
// Set the two panels depending on the position
panels = position == TabPosition.after
? <TabPanel>[oldPanel, newPanel].asObservable()
: <TabPanel>[newPanel, oldPanel].asObservable();
// This panel now has child panels so we clear the tabs
tabs = <Tab>[].asObservable();
selectedTab = 0;
}
}