Skip to content

Commit 65babaa

Browse files
committed
✨: refactor DockingView to streamline item addition and improve error handling in home screen
1 parent 057a52b commit 65babaa

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

lib/constant.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class DockingView {
2020
static DockingItem setting =
2121
DockingItem(name: 'setting', weight: 0.2, widget: SettingView());
2222

23-
static DockingItem createFFC() => DockingItem(name: 'fcc', weight: 0.2, widget: FleetForcesCommand());
23+
static DockingItem createFFC() => DockingItem(name: 'fcc', weight: 0.2, widget: FleetForcesCommand());
2424

2525
static DockingItem createDryDock() => DockingItem(name: 'drydock', weight: 0.2, widget: Drydock());
2626

lib/screens/home.dart

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class _HomeViewState extends State<HomeView>
2222
root: DockingTabs([
2323
DockingView.webView,
2424
DockingView.setting,
25-
]),
25+
], id: 'root'),
2626
);
2727
try {
2828
_layout.load(layout: '', parser: this, builder: this);
@@ -41,14 +41,12 @@ class _HomeViewState extends State<HomeView>
4141
PlatformMenuItem(
4242
label: 'add',
4343
onSelected: () {
44-
//setState(() {
4544
_layout.addItemOnRoot(
4645
newItem: DockingItem(
4746
name: '3',
4847
weight: 0.2,
4948
widget: Center(child: Text('1'))),
5049
dropPosition: DropPosition.top);
51-
//});
5250
},
5351
),
5452
PlatformMenuItem(
@@ -67,19 +65,15 @@ class _HomeViewState extends State<HomeView>
6765
PlatformMenuItem(
6866
label: 'FleetForcesCommand',
6967
onSelected: () {
70-
_layout.addItemOnRoot(
71-
newItem: DockingView.createFFC(),
72-
dropPosition: DropPosition.top);
68+
addItemOnWebview(DockingView.createFFC());
7369
},
7470
),
7571
PlatformMenuItemGroup(members: [
7672
PlatformMenu(label: 'fleet', menus: [
7773
PlatformMenuItem(
7874
label: 'dry dock',
7975
onSelected: () {
80-
_layout.addItemOnRoot(
81-
newItem: DockingView.createDryDock(),
82-
dropPosition: DropPosition.top);
76+
addItemOnWebview(DockingView.createDryDock());
8377
},
8478
),
8579
PlatformMenuItem(
@@ -89,23 +83,15 @@ class _HomeViewState extends State<HomeView>
8983
PlatformMenuItem(
9084
label: 'quest',
9185
onSelected: () {
92-
try {
93-
_layout.addItemOnRoot(
94-
newItem: DockingView.createQuestlist(),
95-
dropPosition: DropPosition.top);
96-
} catch (e) {
97-
print(e);
98-
}
86+
addItemOnWebview(DockingView.createQuestlist());
9987
},
10088
),
10189
]),
10290
]),
10391
PlatformMenuItem(
10492
label: 'quest',
10593
onSelected: () {
106-
_layout.addItemOnRoot(
107-
newItem: DockingView.createQuestlist(),
108-
dropPosition: DropPosition.top);
94+
addItemOnWebview(DockingView.createQuestlist());
10995
},
11096
),
11197
]),
@@ -138,4 +124,14 @@ class _HomeViewState extends State<HomeView>
138124
widget: Center(child: Text(id)),
139125
);
140126
}
127+
128+
void addItemOnWebview(DockingItem newItem) {
129+
try {
130+
DockingTabs root = _layout.findDockingArea('root') as DockingTabs;
131+
_layout.addItemOn(
132+
newItem: newItem, targetArea: root, dropIndex: root.childrenCount);
133+
} catch (e) {
134+
print(e);
135+
}
136+
}
141137
}

0 commit comments

Comments
 (0)