fix(app): 移除设置页调试服务器地址
This commit is contained in:
1 parent
2b95c79931
commit
061aac6577
6 files changed
+25
-273
No files matched your search
@@ -1,128 +0,0 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import '../config/app_config.dart';
|
||||
import '../config/server_endpoint.dart';
|
||||
import '../theme/app_colors.dart';
|
||||
|
||||
/// Opens the debug-only runtime server address editor.
|
||||
Future<bool> showServerEndpointDialog(
|
||||
BuildContext context,
|
||||
AppLocalizations l10n,
|
||||
) async {
|
||||
final changed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (_) => _ServerEndpointDialog(l10n: l10n),
|
||||
);
|
||||
if (changed == true && context.mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(l10n.restartToApply)));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
class _ServerEndpointDialog extends StatefulWidget {
|
||||
const _ServerEndpointDialog({required this.l10n});
|
||||
|
||||
final AppLocalizations l10n;
|
||||
|
||||
@override
|
||||
State<_ServerEndpointDialog> createState() => _ServerEndpointDialogState();
|
||||
}
|
||||
|
||||
class _ServerEndpointDialogState extends State<_ServerEndpointDialog> {
|
||||
late final TextEditingController _controller = TextEditingController(
|
||||
text: AppConfig.apiBaseUrl,
|
||||
);
|
||||
String? _error;
|
||||
bool _saving = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _save() async {
|
||||
final normalized = ServerEndpoint.normalize(_controller.text);
|
||||
if (normalized == null) {
|
||||
setState(() => _error = widget.l10n.invalidServerAddress);
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_saving = true;
|
||||
_error = null;
|
||||
});
|
||||
final saved = await ServerEndpoint.save(normalized);
|
||||
if (!mounted) return;
|
||||
if (!saved) {
|
||||
setState(() {
|
||||
_saving = false;
|
||||
_error = widget.l10n.invalidServerAddress;
|
||||
});
|
||||
return;
|
||||
}
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
|
||||
Future<void> _restoreDefault() async {
|
||||
setState(() => _saving = true);
|
||||
await ServerEndpoint.clear();
|
||||
if (mounted) Navigator.pop(context, true);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = widget.l10n;
|
||||
return AlertDialog(
|
||||
title: Text(l10n.serverAddress),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TextField(
|
||||
key: const Key('server-endpoint-input'),
|
||||
controller: _controller,
|
||||
enabled: !_saving,
|
||||
keyboardType: TextInputType.url,
|
||||
autocorrect: false,
|
||||
decoration: InputDecoration(
|
||||
hintText: l10n.serverAddressHint,
|
||||
errorText: _error,
|
||||
errorMaxLines: 2,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
l10n.restartToApply,
|
||||
key: const Key('server-endpoint-restart-hint'),
|
||||
style: const TextStyle(color: AppColors.muted, fontSize: 12),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
TextButton(
|
||||
key: const Key('server-endpoint-restore'),
|
||||
onPressed: _saving ? null : _restoreDefault,
|
||||
child: Text(l10n.restoreDefault),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: _saving ? null : () => Navigator.pop(context, false),
|
||||
child: Text(l10n.cancel),
|
||||
),
|
||||
FilledButton(
|
||||
key: const Key('server-endpoint-save'),
|
||||
onPressed: _saving ? null : _save,
|
||||
child: Text(l10n.saveAddress),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user