feat: custom server logo
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:extended_image/extended_image.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:icons_plus/icons_plus.dart';
|
||||
@@ -11,6 +12,7 @@ import 'package:toolbox/data/model/app/shell_func.dart';
|
||||
import 'package:toolbox/data/model/server/battery.dart';
|
||||
import 'package:toolbox/data/model/server/cpu.dart';
|
||||
import 'package:toolbox/data/model/server/disk.dart';
|
||||
import 'package:toolbox/data/model/server/dist.dart';
|
||||
import 'package:toolbox/data/model/server/net_speed.dart';
|
||||
import 'package:toolbox/data/model/server/nvdia.dart';
|
||||
import 'package:toolbox/data/model/server/sensors.dart';
|
||||
@@ -100,6 +102,13 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
|
||||
Widget _buildMainPage(Server si) {
|
||||
final buildFuncs = !Stores.setting.moveOutServerTabFuncBtns.fetch();
|
||||
final logoUrl = si.spi.custom?.logoUrl;
|
||||
final listLen = () {
|
||||
var len = _cardsOrder.length;
|
||||
if (buildFuncs) len++;
|
||||
if (logoUrl != null) len++;
|
||||
return len;
|
||||
}();
|
||||
return Scaffold(
|
||||
appBar: CustomAppBar(
|
||||
title: Text(si.spi.name, style: UIs.text18),
|
||||
@@ -121,11 +130,15 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
right: 13,
|
||||
bottom: _media.padding.bottom + 77,
|
||||
),
|
||||
itemCount: buildFuncs ? _cardsOrder.length + 1 : _cardsOrder.length,
|
||||
itemCount: listLen,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == 0 && buildFuncs) {
|
||||
if (index == 0 && logoUrl != null) {
|
||||
return _buildLogo(logoUrl, si.status.more[StatusCmdType.sys]?.dist);
|
||||
}
|
||||
if (index == 1 && buildFuncs) {
|
||||
return ServerFuncBtns(spi: widget.spi);
|
||||
}
|
||||
if (logoUrl != null) index--;
|
||||
if (buildFuncs) index--;
|
||||
return _cardBuildMap[_cardsOrder[index]]?.call(si.status);
|
||||
},
|
||||
@@ -133,6 +146,20 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLogo(String logoUrl, Dist? dist) {
|
||||
if (dist != null) {
|
||||
logoUrl = logoUrl.replaceFirst('{DIST}', dist.name);
|
||||
}
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 13),
|
||||
child: ExtendedImage.network(
|
||||
logoUrl,
|
||||
cache: true,
|
||||
height: _media.size.height * 0.2,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAbout(ServerStatus ss) {
|
||||
return CardX(
|
||||
child: ExpandTile(
|
||||
|
||||
@@ -43,6 +43,7 @@ class _ServerEditPageState extends State<ServerEditPage> {
|
||||
final _pveAddrCtrl = TextEditingController();
|
||||
final _customCmdCtrl = TextEditingController();
|
||||
final _preferTempDevCtrl = TextEditingController();
|
||||
final _logoUrlCtrl = TextEditingController();
|
||||
|
||||
final _nameFocus = FocusNode();
|
||||
final _ipFocus = FocusNode();
|
||||
@@ -96,6 +97,7 @@ class _ServerEditPageState extends State<ServerEditPage> {
|
||||
}
|
||||
} catch (_) {}
|
||||
_preferTempDevCtrl.text = custom.preferTempDev ?? '';
|
||||
_logoUrlCtrl.text = custom.logoUrl ?? '';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -117,6 +119,7 @@ class _ServerEditPageState extends State<ServerEditPage> {
|
||||
_pveAddrCtrl.dispose();
|
||||
_customCmdCtrl.dispose();
|
||||
_preferTempDevCtrl.dispose();
|
||||
_logoUrlCtrl.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -367,6 +370,16 @@ class _ServerEditPageState extends State<ServerEditPage> {
|
||||
return ExpandTile(
|
||||
title: Text(l10n.more),
|
||||
children: [
|
||||
const Text('Logo', style: UIs.text13Grey),
|
||||
UIs.height7,
|
||||
Input(
|
||||
controller: _logoUrlCtrl,
|
||||
type: TextInputType.url,
|
||||
icon: Icons.image,
|
||||
label: 'Url',
|
||||
hint: 'https://example.com/logo.png',
|
||||
),
|
||||
UIs.height7,
|
||||
const Text('PVE', style: UIs.text13Grey),
|
||||
UIs.height7,
|
||||
Input(
|
||||
@@ -528,6 +541,7 @@ class _ServerEditPageState extends State<ServerEditPage> {
|
||||
pveIgnoreCert: _pveIgnoreCert.value,
|
||||
cmds: customCmds,
|
||||
preferTempDev: _preferTempDevCtrl.text.selfIfNotNullEmpty,
|
||||
logoUrl: _logoUrlCtrl.text.selfIfNotNullEmpty,
|
||||
);
|
||||
|
||||
final spi = ServerPrivateInfo(
|
||||
|
||||
@@ -281,7 +281,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
}
|
||||
},
|
||||
onLongPress: () {
|
||||
if (srv.state == ServerState.finished) {
|
||||
if (srv.conn == ServerConn.finished) {
|
||||
final id = srv.spi.id;
|
||||
final cardStatus = _getCardNoti(id);
|
||||
cardStatus.value = cardStatus.value.copyWith(
|
||||
@@ -319,7 +319,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
listenable: cardStatus,
|
||||
builder: (_, __) {
|
||||
final List<Widget> children = [title];
|
||||
if (srv.state == ServerState.finished) {
|
||||
if (srv.conn == ServerConn.finished) {
|
||||
if (cardStatus.value.flip) {
|
||||
children.addAll(_buildFlippedCard(srv));
|
||||
} else {
|
||||
@@ -330,7 +330,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 377),
|
||||
curve: Curves.fastEaseInToSlowEaseOut,
|
||||
height: _calcCardHeight(srv.state, cardStatus.value.flip),
|
||||
height: _calcCardHeight(srv.conn, cardStatus.value.flip),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
@@ -461,10 +461,10 @@ class _ServerPageState extends State<ServerPage>
|
||||
}
|
||||
|
||||
Widget _buildTopRightWidget(Server s) {
|
||||
return switch (s.state) {
|
||||
ServerState.connecting ||
|
||||
ServerState.loading ||
|
||||
ServerState.connected =>
|
||||
return switch (s.conn) {
|
||||
ServerConn.connecting ||
|
||||
ServerConn.loading ||
|
||||
ServerConn.connected =>
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 7),
|
||||
child: SizedBox(
|
||||
@@ -476,7 +476,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
),
|
||||
),
|
||||
),
|
||||
ServerState.failed => InkWell(
|
||||
ServerConn.failed => InkWell(
|
||||
onTap: () {
|
||||
TryLimiter.reset(s.spi.id);
|
||||
Pros.server.refresh(spi: s.spi);
|
||||
@@ -490,7 +490,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
),
|
||||
),
|
||||
),
|
||||
ServerState.disconnected when !(s.spi.autoConnect ?? true) => InkWell(
|
||||
ServerConn.disconnected when !(s.spi.autoConnect ?? true) => InkWell(
|
||||
onTap: () => Pros.server.refresh(spi: s.spi),
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 7),
|
||||
@@ -508,7 +508,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
}
|
||||
|
||||
Widget _buildTopRightText(Server s) {
|
||||
final hasErr = s.state == ServerState.failed && s.status.err != null;
|
||||
final hasErr = s.conn == ServerConn.failed && s.status.err != null;
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (!hasErr) return;
|
||||
@@ -636,9 +636,9 @@ class _ServerPageState extends State<ServerPage>
|
||||
_tag == null || (pro.pick(id: e)?.spi.tags?.contains(_tag) ?? false))
|
||||
.toList();
|
||||
|
||||
double? _calcCardHeight(ServerState cs, bool flip) {
|
||||
double? _calcCardHeight(ServerConn cs, bool flip) {
|
||||
if (_textFactorDouble != 1.0) return null;
|
||||
if (cs != ServerState.finished) {
|
||||
if (cs != ServerConn.finished) {
|
||||
return 23.0;
|
||||
}
|
||||
if (flip) {
|
||||
|
||||
Reference in New Issue
Block a user