11import 'package:flutter/material.dart' ;
2- import 'package:flutter/services.dart' ;
32import 'package:flutter_riverpod/flutter_riverpod.dart' ;
43
54import 'package:maple_file/app/i18n.dart' ;
6- import 'package:maple_file/common/widgets/dialog .dart' ;
5+ import 'package:maple_file/common/widgets/form .dart' ;
76import 'package:maple_file/common/widgets/custom.dart' ;
87
98import '../providers/file_setting.dart' ;
@@ -16,14 +15,6 @@ class FileSettingUpload extends ConsumerStatefulWidget {
1615}
1716
1817class _FileSettingUploadState extends ConsumerState <FileSettingUpload > {
19- final TextEditingController _controller = TextEditingController ();
20-
21- @override
22- void dispose () {
23- _controller.dispose ();
24- super .dispose ();
25- }
26-
2718 @override
2819 Widget build (BuildContext context) {
2920 return Scaffold (
@@ -57,11 +48,7 @@ class _FileSettingUploadState extends ConsumerState<FileSettingUpload> {
5748 child: Column (
5849 children: [
5950 ListTile (
60- title: Text ("文件上传" .tr ()),
61- dense: true ,
62- ),
63- ListTile (
64- title: const Text ('自动重命名' ),
51+ title: Text ('自动重命名' .tr ()),
6552 trailing: Switch (
6653 value: setting.uploadRename,
6754 onChanged: (bool value) async {
@@ -72,56 +59,34 @@ class _FileSettingUploadState extends ConsumerState<FileSettingUpload> {
7259 ),
7360 ),
7461 if (setting.uploadRename)
75- ListTile (
76- title: const Text ('重命名格式' ),
77- trailing: Text (setting.uploadFormat == ""
78- ? "{filename}{extension}"
79- : setting.uploadFormat),
80- onTap: () async {
81- _controller.text = setting.uploadFormat;
82-
83- final result = await showEditingDialog (
84- context,
85- "重命名格式" ,
86- controller: _controller,
87- helper: buildHelper (),
88- );
89- if (result != null ) {
90- ref.read (fileSettingProvider.notifier).update ((state) {
91- return state.copyWith (uploadFormat: result);
92- });
93- }
62+ CustomFormField (
63+ type: CustomFormFieldType .path,
64+ label: '重命名格式' .tr (),
65+ value: setting.uploadFormat,
66+ subtitle: Text (
67+ "默认为 {path}" .tr (args: {
68+ "path" : "{filename}{extension}" ,
69+ }),
70+ style: const TextStyle (fontSize: 12 ),
71+ ),
72+ onTap: (result) {
73+ ref.read (fileSettingProvider.notifier).update ((state) {
74+ return state.copyWith (uploadFormat: result);
75+ });
9476 },
9577 ),
96- ListTile (
97- title: const Text ('分片大小' ),
98- subtitle: const Text (
99- '文件上传分片大小' ,
100- style: TextStyle (fontSize: 10 ),
101- ),
102- trailing: Wrap (
103- crossAxisAlignment: WrapCrossAlignment .center,
104- children: [
105- Text ("${setting .uploadSliceSize }KB" ),
106- ],
78+ CustomFormField (
79+ type: CustomFormFieldType .number,
80+ label: '分片大小' .tr (),
81+ value: "${setting .uploadSliceSize }" ,
82+ subtitle: Text (
83+ '文件上传分片大小(单位:KB)' .tr (),
84+ style: const TextStyle (fontSize: 12 ),
10785 ),
108- onTap: () async {
109- _controller.text = setting.uploadSliceSize.toString ();
110-
111- final result = await showEditingDialog (
112- context,
113- "分片大小(单位:KB)" ,
114- controller: _controller,
115- keyboardType: TextInputType .number,
116- inputFormatters: [
117- FilteringTextInputFormatter .digitsOnly,
118- ],
119- );
120- if (result != null ) {
121- ref.read (fileSettingProvider.notifier).update ((state) {
122- return state.copyWith (uploadSliceSize: int .parse (result));
123- });
124- }
86+ onTap: (result) {
87+ ref.read (fileSettingProvider.notifier).update ((state) {
88+ return state.copyWith (uploadSliceSize: int .parse (result));
89+ });
12590 },
12691 ),
12792 ],
@@ -130,68 +95,31 @@ class _FileSettingUploadState extends ConsumerState<FileSettingUpload> {
13095 Card (
13196 child: Column (
13297 children: [
133- const ListTile (
134- title: Text ("文件限制" ),
135- dense: true ,
136- ),
137- ListTile (
138- title: const Text ('大小限制' ),
139- subtitle: const Text (
140- '0表示不限制' ,
141- style: TextStyle (fontSize: 10 ),
142- ),
143- trailing: Wrap (
144- crossAxisAlignment: WrapCrossAlignment .center,
145- children: [
146- Text ("${setting .uploadLimitSize }MB" ),
147- ],
98+ CustomFormField (
99+ type: CustomFormFieldType .number,
100+ label: '大小限制' .tr (),
101+ value: "${setting .uploadLimitSize }" ,
102+ subtitle: Text (
103+ '0表示不限制(单位:MB)' .tr (),
104+ style: const TextStyle (fontSize: 12 ),
148105 ),
149- onTap: () async {
150- _controller.text = setting.uploadLimitSize.toString ();
151-
152- final result = await showEditingDialog (
153- context,
154- "大小限制(单位:MB)" ,
155- controller: _controller,
156- keyboardType: TextInputType .number,
157- inputFormatters: [
158- FilteringTextInputFormatter .digitsOnly,
159- ],
160- );
161- if (result != null ) {
162- ref.read (fileSettingProvider.notifier).update ((state) {
163- return state.copyWith (uploadLimitSize: int .parse (result));
164- });
165- }
106+ onTap: (result) {
107+ ref.read (fileSettingProvider.notifier).update ((state) {
108+ return state.copyWith (uploadLimitSize: int .parse (result));
109+ });
166110 },
167111 ),
168- ListTile (
169- title: const Text ('格式限制' ),
170- subtitle: const Text (
171- '多个格式使用逗号分隔。例如: .mp4,.png' ,
172- style: TextStyle (fontSize: 10 ),
112+ CustomFormField (
113+ label: '格式限制' .tr (),
114+ value: setting.uploadLimitType,
115+ subtitle: Text (
116+ '多个格式使用逗号分隔。例如: .mp4,.png' .tr (),
117+ style: const TextStyle (fontSize: 12 ),
173118 ),
174- trailing: Wrap (
175- crossAxisAlignment: WrapCrossAlignment .center,
176- children: [
177- Text (setting.uploadLimitType == ""
178- ? "未设置"
179- : setting.uploadLimitType),
180- ],
181- ),
182- onTap: () async {
183- _controller.text = setting.uploadLimitType;
184-
185- final result = await showEditingDialog (
186- context,
187- "格式限制" ,
188- controller: _controller,
189- );
190- if (result != null ) {
191- ref.read (fileSettingProvider.notifier).update ((state) {
192- return state.copyWith (uploadLimitType: result);
193- });
194- }
119+ onTap: (result) {
120+ ref.read (fileSettingProvider.notifier).update ((state) {
121+ return state.copyWith (uploadLimitType: result);
122+ });
195123 },
196124 ),
197125 ],
@@ -200,34 +128,4 @@ class _FileSettingUploadState extends ConsumerState<FileSettingUpload> {
200128 ],
201129 );
202130 }
203-
204- Widget buildHelper () {
205- Map <String , String > formats = {
206- "文件名" : "{filename}" ,
207- "文件扩展" : "{extension}" ,
208- "年" : "{time:year}" ,
209- "月" : "{time:month}" ,
210- "日" : "{time:day}" ,
211- "时" : "{time:hour}" ,
212- "分" : "{time:minute}" ,
213- "秒" : "{time:second}" ,
214- };
215- return Wrap (
216- spacing: 4 ,
217- runSpacing: 4 ,
218- children: [
219- for (final key in formats.keys)
220- ActionChip (
221- label: Text (key),
222- labelStyle: TextStyle (
223- fontSize: kDefaultFontSize * 0.875 ,
224- color: Theme .of (context).primaryColor,
225- ),
226- onPressed: () {
227- _controller.text = "${_controller .text }${formats [key ]}" ;
228- },
229- ),
230- ],
231- );
232- }
233131}
0 commit comments