This commit is contained in:
lollipopkit
2023-07-07 21:09:29 +08:00
parent bb50fbc589
commit cb16b3a8b6
5 changed files with 122 additions and 116 deletions

View File

@@ -121,7 +121,7 @@ Future<void> loadFontFile(String? localPath) async {
void showSnippetDialog( void showSnippetDialog(
BuildContext context, BuildContext context,
S s, S s,
Function(Snippet s) onSelected, void Function(Snippet s) onSelected,
) { ) {
final provider = locator<SnippetProvider>(); final provider = locator<SnippetProvider>();
if (provider.snippets.isEmpty) { if (provider.snippets.isEmpty) {

View File

@@ -68,19 +68,20 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
} }
PreferredSizeWidget _buildAppBar() { PreferredSizeWidget _buildAppBar() {
return AppBar( final actions = widget.info == null
title: Text(_s.edit, style: textSize18), ? null
actions: [ : [
widget.info != null IconButton(
? IconButton(
tooltip: _s.delete, tooltip: _s.delete,
onPressed: () { onPressed: () {
_provider.delInfo(widget.info!); _provider.delInfo(widget.info!);
context.pop(); context.pop();
}, },
icon: const Icon(Icons.delete)) icon: const Icon(Icons.delete))
: nil ];
], return AppBar(
title: Text(_s.edit, style: textSize18),
actions: actions,
); );
} }

View File

@@ -1,10 +1,10 @@
import 'package:after_layout/after_layout.dart'; import 'package:after_layout/after_layout.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:nil/nil.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:toolbox/core/extension/navigator.dart'; import 'package:toolbox/core/extension/navigator.dart';
import 'package:toolbox/view/widget/input_field.dart'; import 'package:toolbox/view/widget/input_field.dart';
import 'package:toolbox/view/widget/round_rect_card.dart';
import '../../../core/route.dart'; import '../../../core/route.dart';
import '../../../core/utils/ui.dart'; import '../../../core/utils/ui.dart';
@@ -97,21 +97,15 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
}, },
icon: const Icon(Icons.delete), icon: const Icon(Icons.delete),
); );
final actions = widget.spi != null ? [delBtn] : null;
return AppBar( return AppBar(
title: Text(_s.edit, style: textSize18), title: Text(_s.edit, style: textSize18),
actions: [ actions: actions,
widget.spi != null ? delBtn : nil,
],
); );
} }
Widget _buildForm() { Widget _buildForm() {
return SingleChildScrollView( final children = [
padding: const EdgeInsets.all(17),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Input( Input(
controller: _nameController, controller: _nameController,
type: TextInputType.text, type: TextInputType.text,
@@ -168,8 +162,11 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
), ),
], ],
), ),
!usePublicKey ];
? Input( if (usePublicKey) {
children.add(_buildKeyAuth());
} else {
children.add(Input(
controller: _passwordController, controller: _passwordController,
obscureText: true, obscureText: true,
type: TextInputType.text, type: TextInputType.text,
@@ -177,10 +174,14 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
icon: Icons.password, icon: Icons.password,
hint: _s.pwd, hint: _s.pwd,
onSubmitted: (_) => {}, onSubmitted: (_) => {},
) ));
: nil, }
usePublicKey ? _buildKeyAuth() : nil return SingleChildScrollView(
], padding: const EdgeInsets.fromLTRB(17, 17, 17, 47),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: children,
), ),
); );
} }
@@ -215,11 +216,12 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
), ),
), ),
); );
return Padding( return RoundRectCard(
Padding(
padding: const EdgeInsets.symmetric(horizontal: 17), padding: const EdgeInsets.symmetric(horizontal: 17),
child: Column( child: Column(
children: tiles, children: tiles,
), )),
); );
}, },
); );

View File

@@ -4,7 +4,6 @@ import 'dart:typed_data';
import 'package:dartssh2/dartssh2.dart'; import 'package:dartssh2/dartssh2.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:nil/nil.dart';
import 'package:toolbox/core/extension/navigator.dart'; import 'package:toolbox/core/extension/navigator.dart';
import 'package:toolbox/core/extension/sftpfile.dart'; import 'package:toolbox/core/extension/sftpfile.dart';
import 'package:toolbox/data/res/misc.dart'; import 'package:toolbox/data/res/misc.dart';
@@ -119,7 +118,6 @@ class _SFTPPageState extends State<SFTPPage> {
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
const Divider(),
(_status.path?.path ?? _s.loadingFiles).omitStartStr(), (_status.path?.path ?? _s.loadingFiles).omitStartStr(),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
@@ -299,18 +297,7 @@ class _SFTPPageState extends State<SFTPPage> {
} }
void _onItemPress(BuildContext context, SftpName file, bool notDir) { void _onItemPress(BuildContext context, SftpName file, bool notDir) {
showRoundDialog( final children = [
context: context,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
notDir
? ListTile(
leading: const Icon(Icons.edit),
title: Text(_s.edit),
onTap: () => _edit(context, file),
)
: nil,
ListTile( ListTile(
leading: const Icon(Icons.delete), leading: const Icon(Icons.delete),
title: Text(_s.delete), title: Text(_s.delete),
@@ -321,14 +308,26 @@ class _SFTPPageState extends State<SFTPPage> {
title: Text(_s.rename), title: Text(_s.rename),
onTap: () => _rename(context, file), onTap: () => _rename(context, file),
), ),
notDir ];
? ListTile( if (notDir) {
children.addAll([
ListTile(
leading: const Icon(Icons.edit),
title: Text(_s.edit),
onTap: () => _edit(context, file),
),
ListTile(
leading: const Icon(Icons.download), leading: const Icon(Icons.download),
title: Text(_s.download), title: Text(_s.download),
onTap: () => _download(context, file), onTap: () => _download(context, file),
) ),
: nil, ]);
], }
showRoundDialog(
context: context,
child: Column(
mainAxisSize: MainAxisSize.min,
children: children,
), ),
); );
} }

View File

@@ -131,6 +131,10 @@ class _SnippetEditPageState extends State<SnippetEditPage>
if (widget.snippet != null) { if (widget.snippet != null) {
_nameController.text = widget.snippet!.name; _nameController.text = widget.snippet!.name;
_scriptController.text = widget.snippet!.script; _scriptController.text = widget.snippet!.script;
if (widget.snippet!.tags != null) {
_tags = widget.snippet!.tags!;
setState(() {});
}
} }
} }
} }