mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
fix & opt
fix: whether display docker edit host opt: docker funcs
This commit is contained in:
@@ -42,10 +42,6 @@ class MyApp extends StatelessWidget {
|
||||
final radioTheme = RadioThemeData(
|
||||
fillColor: materialColor,
|
||||
);
|
||||
final iconBtnTheme = IconButtonThemeData(
|
||||
style: ButtonStyle(
|
||||
iconColor: primaryColor.materialStateColor,
|
||||
));
|
||||
|
||||
return MaterialApp(
|
||||
localizationsDelegates: const [
|
||||
@@ -61,7 +57,6 @@ class MyApp extends StatelessWidget {
|
||||
appBarTheme: appBarTheme,
|
||||
floatingActionButtonTheme: fabTheme,
|
||||
iconTheme: iconTheme,
|
||||
iconButtonTheme: iconBtnTheme,
|
||||
primaryIconTheme: iconTheme,
|
||||
switchTheme: switchTheme,
|
||||
inputDecorationTheme: inputDecorationTheme,
|
||||
@@ -71,7 +66,6 @@ class MyApp extends StatelessWidget {
|
||||
useMaterial3: false,
|
||||
floatingActionButtonTheme: fabTheme,
|
||||
iconTheme: iconTheme,
|
||||
iconButtonTheme: iconBtnTheme,
|
||||
primaryIconTheme: iconTheme,
|
||||
switchTheme: switchTheme,
|
||||
inputDecorationTheme: inputDecorationTheme,
|
||||
|
||||
@@ -53,6 +53,7 @@ class DockerProvider extends BusyProvider {
|
||||
}
|
||||
|
||||
Future<void> refresh() async {
|
||||
if (isBusy) return;
|
||||
final verRaw = await client!.run('docker version'.withLangExport).string;
|
||||
if (verRaw.contains(_dockerNotFound)) {
|
||||
error = DockerErr(type: DockerErrType.notInstalled);
|
||||
|
||||
@@ -61,32 +61,32 @@ class _DockerManagePageState extends State<DockerManagePage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<DockerProvider>(builder: (_, docker, __) {
|
||||
return Consumer<DockerProvider>(builder: (_, ___, __) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
title: TwoLineText(up: 'Docker', down: widget.spi.name),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () => docker.refresh(),
|
||||
onPressed: () => _docker.refresh(),
|
||||
icon: const Icon(Icons.refresh),
|
||||
)
|
||||
],
|
||||
),
|
||||
body: _buildMain(docker),
|
||||
floatingActionButton: _buildFAB(docker),
|
||||
body: _buildMain(),
|
||||
floatingActionButton: _buildFAB(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildFAB(DockerProvider docker) {
|
||||
Widget _buildFAB() {
|
||||
return FloatingActionButton(
|
||||
onPressed: () async => await _showAddFAB(docker),
|
||||
onPressed: () async => await _showAddFAB(),
|
||||
child: const Icon(Icons.add),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _showAddFAB(DockerProvider docker) async {
|
||||
Future<void> _showAddFAB() async {
|
||||
final imageCtrl = TextEditingController();
|
||||
final nameCtrl = TextEditingController();
|
||||
final argsCtrl = TextEditingController();
|
||||
@@ -233,9 +233,8 @@ class _DockerManagePageState extends State<DockerManagePage> {
|
||||
return _textController.text.trim();
|
||||
}
|
||||
|
||||
Widget _buildMain(DockerProvider docker) {
|
||||
final running = docker.items;
|
||||
if (docker.error != null && running == null) {
|
||||
Widget _buildMain() {
|
||||
if (_docker.error != null && _docker.items == null) {
|
||||
return SizedBox.expand(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
@@ -246,17 +245,17 @@ class _DockerManagePageState extends State<DockerManagePage> {
|
||||
size: 37,
|
||||
),
|
||||
const SizedBox(height: 27),
|
||||
_buildErr(docker.error!),
|
||||
_buildErr(_docker.error!),
|
||||
const SizedBox(height: 27),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(17),
|
||||
child: _buildSolution(docker.error!),
|
||||
child: _buildSolution(_docker.error!),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
if (running == null) {
|
||||
if (_docker.items == null || _docker.images == null) {
|
||||
_docker.refresh();
|
||||
return centerLoading;
|
||||
}
|
||||
@@ -264,73 +263,74 @@ class _DockerManagePageState extends State<DockerManagePage> {
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(7),
|
||||
children: [
|
||||
_buildLoading(docker),
|
||||
_buildLoading(),
|
||||
_buildVersion(
|
||||
docker.edition ?? _s.unknown, docker.version ?? _s.unknown),
|
||||
_buildPsItems(running, docker),
|
||||
_buildImages(docker),
|
||||
_buildEditHost(running, docker),
|
||||
_docker.edition ?? _s.unknown, _docker.version ?? _s.unknown),
|
||||
_buildPsItems(),
|
||||
_buildImages(),
|
||||
_buildEditHost(),
|
||||
].map((e) => RoundRectCard(e)).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildImages(DockerProvider docker) {
|
||||
if (docker.images == null) {
|
||||
Widget _buildImages() {
|
||||
if (_docker.images == null) {
|
||||
return const SizedBox();
|
||||
}
|
||||
return ExpansionTile(
|
||||
title: Text(_s.imagesList),
|
||||
subtitle: Text(
|
||||
_s.dockerImagesFmt(docker.images!.length),
|
||||
style: grey,
|
||||
),
|
||||
children: docker.images!
|
||||
.map(
|
||||
(e) => ListTile(
|
||||
title: Text(e.repo),
|
||||
subtitle: Text('${e.tag} - ${e.size}'),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.delete),
|
||||
onPressed: () async {
|
||||
showRoundDialog(
|
||||
context,
|
||||
_s.attention,
|
||||
Text(_s.sureDelete(e.repo)),
|
||||
[
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: Text(_s.cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
final result = await _docker.run(
|
||||
'docker rmi ${e.id} -f',
|
||||
title: Text(_s.imagesList),
|
||||
subtitle: Text(
|
||||
_s.dockerImagesFmt(_docker.images!.length),
|
||||
style: grey,
|
||||
),
|
||||
children: _docker.images!
|
||||
.map(
|
||||
(e) => ListTile(
|
||||
title: Text(e.repo),
|
||||
subtitle: Text('${e.tag} - ${e.size}'),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.delete),
|
||||
onPressed: () async {
|
||||
showRoundDialog(
|
||||
context,
|
||||
_s.attention,
|
||||
Text(_s.sureDelete(e.repo)),
|
||||
[
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: Text(_s.cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
final result = await _docker.run(
|
||||
'docker rmi ${e.id} -f',
|
||||
);
|
||||
if (result != null) {
|
||||
showSnackBar(
|
||||
context,
|
||||
Text(getErrMsg(result) ?? _s.unknownError),
|
||||
);
|
||||
if (result != null) {
|
||||
showSnackBar(
|
||||
context,
|
||||
Text(getErrMsg(result) ?? _s.unknownError),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
_s.ok,
|
||||
style: const TextStyle(color: Colors.red),
|
||||
),
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
_s.ok,
|
||||
style: const TextStyle(color: Colors.red),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
.toList());
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLoading(DockerProvider docker) {
|
||||
if (!docker.isBusy) return const SizedBox();
|
||||
final haveLog = docker.runLog != null;
|
||||
Widget _buildLoading() {
|
||||
if (!_docker.isBusy) return const SizedBox();
|
||||
final haveLog = _docker.runLog != null;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(17),
|
||||
child: Column(
|
||||
@@ -339,14 +339,16 @@ class _DockerManagePageState extends State<DockerManagePage> {
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
haveLog ? const SizedBox(height: 17) : const SizedBox(),
|
||||
haveLog ? Text(docker.runLog!) : const SizedBox()
|
||||
haveLog ? Text(_docker.runLog!) : const SizedBox()
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEditHost(List<DockerPsItem> running, DockerProvider docker) {
|
||||
if (running.isNotEmpty) return const SizedBox();
|
||||
Widget _buildEditHost() {
|
||||
if (_docker.items!.isNotEmpty || _docker.images!.isNotEmpty) {
|
||||
return const SizedBox();
|
||||
}
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(17, 17, 17, 0),
|
||||
child: Column(
|
||||
@@ -356,7 +358,7 @@ class _DockerManagePageState extends State<DockerManagePage> {
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => _showEditHostDialog(docker),
|
||||
onPressed: () => _showEditHostDialog(),
|
||||
child: Text(_s.dockerEditHost),
|
||||
)
|
||||
],
|
||||
@@ -364,7 +366,7 @@ class _DockerManagePageState extends State<DockerManagePage> {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _showEditHostDialog(DockerProvider docker) async {
|
||||
Future<void> _showEditHostDialog() async {
|
||||
await showRoundDialog(
|
||||
context,
|
||||
_s.dockerEditHost,
|
||||
@@ -375,7 +377,7 @@ class _DockerManagePageState extends State<DockerManagePage> {
|
||||
TextEditingController(text: 'unix:///run/user/1000/docker.sock'),
|
||||
onSubmitted: (value) {
|
||||
locator<DockerStore>().setDockerHost(widget.spi.id, value.trim());
|
||||
docker.refresh();
|
||||
_docker.refresh();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
@@ -435,16 +437,16 @@ class _DockerManagePageState extends State<DockerManagePage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPsItems(List<DockerPsItem> running, DockerProvider docker) {
|
||||
Widget _buildPsItems() {
|
||||
return ExpansionTile(
|
||||
title: Text(_s.containerStatus),
|
||||
subtitle: Text(_buildSubtitle(running), style: grey),
|
||||
children: running.map(
|
||||
subtitle: Text(_buildSubtitle(_docker.items!), style: grey),
|
||||
children: _docker.items!.map(
|
||||
(item) {
|
||||
return ListTile(
|
||||
title: Text(item.name),
|
||||
subtitle: Text('${item.image} - ${item.status}'),
|
||||
trailing: _buildMoreBtn(item, docker.isBusy),
|
||||
trailing: _buildMoreBtn(item, _docker.isBusy),
|
||||
);
|
||||
},
|
||||
).toList(),
|
||||
|
||||
@@ -126,7 +126,7 @@ class _PkgManagePageState extends State<PkgManagePage>
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
title: TwoLineText(up: 'Apt', down: widget.spi.name),
|
||||
title: TwoLineText(up: _s.pkg, down: widget.spi.name),
|
||||
),
|
||||
body: Consumer<PkgProvider>(builder: (_, apt, __) {
|
||||
if (apt.error != null) {
|
||||
@@ -141,8 +141,11 @@ class _PkgManagePageState extends State<PkgManagePage>
|
||||
const SizedBox(
|
||||
height: 37,
|
||||
),
|
||||
SizedBox(
|
||||
height: _media.size.height * 0.4,
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: _media.size.height * 0.3,
|
||||
minWidth: _media.size.width
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(17),
|
||||
child: RoundRectCard(
|
||||
@@ -150,7 +153,6 @@ class _PkgManagePageState extends State<PkgManagePage>
|
||||
padding: const EdgeInsets.all(17),
|
||||
child: Text(
|
||||
apt.error!,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../data/res/color.dart';
|
||||
import '../../data/res/menu.dart';
|
||||
import '../../generated/l10n.dart';
|
||||
|
||||
@@ -15,10 +14,7 @@ class DropdownBtnItem {
|
||||
|
||||
Widget build(S s) => Row(
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
color: primaryColor,
|
||||
),
|
||||
Icon(icon),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user