1
+ import 'dart:io' ;
2
+
1
3
import 'package:fluent_ui/fluent_ui.dart' as fluent;
2
4
import 'package:flutter/material.dart' ;
5
+ import 'package:flutter/services.dart' ;
3
6
import 'package:get/get.dart' ;
4
7
import 'package:miru_app/main.dart' ;
5
8
import 'package:miru_app/pages/extension/controller.dart' ;
6
9
import 'package:miru_app/pages/extension/widgets/extension_tile.dart' ;
7
10
import 'package:miru_app/pages/extension_repo/view.dart' ;
8
11
import 'package:miru_app/utils/extension.dart' ;
12
+ import 'package:miru_app/utils/router.dart' ;
13
+ import 'package:miru_app/widgets/button.dart' ;
14
+ import 'package:miru_app/widgets/messenger.dart' ;
9
15
import 'package:miru_app/widgets/platform_widget.dart' ;
10
16
import 'package:url_launcher/url_launcher.dart' ;
11
17
@@ -28,90 +34,121 @@ class _ExtensionPageState extends State<ExtensionPage> {
28
34
// 导入扩展对话框
29
35
_importDialog () {
30
36
String url = '' ;
31
- fluent. showDialog (
37
+ showPlatformDialog (
32
38
context: context,
33
- builder: (context) => fluent.ContentDialog (
34
- title: const Text ("导入扩展" ),
35
- content: Column (
36
- mainAxisSize: MainAxisSize .min,
37
- crossAxisAlignment: CrossAxisAlignment .start,
38
- children: [
39
- fluent.TextBox (
40
- placeholder: "扩展地址" ,
39
+ title: "导入扩展" ,
40
+ content: Column (
41
+ mainAxisSize: MainAxisSize .min,
42
+ crossAxisAlignment: CrossAxisAlignment .start,
43
+ children: [
44
+ PlatformWidget (
45
+ androidWidget: TextField (
46
+ decoration: const InputDecoration (
47
+ labelText: "扩展地址" ,
48
+ hintText: "https://example.com/extension.js" ,
49
+ ),
41
50
onChanged: (value) {
42
51
url = value;
43
52
},
44
53
),
45
- const SizedBox (height: 16 ),
46
- const Row (
47
- children: [
48
- Icon (fluent.FluentIcons .error),
49
- SizedBox (width: 8 ),
50
- Text (
51
- "你可以通过链接导入扩展,\n 或者点击下方的扩展目录,将扩展文件\n 放入其中。" ,
52
- softWrap: true ,
53
- )
54
- ],
54
+ desktopWidget: fluent.TextBox (
55
+ placeholder: "扩展地址" ,
56
+ onChanged: (value) {
57
+ url = value;
58
+ },
55
59
),
56
- ],
57
- ),
58
- actions: [
59
- fluent.Button (
60
- onPressed: () {
61
- router.pop ();
62
- },
63
- child: const Text ("取消" ),
64
60
),
65
- fluent.FilledButton (
66
- onPressed: () async {
67
- router.pop ();
68
- // 定位目录
69
- final dir = await ExtensionUtils .getExtensionsDir;
70
- final uri = Uri .directory (dir);
71
- await launchUrl (uri);
72
- },
73
- child: const Text ("扩展目录" ),
74
- ),
75
- fluent.FilledButton (
76
- onPressed: () async {
77
- Navigator .of (context).pop ();
78
- await ExtensionUtils .install (url, context);
79
- },
80
- child: const Text ("通过链接导入" ),
61
+ const SizedBox (height: 16 ),
62
+ const Row (
63
+ children: [
64
+ Icon (fluent.FluentIcons .error),
65
+ SizedBox (width: 8 ),
66
+ Text (
67
+ "你可以通过链接导入扩展,\n 或者点击下方的扩展目录,将扩展文件\n 放入其中。" ,
68
+ softWrap: true ,
69
+ )
70
+ ],
81
71
),
82
72
],
83
73
),
74
+ actions: [
75
+ PlatformButton (
76
+ onPressed: () {
77
+ RouterUtils .pop ();
78
+ },
79
+ child: const Text ("取消" ),
80
+ ),
81
+ PlatformFilledButton (
82
+ onPressed: () async {
83
+ RouterUtils .pop ();
84
+ // 定位目录
85
+ final dir = await ExtensionUtils .getExtensionsDir;
86
+ if (Platform .isAndroid) {
87
+ // 复制 dir
88
+ Clipboard .setData (ClipboardData (text: dir));
89
+ // ignore: use_build_context_synchronously
90
+ showPlatformSnackbar (
91
+ context: context,
92
+ title: '扩展目录' ,
93
+ content: '已复制到剪贴板' ,
94
+ );
95
+ return ;
96
+ }
97
+ final uri = Uri .directory (dir);
98
+ await launchUrl (uri);
99
+ },
100
+ child: const Text ("扩展目录" ),
101
+ ),
102
+ PlatformFilledButton (
103
+ onPressed: () async {
104
+ RouterUtils .pop ();
105
+ await ExtensionUtils .install (url, context);
106
+ },
107
+ child: const Text ("通过链接导入" ),
108
+ ),
109
+ ],
84
110
);
85
111
}
86
112
87
113
// 加载错误对话框
88
114
_loadErrorDialog () {
89
- fluent. showDialog (
115
+ showPlatformDialog (
90
116
context: context,
91
- builder : (context) => fluent. ContentDialog (
92
- title : const Text ( "错误信息" ),
93
- content : ListView (
94
- shrinkWrap : true ,
117
+ title : "错误信息" ,
118
+ content : SingleChildScrollView (
119
+ child : Column (
120
+ mainAxisSize : MainAxisSize .min ,
95
121
children: [
96
122
// 输出key 和 value
97
123
for (final e in c.errors.entries)
98
- fluent.Card (
99
- margin: const EdgeInsets .only (bottom: 8 ),
100
- child: Text (
101
- "${e .key }: ${e .value }" ,
124
+ PlatformWidget (
125
+ androidWidget: Card (
126
+ margin: const EdgeInsets .only (bottom: 8 ),
127
+ child: Container (
128
+ padding: const EdgeInsets .all (16 ),
129
+ child: Text (
130
+ "${e .key }: ${e .value }" ,
131
+ ),
132
+ ),
133
+ ),
134
+ desktopWidget: fluent.Card (
135
+ margin: const EdgeInsets .only (bottom: 8 ),
136
+ child: Text (
137
+ "${e .key }: ${e .value }" ,
138
+ ),
102
139
),
103
140
),
104
141
],
105
142
),
106
- actions: [
107
- fluent.Button (
108
- onPressed: () {
109
- router.pop ();
110
- },
111
- child: const Text ("确定" ),
112
- ),
113
- ],
114
143
),
144
+ actions: [
145
+ PlatformButton (
146
+ onPressed: () {
147
+ RouterUtils .pop ();
148
+ },
149
+ child: const Text ("确定" ),
150
+ ),
151
+ ],
115
152
);
116
153
}
117
154
@@ -122,10 +159,27 @@ class _ExtensionPageState extends State<ExtensionPage> {
122
159
child: Scaffold (
123
160
appBar: AppBar (
124
161
title: const Text ("扩展" ),
125
- bottom: const TabBar (tabs: [
126
- Tab (text: "已安装" ),
127
- Tab (text: "仓库" ),
128
- ]),
162
+ bottom: const TabBar (
163
+ tabs: [
164
+ Tab (text: "已安装" ),
165
+ Tab (text: "仓库" ),
166
+ ],
167
+ ),
168
+ actions: [
169
+ if (c.errors.isNotEmpty)
170
+ IconButton (
171
+ icon: const Icon (Icons .error),
172
+ onPressed: () {
173
+ _loadErrorDialog ();
174
+ },
175
+ ),
176
+ ],
177
+ ),
178
+ floatingActionButton: FloatingActionButton (
179
+ onPressed: () {
180
+ _importDialog ();
181
+ },
182
+ child: const Icon (Icons .add),
129
183
),
130
184
body: TabBarView (children: [
131
185
ListView (
0 commit comments