-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathplugin_tab.dart
More file actions
93 lines (77 loc) · 2.1 KB
/
plugin_tab.dart
File metadata and controls
93 lines (77 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import 'package:flex_tabs/flex_tabs.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:terminal_studio/src/core/plugin.dart';
import 'package:terminal_studio/src/core/state/host.dart';
class PluginTab extends TabItem {
final Plugin plugin;
final PluginManager manager;
PluginTab(this.plugin, this.manager) {
manager.add(plugin);
_updateTitle();
plugin.title.addListener(_updateTitle);
manager.addListener(_onPluginManagerChanged);
content.value = PluginTabView(
key: ValueKey(plugin),
plugin,
);
}
@override
void didDispose() {
if (plugin.mounted) {
manager.remove(plugin);
}
plugin.title.removeListener(_updateTitle);
manager.removeListener(_onPluginManagerChanged);
super.didDispose();
}
void _updateTitle() {
final titleWidget = plugin.title.value;
title.value = Row(
mainAxisSize: MainAxisSize.min,
children: [
if (titleWidget != null)
Flexible(
child: Text(
titleWidget,
softWrap: false,
),
),
if (titleWidget != null) const SizedBox(width: 4),
Text(
manager.hostSpec.name,
style: const TextStyle(
fontSize: 10,
color: CupertinoColors.systemGrey,
),
),
],
);
}
void _onPluginManagerChanged() {
if (!plugin.mounted) {
detach();
}
}
}
class PluginTabView extends ConsumerStatefulWidget {
const PluginTabView(this.plugin, {super.key});
final Plugin plugin;
@override
ConsumerState<ConsumerStatefulWidget> createState() => _PluginTabViewState();
}
class _PluginTabViewState extends ConsumerState<PluginTabView> {
Plugin get plugin => widget.plugin;
@override
void initState() {
SchedulerBinding.instance.addPostFrameCallback((_) {
ref.read(connectorProvider(plugin.hostSpec)).connect();
});
super.initState();
}
@override
Widget build(BuildContext context) {
return plugin.build(context);
}
}