Validate proxy port input and show error for out-of-range values

This commit is contained in:
wanghongenpin
2026-03-07 11:51:56 +08:00
parent 8013615b4d
commit 0095344b50
2 changed files with 10 additions and 1 deletions

View File

@@ -30,7 +30,14 @@ class _PortState extends State<PortWidget> {
portFocus.addListener(() async { portFocus.addListener(() async {
//失去焦点 //失去焦点
if (!portFocus.hasFocus && textController.text != widget.proxyServer.port.toString()) { if (!portFocus.hasFocus && textController.text != widget.proxyServer.port.toString()) {
widget.proxyServer.configuration.port = int.parse(textController.text); final port = int.tryParse(textController.text) ?? -1;
if (port < 0 || port > 65535) {
textController.text = widget.proxyServer.port.toString();
FlutterToastr.show("Port out of range 0-65535", context, duration: 3);
return;
}
widget.proxyServer.configuration.port = port;
if (widget.proxyServer.isRunning) { if (widget.proxyServer.isRunning) {
String message = localizations.proxyPortRepeat(widget.proxyServer.port); String message = localizations.proxyPortRepeat(widget.proxyServer.port);

View File

@@ -10,6 +10,7 @@ import device_info_plus
import file_picker import file_picker
import flutter_desktop_context_menu import flutter_desktop_context_menu
import flutter_js import flutter_js
import path_provider_foundation
import proxy_manager import proxy_manager
import screen_retriever_macos import screen_retriever_macos
import share_plus import share_plus
@@ -24,6 +25,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FilePickerPlugin.register(with: registry.registrar(forPlugin: "FilePickerPlugin")) FilePickerPlugin.register(with: registry.registrar(forPlugin: "FilePickerPlugin"))
FlutterDesktopContextMenuPlugin.register(with: registry.registrar(forPlugin: "FlutterDesktopContextMenuPlugin")) FlutterDesktopContextMenuPlugin.register(with: registry.registrar(forPlugin: "FlutterDesktopContextMenuPlugin"))
FlutterJsPlugin.register(with: registry.registrar(forPlugin: "FlutterJsPlugin")) FlutterJsPlugin.register(with: registry.registrar(forPlugin: "FlutterJsPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
ProxyManagerPlugin.register(with: registry.registrar(forPlugin: "ProxyManagerPlugin")) ProxyManagerPlugin.register(with: registry.registrar(forPlugin: "ProxyManagerPlugin"))
ScreenRetrieverMacosPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverMacosPlugin")) ScreenRetrieverMacosPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverMacosPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin")) SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))