mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2026-02-23 08:34:39 +01:00
#25 new: sftp upload
This commit is contained in:
@@ -3,9 +3,14 @@ import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:toolbox/core/extension/navigator.dart';
|
||||
import 'package:toolbox/data/model/sftp/req.dart';
|
||||
import 'package:toolbox/data/provider/server.dart';
|
||||
import 'package:toolbox/data/provider/sftp.dart';
|
||||
import 'package:toolbox/data/res/misc.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
import 'package:toolbox/view/page/editor.dart';
|
||||
import 'package:toolbox/view/widget/input_field.dart';
|
||||
import 'package:toolbox/view/widget/picker.dart';
|
||||
|
||||
import '../../../core/extension/numx.dart';
|
||||
import '../../../core/extension/stringx.dart';
|
||||
@@ -217,6 +222,51 @@ class _SFTPDownloadedPageState extends State<SFTPDownloadedPage> {
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.upload),
|
||||
title: Text(_s.upload),
|
||||
onTap: () async {
|
||||
context.pop();
|
||||
final remotePath = await showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.remotePath),
|
||||
child: Input(
|
||||
controller: TextEditingController(text: '/'),
|
||||
onSubmitted: (p0) {
|
||||
context.pop(p0);
|
||||
},
|
||||
));
|
||||
if (remotePath == null) {
|
||||
showSnackBar(context, Text(_s.fieldMustNotEmpty));
|
||||
return;
|
||||
}
|
||||
final serverProvider = locator<ServerProvider>();
|
||||
final ids = serverProvider.serverOrder;
|
||||
var idx = 0;
|
||||
await showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.server),
|
||||
child: Picker(
|
||||
items: ids.map((e) => Text(e)).toList(),
|
||||
onSelected: (idx_) => idx = idx_,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(), child: Text(_s.ok)),
|
||||
],
|
||||
);
|
||||
final id = ids[idx];
|
||||
final spi = serverProvider.servers[id]?.spi;
|
||||
if (spi == null) {
|
||||
showSnackBar(context, Text(_s.noResult));
|
||||
return;
|
||||
}
|
||||
locator<SftpProvider>().add(
|
||||
SftpReqItem(spi, remotePath, file.absolute.path),
|
||||
SftpReqType.upload,
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.open_in_new),
|
||||
title: Text(_s.open),
|
||||
|
||||
@@ -5,8 +5,8 @@ import 'package:provider/provider.dart';
|
||||
import '../../../core/extension/numx.dart';
|
||||
import '../../../core/utils/misc.dart';
|
||||
import '../../../core/utils/ui.dart';
|
||||
import '../../../data/model/sftp/download_status.dart';
|
||||
import '../../../data/provider/sftp_download.dart';
|
||||
import '../../../data/model/sftp/req.dart';
|
||||
import '../../../data/provider/sftp.dart';
|
||||
import '../../../data/res/ui.dart';
|
||||
import '../../widget/round_rect_card.dart';
|
||||
|
||||
@@ -57,7 +57,7 @@ class _SFTPDownloadingPageState extends State<SFTPDownloadingPage> {
|
||||
});
|
||||
}
|
||||
|
||||
Widget _wrapInCard(SftpDownloadStatus status, String? subtitle,
|
||||
Widget _wrapInCard(SftpReqStatus status, String? subtitle,
|
||||
{Widget? trailing}) {
|
||||
return RoundRectCard(
|
||||
ListTile(
|
||||
@@ -73,7 +73,7 @@ class _SFTPDownloadingPageState extends State<SFTPDownloadingPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildItem(SftpDownloadStatus status) {
|
||||
Widget _buildItem(SftpReqStatus status) {
|
||||
if (status.error != null) {
|
||||
showSnackBar(context, Text(status.error.toString()));
|
||||
status.error = null;
|
||||
|
||||
@@ -18,9 +18,9 @@ import '../../../data/model/server/server.dart';
|
||||
import '../../../data/model/server/server_private_info.dart';
|
||||
import '../../../data/model/sftp/absolute_path.dart';
|
||||
import '../../../data/model/sftp/browser_status.dart';
|
||||
import '../../../data/model/sftp/download_item.dart';
|
||||
import '../../../data/model/sftp/req.dart';
|
||||
import '../../../data/provider/server.dart';
|
||||
import '../../../data/provider/sftp_download.dart';
|
||||
import '../../../data/provider/sftp.dart';
|
||||
import '../../../data/res/path.dart';
|
||||
import '../../../data/res/ui.dart';
|
||||
import '../../../data/store/private_key.dart';
|
||||
@@ -313,6 +313,7 @@ class _SFTPPageState extends State<SFTPPage> {
|
||||
void _download(BuildContext context, SftpName name) {
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.attention),
|
||||
child: Text('${_s.dl2Local(name.filename)}\n${_s.keepForeground}'),
|
||||
actions: [
|
||||
TextButton(
|
||||
@@ -325,16 +326,16 @@ class _SFTPPageState extends State<SFTPPage> {
|
||||
final remotePath = _getRemotePath(name);
|
||||
final local = '${(await sftpDir).path}$remotePath';
|
||||
final pubKeyId = widget.spi.pubKeyId;
|
||||
final key = locator<PrivateKeyStore>().get(pubKeyId)?.privateKey;
|
||||
|
||||
locator<SftpProvider>().add(
|
||||
DownloadItem(
|
||||
SftpReqItem(
|
||||
widget.spi,
|
||||
remotePath,
|
||||
local,
|
||||
),
|
||||
key: pubKeyId == null
|
||||
? null
|
||||
: locator<PrivateKeyStore>().get(pubKeyId).privateKey,
|
||||
SftpReqType.download,
|
||||
key: key,
|
||||
);
|
||||
|
||||
context.pop();
|
||||
@@ -354,6 +355,7 @@ class _SFTPPageState extends State<SFTPPage> {
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
child: child,
|
||||
title: Text(_s.attention),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(),
|
||||
|
||||
@@ -112,6 +112,7 @@ class _SnippetEditPageState extends State<SnippetEditPage>
|
||||
onChanged: (p0) => setState(() {
|
||||
_tags = p0;
|
||||
}),
|
||||
s: _s.tag,
|
||||
)
|
||||
],
|
||||
);
|
||||
|
||||
5
lib/view/page/snippet/group_order.dart
Normal file
5
lib/view/page/snippet/group_order.dart
Normal file
@@ -0,0 +1,5 @@
|
||||
// import 'package:flutter/material.dart';
|
||||
|
||||
// class SnippetGroupOrderPage extends StatelessWidget {
|
||||
// final
|
||||
// }
|
||||
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
class Picker extends StatelessWidget {
|
||||
final List<Widget> items;
|
||||
final Function(int idx) onSelected;
|
||||
final void Function(int idx) onSelected;
|
||||
final double height;
|
||||
|
||||
const Picker({
|
||||
|
||||
@@ -6,9 +6,11 @@ import '../../data/res/color.dart';
|
||||
|
||||
class TagEditor extends StatelessWidget {
|
||||
final List<String> tags;
|
||||
final String s;
|
||||
final void Function(List<String>)? onChanged;
|
||||
|
||||
const TagEditor({super.key, required this.tags, this.onChanged});
|
||||
const TagEditor(
|
||||
{super.key, required this.tags, this.onChanged, required this.s});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -36,7 +38,7 @@ class TagEditor extends StatelessWidget {
|
||||
List<String> tags,
|
||||
Function(String) onTagDelete,
|
||||
) {
|
||||
if (tags.isEmpty) return Text('Tags');
|
||||
if (tags.isEmpty) return Text(s);
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
@@ -49,35 +51,33 @@ class TagEditor extends StatelessWidget {
|
||||
|
||||
Widget _buildTagItem(String tag, Function(String) onTagDelete) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(right: 7),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.all(
|
||||
Radius.circular(20.0),
|
||||
padding: const EdgeInsets.only(right: 7),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(20.0)),
|
||||
color: primaryColor,
|
||||
),
|
||||
color: primaryColor,
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 3),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 3),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'#$tag',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
const SizedBox(width: 4.0),
|
||||
InkWell(
|
||||
child: const Icon(
|
||||
Icons.cancel,
|
||||
size: 14.0,
|
||||
color: Colors.white,
|
||||
),
|
||||
onTap: () {
|
||||
onTagDelete(tag);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 4.0),
|
||||
InkWell(
|
||||
child: const Icon(
|
||||
Icons.cancel,
|
||||
size: 14.0,
|
||||
color: Colors.white,
|
||||
),
|
||||
onTap: () {
|
||||
onTagDelete(tag);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -87,20 +87,20 @@ class TagEditor extends StatelessWidget {
|
||||
List<String> tags,
|
||||
void Function(List<String>)? onChanged,
|
||||
) {
|
||||
final _textEditingController = TextEditingController();
|
||||
final textEditingController = TextEditingController();
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Add Tag'),
|
||||
content: Input(
|
||||
controller: _textEditingController,
|
||||
controller: textEditingController,
|
||||
hint: 'Tag',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
final tag = _textEditingController.text;
|
||||
final tag = textEditingController.text;
|
||||
tags.add(tag.trim());
|
||||
onChanged?.call(tags);
|
||||
Navigator.pop(context);
|
||||
|
||||
Reference in New Issue
Block a user