mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2026-02-23 16:45:27 +01:00
Merge branch 'dev'
This commit is contained in:
@@ -9,7 +9,6 @@ import 'package:toolbox/core/channel/home_widget.dart';
|
||||
import 'package:toolbox/core/extension/build.dart';
|
||||
import 'package:toolbox/core/extension/context/locale.dart';
|
||||
import 'package:toolbox/core/route.dart';
|
||||
import 'package:toolbox/data/model/app/github_id.dart';
|
||||
import 'package:toolbox/data/model/app/tab.dart';
|
||||
import 'package:toolbox/data/res/build_data.dart';
|
||||
import 'package:toolbox/data/res/github_id.dart';
|
||||
@@ -17,6 +16,7 @@ import 'package:toolbox/data/res/misc.dart';
|
||||
import 'package:toolbox/data/res/provider.dart';
|
||||
import 'package:toolbox/data/res/store.dart';
|
||||
import 'package:toolbox/data/res/url.dart';
|
||||
import 'package:toolbox/view/page/ssh/page.dart';
|
||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||
|
||||
part 'appbar.dart';
|
||||
@@ -151,6 +151,7 @@ class _HomePageState extends State<HomePage>
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemBuilder: (_, index) => AppTab.values[index].page,
|
||||
onPageChanged: (value) {
|
||||
SSHPage.focusNode.unfocus();
|
||||
if (!_switchingPage) {
|
||||
_selectIndex.value = value;
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
_setting.primaryColor.put(color.value);
|
||||
context.pop();
|
||||
context.pop();
|
||||
RebuildNodes.app.rebuild();
|
||||
RNodes.app.build();
|
||||
}
|
||||
|
||||
// Widget _buildLaunchPage() {
|
||||
@@ -393,7 +393,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
);
|
||||
if (selected != null) {
|
||||
_setting.themeMode.put(selected);
|
||||
RebuildNodes.app.rebuild();
|
||||
RNodes.app.build();
|
||||
}
|
||||
},
|
||||
trailing: ValBuilder(
|
||||
@@ -442,7 +442,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
onPressed: () {
|
||||
_setting.fontPath.delete();
|
||||
context.pop();
|
||||
RebuildNodes.app.rebuild();
|
||||
RNodes.app.build();
|
||||
},
|
||||
child: Text(l10n.clear),
|
||||
)
|
||||
@@ -466,7 +466,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
}
|
||||
|
||||
context.pop();
|
||||
RebuildNodes.app.rebuild();
|
||||
RNodes.app.build();
|
||||
}
|
||||
|
||||
Widget _buildTermFontSize() {
|
||||
@@ -536,7 +536,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
if (selected != null) {
|
||||
_setting.locale.put(selected.code);
|
||||
context.pop();
|
||||
RebuildNodes.app.rebuild();
|
||||
RNodes.app.build();
|
||||
}
|
||||
},
|
||||
trailing: ListenBuilder(
|
||||
@@ -609,7 +609,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
subtitle: Text(l10n.fullScreenTip, style: UIs.textGrey),
|
||||
trailing: StoreSwitch(
|
||||
prop: _setting.fullScreen,
|
||||
callback: (_) => RebuildNodes.app.rebuild(),
|
||||
callback: (_) => RNodes.app.build(),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -820,7 +820,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
return;
|
||||
}
|
||||
_setting.textFactor.put(val);
|
||||
RebuildNodes.app.rebuild();
|
||||
RNodes.app.build();
|
||||
context.pop();
|
||||
}
|
||||
|
||||
|
||||
@@ -41,13 +41,15 @@ class SSHPage extends StatefulWidget {
|
||||
this.terminalKey,
|
||||
});
|
||||
|
||||
static final focusNode = FocusNode();
|
||||
|
||||
@override
|
||||
State<SSHPage> createState() => _SSHPageState();
|
||||
State<SSHPage> createState() => SSHPageState();
|
||||
}
|
||||
|
||||
const _horizonPadding = 7.0;
|
||||
|
||||
class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
|
||||
class SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
|
||||
final _keyboard = VirtKeyProvider();
|
||||
late final _terminal = Terminal(inputHandler: _keyboard);
|
||||
final TerminalController _terminalController = TerminalController();
|
||||
@@ -159,6 +161,7 @@ class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
|
||||
CustomAppBar.barHeight ?? _media.padding.top,
|
||||
),
|
||||
hideScrollBar: false,
|
||||
focusNode: SSHPage.focusNode,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:fl_lib/fl_lib.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:icons_plus/icons_plus.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:toolbox/core/extension/context/locale.dart';
|
||||
import 'package:toolbox/core/route.dart';
|
||||
@@ -15,37 +16,37 @@ class SSHTabPage extends StatefulWidget {
|
||||
State<SSHTabPage> createState() => _SSHTabPageState();
|
||||
}
|
||||
|
||||
typedef _TabMap = Map<String, ({Widget page, GlobalKey<SSHPageState>? key})>;
|
||||
|
||||
class _SSHTabPageState extends State<SSHTabPage>
|
||||
with TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
|
||||
late final _tabMap = <String, ({Widget page})>{
|
||||
l10n.add: (page: _buildAddPage()),
|
||||
late final _TabMap _tabMap = {
|
||||
l10n.add: (page: _buildAddPage(), key: null),
|
||||
};
|
||||
late var _tabController = TabController(
|
||||
length: _tabMap.length,
|
||||
vsync: this,
|
||||
);
|
||||
final _fabRN = ValueNotifier(0);
|
||||
final _pageCtrl = PageController();
|
||||
final _fabVN = 0.vn;
|
||||
final _tabRN = RNode();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return Scaffold(
|
||||
appBar: TabBar(
|
||||
controller: _tabController,
|
||||
tabs: _tabMap.keys.map(_buildTabItem).toList(),
|
||||
isScrollable: true,
|
||||
tabAlignment: TabAlignment.start,
|
||||
dividerColor: Colors.transparent,
|
||||
onTap: (value) {
|
||||
_fabRN.value = value;
|
||||
FocusScope.of(context).unfocus();
|
||||
appBar: PreferredSizeListenBuilder(
|
||||
listenable: _tabRN,
|
||||
builder: () {
|
||||
return _TabBar(
|
||||
idxVN: _fabVN,
|
||||
map: _tabMap,
|
||||
onTap: _onTapTab,
|
||||
onClose: _onTapClose,
|
||||
);
|
||||
},
|
||||
),
|
||||
body: _buildBody(),
|
||||
floatingActionButton: ListenableBuilder(
|
||||
listenable: _fabRN,
|
||||
listenable: _fabVN,
|
||||
builder: (_, __) {
|
||||
if (_fabRN.value != 0) return const SizedBox();
|
||||
if (_fabVN.value != 0) return const SizedBox();
|
||||
return FloatingActionButton(
|
||||
heroTag: 'sshAddServer',
|
||||
onPressed: () => AppRoutes.serverEdit().go(context),
|
||||
@@ -57,49 +58,37 @@ class _SSHTabPageState extends State<SSHTabPage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTabItem(String e) {
|
||||
if (e == l10n.add) {
|
||||
return Tab(child: Text(e));
|
||||
}
|
||||
return Tab(
|
||||
child: Row(
|
||||
children: [
|
||||
Text(e),
|
||||
UIs.width7,
|
||||
IconBtn(
|
||||
icon: Icons.close,
|
||||
onTap: () async {
|
||||
final confirm = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text(l10n.attention),
|
||||
content: Text('${l10n.close} SSH ${l10n.conn}($e) ?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(true),
|
||||
child: Text(l10n.ok, style: UIs.textRed),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => context.pop(false),
|
||||
child: Text(l10n.cancel),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
Future.delayed(const Duration(milliseconds: 50),
|
||||
FocusScope.of(context).unfocus);
|
||||
if (confirm != true) {
|
||||
return;
|
||||
}
|
||||
_tabMap.remove(e);
|
||||
_refreshTabs();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
void _onTapTab(int idx) async {
|
||||
await _toPage(idx);
|
||||
_fabVN.value = idx;
|
||||
FocusScope.of(context).unfocus();
|
||||
}
|
||||
|
||||
void _onTapClose(String name) async {
|
||||
final confirm = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text(l10n.attention),
|
||||
content: Text('${l10n.close} SSH ${l10n.conn}($name) ?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(true),
|
||||
child: Text(l10n.ok, style: UIs.textRed),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => context.pop(false),
|
||||
child: Text(l10n.cancel),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
Future.delayed(Durations.short1, FocusScope.of(context).unfocus);
|
||||
if (confirm != true) return;
|
||||
|
||||
_tabMap.remove(name);
|
||||
_tabRN.build();
|
||||
}
|
||||
|
||||
Widget _buildAddPage() {
|
||||
@@ -134,44 +123,155 @@ class _SSHTabPageState extends State<SSHTabPage>
|
||||
}
|
||||
|
||||
Widget _buildBody() {
|
||||
return TabBarView(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
controller: _tabController,
|
||||
children: _tabMap.values.map((e) => e.page).toList(),
|
||||
return ListenBuilder(
|
||||
listenable: _tabRN,
|
||||
builder: () {
|
||||
return PageView.builder(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
controller: _pageCtrl,
|
||||
itemCount: _tabMap.length,
|
||||
itemBuilder: (_, idx) {
|
||||
final name = _tabMap.keys.elementAt(idx);
|
||||
return _tabMap[name]?.page ?? UIs.placeholder;
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _onTapInitCard(ServerPrivateInfo spi) {
|
||||
void _onTapInitCard(ServerPrivateInfo spi) async {
|
||||
final name = () {
|
||||
if (_tabMap.containsKey(spi.name)) {
|
||||
return '${spi.name}(${_tabMap.length + 1})';
|
||||
final reg = RegExp(r'\((\d+)\)');
|
||||
final idxs = _tabMap.keys
|
||||
.map((e) => reg.firstMatch(e))
|
||||
.map((e) => e?.group(1))
|
||||
.where((e) => e != null);
|
||||
if (idxs.isEmpty) return spi.name;
|
||||
final biggest = idxs.reduce((a, b) => a!.length > b!.length ? a : b);
|
||||
final biggestInt = int.tryParse(biggest ?? '0');
|
||||
if (biggestInt != null && biggestInt > 0) {
|
||||
return '${spi.name}(${biggestInt + 1})';
|
||||
}
|
||||
return spi.name;
|
||||
}();
|
||||
final key = GlobalKey<SSHPageState>();
|
||||
_tabMap[name] = (
|
||||
page: SSHPage(
|
||||
// Keep it, or the Flutter will works unexpectedly
|
||||
key: key,
|
||||
spi: spi,
|
||||
notFromTab: false,
|
||||
onSessionEnd: () {
|
||||
_tabMap.remove(name);
|
||||
_refreshTabs();
|
||||
},
|
||||
),
|
||||
key: key,
|
||||
);
|
||||
_refreshTabs();
|
||||
final idx = _tabMap.length - 1;
|
||||
_tabController.animateTo(idx);
|
||||
_fabRN.value = idx;
|
||||
_tabRN.build();
|
||||
// Wait for the page to be built
|
||||
await Future.delayed(Durations.short3);
|
||||
final idx = _tabMap.keys.toList().indexOf(name);
|
||||
await _toPage(idx);
|
||||
_fabVN.value = idx;
|
||||
}
|
||||
|
||||
void _refreshTabs() {
|
||||
_tabController = TabController(
|
||||
length: _tabMap.length,
|
||||
vsync: this,
|
||||
);
|
||||
setState(() {});
|
||||
}
|
||||
Future<void> _toPage(int idx) => _pageCtrl.animateToPage(idx,
|
||||
duration: Durations.short3, curve: Curves.fastEaseInToSlowEaseOut);
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
|
||||
final class _TabBar extends StatelessWidget implements PreferredSizeWidget {
|
||||
const _TabBar({
|
||||
required this.idxVN,
|
||||
required this.map,
|
||||
required this.onTap,
|
||||
required this.onClose,
|
||||
});
|
||||
|
||||
final ValueNotifier<int> idxVN;
|
||||
final _TabMap map;
|
||||
final void Function(int idx) onTap;
|
||||
final void Function(String name) onClose;
|
||||
|
||||
List<String> get names => map.keys.toList();
|
||||
|
||||
@override
|
||||
Size get preferredSize => const Size.fromHeight(48);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListenBuilder(
|
||||
listenable: idxVN,
|
||||
builder: () {
|
||||
return ListView.separated(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 11, vertical: 5),
|
||||
itemCount: names.length,
|
||||
itemBuilder: (_, idx) => _buillItem(idx),
|
||||
separatorBuilder: (_, __) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 17),
|
||||
child: Container(
|
||||
color: const Color.fromARGB(61, 158, 158, 158),
|
||||
width: 3,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buillItem(int idx) {
|
||||
final name = names[idx];
|
||||
final selected = idxVN.value == idx;
|
||||
final color = selected ? null : Colors.grey;
|
||||
|
||||
final Widget child;
|
||||
if (idx == 0) {
|
||||
child = Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 13),
|
||||
child: Icon(MingCute.add_circle_fill, size: 17, color: color),
|
||||
);
|
||||
} else {
|
||||
final text = Text(
|
||||
name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: color),
|
||||
softWrap: false,
|
||||
textAlign: TextAlign.center,
|
||||
textWidthBasis: TextWidthBasis.parent,
|
||||
);
|
||||
child = AnimatedContainer(
|
||||
width: selected ? 90 : 50,
|
||||
duration: Durations.medium3,
|
||||
curve: Curves.fastEaseInToSlowEaseOut,
|
||||
child: switch (selected) {
|
||||
true => Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(width: 55, child: text),
|
||||
if (selected)
|
||||
FadeIn(
|
||||
child: IconBtn(
|
||||
icon: MingCute.close_circle_fill,
|
||||
color: color,
|
||||
onTap: () => onClose(name),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
false => Center(child: text),
|
||||
},
|
||||
).paddingOnly(left: 3, right: 3);
|
||||
}
|
||||
|
||||
return InkWell(
|
||||
borderRadius: BorderRadius.circular(13),
|
||||
onTap: () => onTap(idx),
|
||||
child: child,
|
||||
).paddingSymmetric(horizontal: 13);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user