Add linux deb dependencies Add backup recovery strategy select Support custom text scaling Optimize the display of different text scale Optimize windows setup experience Optimize startTun performance Optimize android tv experience Optimize default option Optimize computed text size Optimize hyperOS freeform window Add developer mode Update core Optimize more details
126 lines
3.1 KiB
Dart
126 lines
3.1 KiB
Dart
import 'package:fl_clash/common/common.dart';
|
|
import 'package:fl_clash/pages/scan.dart';
|
|
import 'package:fl_clash/state.dart';
|
|
import 'package:fl_clash/widgets/widgets.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class AddProfile extends StatelessWidget {
|
|
final BuildContext context;
|
|
|
|
const AddProfile({
|
|
super.key,
|
|
required this.context,
|
|
});
|
|
|
|
_handleAddProfileFormFile() async {
|
|
globalState.appController.addProfileFormFile();
|
|
}
|
|
|
|
_handleAddProfileFormURL(String url) async {
|
|
globalState.appController.addProfileFormURL(url);
|
|
}
|
|
|
|
_toScan() async {
|
|
if (system.isDesktop) {
|
|
globalState.appController.addProfileFormQrCode();
|
|
return;
|
|
}
|
|
final url = await BaseNavigator.push(
|
|
context,
|
|
const ScanPage(),
|
|
);
|
|
if (url != null) {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
_handleAddProfileFormURL(url);
|
|
});
|
|
}
|
|
}
|
|
|
|
_toAdd() async {
|
|
final url = await globalState.showCommonDialog<String>(
|
|
child: const URLFormDialog(),
|
|
);
|
|
if (url != null) {
|
|
_handleAddProfileFormURL(url);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(context) {
|
|
return ListView(
|
|
children: [
|
|
ListItem(
|
|
leading: const Icon(Icons.qr_code_sharp),
|
|
title: Text(appLocalizations.qrcode),
|
|
subtitle: Text(appLocalizations.qrcodeDesc),
|
|
onTap: _toScan,
|
|
),
|
|
ListItem(
|
|
leading: const Icon(Icons.upload_file_sharp),
|
|
title: Text(appLocalizations.file),
|
|
subtitle: Text(appLocalizations.fileDesc),
|
|
onTap: _handleAddProfileFormFile,
|
|
),
|
|
ListItem(
|
|
leading: const Icon(Icons.cloud_download_sharp),
|
|
title: Text(appLocalizations.url),
|
|
subtitle: Text(appLocalizations.urlDesc),
|
|
onTap: _toAdd,
|
|
)
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class URLFormDialog extends StatefulWidget {
|
|
const URLFormDialog({super.key});
|
|
|
|
@override
|
|
State<URLFormDialog> createState() => _URLFormDialogState();
|
|
}
|
|
|
|
class _URLFormDialogState extends State<URLFormDialog> {
|
|
final urlController = TextEditingController();
|
|
|
|
_handleAddProfileFormURL() async {
|
|
final url = urlController.value.text;
|
|
if (url.isEmpty) return;
|
|
Navigator.of(context).pop<String>(url);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CommonDialog(
|
|
title: appLocalizations.importFromURL,
|
|
actions: [
|
|
TextButton(
|
|
onPressed: _handleAddProfileFormURL,
|
|
child: Text(appLocalizations.submit),
|
|
)
|
|
],
|
|
child: SizedBox(
|
|
width: 300,
|
|
child: Wrap(
|
|
runSpacing: 16,
|
|
children: [
|
|
TextField(
|
|
keyboardType: TextInputType.url,
|
|
minLines: 1,
|
|
maxLines: 5,
|
|
onSubmitted: (_) {
|
|
_handleAddProfileFormURL();
|
|
},
|
|
onEditingComplete: _handleAddProfileFormURL,
|
|
controller: urlController,
|
|
decoration: InputDecoration(
|
|
border: const OutlineInputBorder(),
|
|
labelText: appLocalizations.url,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|