11// global_settings_page.dart
2- import 'package:file_selector/file_selector .dart' ;
2+ import 'package:file_picker_ohos/file_picker_ohos .dart' ;
33import 'package:flutter/material.dart' ;
44import 'package:connssh/main.dart' ;
55import '../../models/app_settings_model.dart' ;
@@ -63,13 +63,12 @@ class _GlobalSettingsPageState extends State<GlobalSettingsPage> {
6363 child: Column (
6464 mainAxisSize: MainAxisSize .min,
6565 children: [
66- const Text ('请输入备份密码' , style: TextStyle (fontSize: 14 )),
6766 const SizedBox (height: 16 ),
6867 TextField (
6968 controller: passwordController,
7069 obscureText: passwordObscure,
7170 decoration: InputDecoration (
72- labelText: '密码 ' ,
71+ labelText: '请设置密码 ' ,
7372 border: const OutlineInputBorder (),
7473 suffixIcon: IconButton (
7574 icon: Icon (passwordObscure
@@ -202,45 +201,30 @@ class _GlobalSettingsPageState extends State<GlobalSettingsPage> {
202201 child: Column (
203202 mainAxisSize: MainAxisSize .min,
204203 children: [
205- const Text (
206- '选择备份文件并输入密码' ,
207- style: TextStyle (fontSize: 14 ),
208- ),
209204 const SizedBox (height: 16 ),
210205 OutlinedButton .icon (
211206 onPressed: () async {
212207 try {
213- // 使用 file_selector 选择文件
214- const XTypeGroup typeGroup = XTypeGroup (
215- label: 'ConnSSH Backup' ,
216- extensions: ['cntinfo' ],
217- );
218- final XFile ? file = await openFile (
219- acceptedTypeGroups: [typeGroup],
208+ final FilePickerResult ? result =
209+ await FilePicker .platform.pickFiles (
210+ type: FileType .custom,
211+ allowedExtensions: ['cntinfo' ],
212+ dialogTitle: '选择备份文件' ,
213+ allowMultiple: false ,
220214 );
221215
222- if (file != null ) {
216+ if (result != null && result.files.isNotEmpty) {
217+ PlatformFile file = result.files.first;
223218 setState (() {
224219 selectedFilePath = file.path;
225220 });
226-
227- // 显示选择的文件名
228- if (mounted) {
229- ScaffoldMessenger .of (context).showSnackBar (
230- SnackBar (
231- content: Text ('已选择文件: ${file .name }' ),
232- duration: const Duration (seconds: 2 ),
233- ),
234- );
235- }
236221 }
237222 } catch (e) {
238223 debugPrint ('选择文件失败: $e ' );
239224 if (mounted) {
240225 ScaffoldMessenger .of (context).showSnackBar (
241226 SnackBar (
242227 content: Text ('选择文件失败: $e ' ),
243- backgroundColor: Colors .red,
244228 ),
245229 );
246230 }
@@ -257,15 +241,6 @@ class _GlobalSettingsPageState extends State<GlobalSettingsPage> {
257241 ),
258242 if (selectedFilePath != null ) ...[
259243 const SizedBox (height: 8 ),
260- Text (
261- '文件路径: ${selectedFilePath !.length > 50 ? '...${selectedFilePath !.substring (selectedFilePath !.length - 50 )}' : selectedFilePath !}' ,
262- style: const TextStyle (
263- fontSize: 10 ,
264- color: Colors .grey,
265- ),
266- maxLines: 2 ,
267- overflow: TextOverflow .ellipsis,
268- ),
269244 ],
270245 const SizedBox (height: 12 ),
271246 TextField (
@@ -315,10 +290,11 @@ class _GlobalSettingsPageState extends State<GlobalSettingsPage> {
315290 showDialog (
316291 context: context,
317292 builder: (context) => AlertDialog (
318- title: const Text ('确认恢复' ),
319- content: const Text (
320- '此操作将覆盖所有现有数据,且不可撤销,确定要恢复吗?' ,
321- ),
293+ title: const Text ('这是最后一次确认' ),
294+ content: const Text ('此操作将覆盖所有现有数据,且不可撤销,确定要恢复吗?' ,
295+ style: TextStyle (
296+ color: Colors .red,
297+ fontWeight: FontWeight .bold)),
322298 actions: [
323299 OutlinedButton (
324300 onPressed: () => Navigator .of (context).pop (),
@@ -332,7 +308,9 @@ class _GlobalSettingsPageState extends State<GlobalSettingsPage> {
332308 Navigator .of (context, rootNavigator: true )
333309 .pop ();
334310 }
335-
311+ final NavigatorState navigator = Navigator .of (
312+ this .context,
313+ rootNavigator: true );
336314 showDialog (
337315 context: context,
338316 barrierDismissible: false ,
@@ -360,17 +338,13 @@ class _GlobalSettingsPageState extends State<GlobalSettingsPage> {
360338 backupData,
361339 );
362340
363- // 关闭加载对话框
364- if (Navigator .of (context,
365- rootNavigator: true )
366- .canPop ()) {
367- Navigator .of (context, rootNavigator: true )
368- .pop ();
341+ if (navigator.canPop ()) {
342+ navigator.pop ();
369343 }
370344
371345 // 刷新应用
372346 widget.onSettingsChanged ();
373- MyApp .of (context)? .loadSettings ();
347+ MyApp .of (this . context)? .loadSettings ();
374348
375349 showDialog (
376350 context: context,
@@ -385,10 +359,8 @@ class _GlobalSettingsPageState extends State<GlobalSettingsPage> {
385359 actions: [
386360 OutlinedButton (
387361 onPressed: () {
388- Navigator .of (context).pop ();
389- if (Navigator .of (context)
390- .canPop ()) {
391- Navigator .of (context).pop ();
362+ if (navigator.canPop ()) {
363+ navigator.pop ();
392364 }
393365 },
394366 child: const Text ('确定' ),
@@ -458,7 +430,6 @@ class _GlobalSettingsPageState extends State<GlobalSettingsPage> {
458430 ScaffoldMessenger .of (context).showSnackBar (
459431 const SnackBar (
460432 content: Text ('已恢复默认设置' ),
461- duration: Duration (seconds: 2 ),
462433 ),
463434 );
464435 }
0 commit comments