|
| 1 | +import 'dart:convert'; |
| 2 | + |
| 3 | +import 'package:flutter/material.dart'; |
| 4 | + |
| 5 | +import 'package:maple_file/app/i18n.dart'; |
| 6 | +import 'package:maple_file/common/widgets/dialog.dart'; |
| 7 | +import 'package:maple_file/generated/proto/api/file/repo.pb.dart'; |
| 8 | + |
| 9 | +import 'form.dart'; |
| 10 | + |
| 11 | +class Mirror extends StatefulWidget { |
| 12 | + const Mirror({super.key, required this.form}); |
| 13 | + |
| 14 | + final Repo form; |
| 15 | + |
| 16 | + @override |
| 17 | + State<Mirror> createState() => _MirrorState(); |
| 18 | +} |
| 19 | + |
| 20 | +class _MirrorState extends State<Mirror> { |
| 21 | + late Map<String, dynamic> _option; |
| 22 | + |
| 23 | + @override |
| 24 | + void initState() { |
| 25 | + super.initState(); |
| 26 | + |
| 27 | + _option = widget.form.option == "" ? {} : jsonDecode(widget.form.option); |
| 28 | + } |
| 29 | + |
| 30 | + @override |
| 31 | + Widget build(BuildContext context) { |
| 32 | + return Card( |
| 33 | + child: Column( |
| 34 | + children: [ |
| 35 | + DriverFormField( |
| 36 | + label: "源站".tr(context), |
| 37 | + value: _option["endpoint"], |
| 38 | + isRequired: true, |
| 39 | + onTap: (result) { |
| 40 | + setState(() { |
| 41 | + _option["endpoint"] = result; |
| 42 | + }); |
| 43 | + |
| 44 | + widget.form.option = jsonEncode(_option); |
| 45 | + }, |
| 46 | + ), |
| 47 | + ListTile( |
| 48 | + title: Text('源站格式'.tr(context)), |
| 49 | + trailing: Wrap( |
| 50 | + crossAxisAlignment: WrapCrossAlignment.center, |
| 51 | + children: [ |
| 52 | + Text(_option["format"] ?? "未选择".tr(context)), |
| 53 | + const Icon(Icons.chevron_right), |
| 54 | + ], |
| 55 | + ), |
| 56 | + onTap: () async { |
| 57 | + final result = await showListDialog(context, items: [ |
| 58 | + ListDialogItem(value: "nginx"), |
| 59 | + ListDialogItem(value: "tuna"), |
| 60 | + ListDialogItem(value: "aliyun"), |
| 61 | + ]); |
| 62 | + if (result != null) { |
| 63 | + setState(() { |
| 64 | + _option["format"] = result; |
| 65 | + }); |
| 66 | + widget.form.option = jsonEncode(_option); |
| 67 | + } |
| 68 | + }, |
| 69 | + ), |
| 70 | + DriverFormField( |
| 71 | + label: "根目录".tr(context), |
| 72 | + value: _option["root_path"], |
| 73 | + onTap: (result) { |
| 74 | + setState(() { |
| 75 | + _option["root_path"] = result; |
| 76 | + }); |
| 77 | + |
| 78 | + widget.form.option = jsonEncode(_option); |
| 79 | + }, |
| 80 | + ), |
| 81 | + ], |
| 82 | + ), |
| 83 | + ); |
| 84 | + } |
| 85 | +} |
0 commit comments