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