first commit.
This commit is contained in:
@@ -0,0 +1,277 @@
|
||||
import 'package:cloud_archiver/config.dart';
|
||||
import 'package:cloud_archiver/utils.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AppConfigDialog extends StatefulWidget {
|
||||
const AppConfigDialog({super.key});
|
||||
|
||||
static void show(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => Dialog(
|
||||
child: AppConfigDialog(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
State<AppConfigDialog> createState() => _AppConfigDialogState();
|
||||
}
|
||||
|
||||
class _AppConfigDialogState extends State<AppConfigDialog> {
|
||||
final TextEditingController clientCtl = TextEditingController();
|
||||
final TextEditingController serverCtl = TextEditingController();
|
||||
final TextEditingController userCtl = TextEditingController();
|
||||
final TextEditingController passwdCtl = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (appConfig != null) {
|
||||
clientCtl.text = appConfig!.client;
|
||||
serverCtl.text = appConfig!.server;
|
||||
userCtl.text = appConfig!.user;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: 400,
|
||||
height: 300,
|
||||
padding: EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
color: Colors.white,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black26,
|
||||
offset: Offset(4, 4),
|
||||
spreadRadius: 8,
|
||||
blurRadius: 16,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'配置DAV服务',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(width: 70, child: Text('标识名: ')),
|
||||
Flexible(
|
||||
child: TextField(
|
||||
controller: clientCtl,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(width: 70, child: Text('服务器: ')),
|
||||
Flexible(
|
||||
child: TextField(
|
||||
controller: serverCtl,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(width: 70, child: Text('用户名: ')),
|
||||
Flexible(
|
||||
child: TextField(
|
||||
controller: userCtl,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(width: 70, child: Text('密码: ')),
|
||||
Flexible(
|
||||
child: TextField(
|
||||
controller: passwdCtl,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Spacer(),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text('取消'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
var client = clientCtl.text.trim();
|
||||
var server = serverCtl.text.trim();
|
||||
var user = userCtl.text.trim();
|
||||
var passwd = passwdCtl.text.trim();
|
||||
connect(server, user, passwd).then(
|
||||
(connected) {
|
||||
if (connected) {
|
||||
AppConfig.updateConfig(
|
||||
client: client,
|
||||
server: server,
|
||||
user: user,
|
||||
passwd: passwd,
|
||||
);
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
child: Text('确认'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AddSyncItemDialog extends StatefulWidget {
|
||||
final SyncItemConfig? editItemConfig;
|
||||
|
||||
const AddSyncItemDialog({super.key, this.editItemConfig});
|
||||
|
||||
static void show(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => Dialog(
|
||||
child: AddSyncItemDialog(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
State<AddSyncItemDialog> createState() => _AddSyncItemDialogState();
|
||||
}
|
||||
|
||||
class _AddSyncItemDialogState extends State<AddSyncItemDialog> {
|
||||
final TextEditingController nameCtl = TextEditingController();
|
||||
final TextEditingController pathCtl = TextEditingController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: 400,
|
||||
height: 300,
|
||||
padding: EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
color: Colors.white,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black26,
|
||||
offset: Offset(4, 4),
|
||||
spreadRadius: 8,
|
||||
blurRadius: 16,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
widget.editItemConfig == null ? '添加同步项' : '修改同步项',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(width: 80, child: Text('项目名称: ')),
|
||||
Flexible(
|
||||
child: TextField(
|
||||
controller: nameCtl,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(width: 80, child: Text('项目路径: ')),
|
||||
Flexible(
|
||||
child: TextField(
|
||||
controller: pathCtl,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
FilePicker.pickFiles(
|
||||
allowMultiple: false,
|
||||
).then(
|
||||
(res) {
|
||||
if (res?.files.firstOrNull?.path?.isNotEmpty == true) {
|
||||
pathCtl.text = res!.files.first.path!;
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
icon: Icon(Icons.file_open_rounded),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
FilePicker.getDirectoryPath().then(
|
||||
(path) {
|
||||
if (path?.isNotEmpty == true) {
|
||||
pathCtl.text = path!;
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
icon: Icon(Icons.folder_open_rounded),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Spacer(),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text('取消'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
var name = nameCtl.text.trim();
|
||||
var path = pathCtl.text.trim();
|
||||
|
||||
if (name.isNotEmpty && path.isNotEmpty) {
|
||||
AppConfig.addSyncItem(
|
||||
SyncItemConfig(
|
||||
name: name,
|
||||
path: path,
|
||||
uuid: widget.editItemConfig?.uuid,
|
||||
),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
child: Text('确认'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user