Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

Keep the caret in dialog text fields on Flutter 3.44 desktop builds (#17146)

RustDesk144a743d0a5c
diff --git a/.github/patches/apply_flutter_3.44_source_patches.sh b/.github/patches/apply_flutter_3.44_source_patches.sh
index 0f40ddd5c..ab82b4ee4 100644
--- a/.github/patches/apply_flutter_3.44_source_patches.sh
+++ b/.github/patches/apply_flutter_3.44_source_patches.sh
@@ -8,6 +8,12 @@
# 3.24.5, where the old names/versions are required, so these changes are kept OUT of the
# committed sources and applied here instead.
#
+# 3.44 also makes desktop text fields select all their text each time they regain focus, which
+# 3.24 did only on web. A dialog stacked on another (the 2FA code over the login dialog) bounces
+# focus on every rebuild, so each typed digit replaced the last
+# (https://github.com/rustdesk/rustdesk/issues/17143). DialogTextField keeps 3.24's desktop
+# behavior; 3.24 has no selectAllOnFocus parameter, hence the patch.
+#
# Used by BOTH arm64 builds (flutter-build.yml) and their shared bridge artifact (bridge.yml) so
# they share an identical 3.44 source state -- the generated *.freezed.dart must compile against
# the same Flutter/freezed version the arm64 builds resolve.
@@ -74,6 +80,10 @@ validate_patch_inputs() {
echo "Flutter 3.44 source patch input is missing or unreadable: flutter/pubspec.yaml" >&2
return 1
fi
+ if [[ ! -f flutter/lib/common/widgets/dialog.dart || ! -r flutter/lib/common/widgets/dialog.dart ]]; then
+ echo "Flutter 3.44 source patch input is missing or unreadable: flutter/lib/common/widgets/dialog.dart" >&2
+ return 1
+ fi
}
is_complete_patch_state() {
@@ -92,7 +102,9 @@ is_complete_patch_state() {
flutter/lib/common.dart &&
has_dialog_background_in_theme_range 'static ThemeData darkTheme = ThemeData(' \
'scrollbarTheme: scrollbarThemeDark,' 'backgroundColor: Color(0xFF18191E),' \
- flutter/lib/common.dart
+ flutter/lib/common.dart &&
+ has_exact_count "$SINGLE_MATCH" 'selectAllOnFocus: isDesktop ? false : null,' \
+ flutter/lib/common/widgets/dialog.dart
}
is_unpatched_state() {
@@ -105,7 +117,10 @@ is_unpatched_state() {
has_exact_count "$NO_MATCHES" 'backgroundColor: Colors.white,' flutter/lib/common.dart &&
has_exact_count "$NO_MATCHES" 'backgroundColor: Color(0xFF18191E),' flutter/lib/common.dart &&
has_exact_count "$NO_MATCHES" 'extended_text: 15.0.2' flutter/pubspec.yaml &&
- has_exact_count "$NO_MATCHES" 'google_fonts: ^8.1.0' flutter/pubspec.yaml
+ has_exact_count "$NO_MATCHES" 'google_fonts: ^8.1.0' flutter/pubspec.yaml &&
+ has_exact_count "$SINGLE_MATCH" 'inputFormatters: inputFormatters,' \
+ flutter/lib/common/widgets/dialog.dart &&
+ has_exact_count "$NO_MATCHES" 'selectAllOnFocus' flutter/lib/common/widgets/dialog.dart
}
if ! validate_patch_inputs; then
@@ -114,7 +129,8 @@ fi
if is_complete_patch_state; then
echo "Flutter 3.44 source patches already applied."
- git --no-pager diff -- flutter/lib/common.dart flutter/pubspec.yaml
+ git --no-pager diff -- flutter/lib/common.dart flutter/pubspec.yaml \
+ flutter/lib/common/widgets/dialog.dart
exit 0
fi
@@ -133,6 +149,9 @@ sed -i '/static ThemeData darkTheme = ThemeData(/,/scrollbarTheme: scrollbarThem
# Dependency bumps required by the newer Dart/Flutter:
sed -i 's/extended_text: 14.0.0/extended_text: 15.0.2/' flutter/pubspec.yaml
sed -i 's/google_fonts: \^6.2.1/google_fonts: ^8.1.0/' flutter/pubspec.yaml
+# DialogTextField keeps the caret when a desktop field regains focus (see the header):
+sed -i 's/inputFormatters: inputFormatters,/inputFormatters: inputFormatters,\
+ selectAllOnFocus: isDesktop ? false : null,/' flutter/lib/common/widgets/dialog.dart
# Fail loudly if any expected substitution did not produce the complete state.
if ! is_complete_patch_state; then
@@ -140,4 +159,5 @@ if ! is_complete_patch_state; then
exit 1
fi
-git --no-pager diff -- flutter/lib/common.dart flutter/pubspec.yaml
+git --no-pager diff -- flutter/lib/common.dart flutter/pubspec.yaml \
+ flutter/lib/common/widgets/dialog.dart
diff --git a/.github/patches/apply_flutter_3.44_web_patches.sh b/.github/patches/apply_flutter_3.44_web_patches.sh
index 24ce7f1b4..5d73a95c9 100755
--- a/.github/patches/apply_flutter_3.44_web_patches.sh
+++ b/.github/patches/apply_flutter_3.44_web_patches.sh
@@ -11,7 +11,8 @@
# (cd flutter && flutter build web --release) # or ./web/js/flutter_build.py
#
# Idempotent. To undo the source changes locally:
-# git checkout -- flutter/lib/common.dart flutter/pubspec.yaml flutter/pubspec.lock
+# git checkout -- flutter/lib/common.dart flutter/lib/common/widgets/dialog.dart \
+# flutter/pubspec.yaml flutter/pubspec.lock
set -euo pipefail
flutter --version | grep -q "Flutter 3\.44\." || {
diff --git a/flutter/test/dialog_text_field_focus_test.dart b/flutter/test/dialog_text_field_focus_test.dart
new file mode 100644
index 000000000..0c131fbee
--- /dev/null
+++ b/flutter/test/dialog_text_field_focus_test.dart
@@ -0,0 +1,32 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:flutter_hbb/common/widgets/dialog.dart';
+
+void main() {
+ // Passes trivially on Flutter 3.24; the macOS arm64 CI job runs it against
+ // the 3.44-patched sources, where desktop fields select all on focus (#17143).
+ testWidgets('dialog text field keeps the caret when it regains focus',
+ (tester) async {
+ final controller = TextEditingController();
+ final focusNode = FocusNode();
+ addTearDown(controller.dispose);
+ addTearDown(focusNode.dispose);
+
+ await tester.pumpWidget(MaterialApp(
+ home: Scaffold(
+ body: DialogTextField(
+ title: '2FA code',
+ controller: controller,
+ focusNode: focusNode,
+ ),
+ ),
+ ));
+ await tester.enterText(find.byType(TextField), '1');
+ focusNode.unfocus();
+ await tester.pump();
+ focusNode.requestFocus();
+ await tester.pump();
+
+ expect(controller.selection, const TextSelection.collapsed(offset: 1));
+ }, variant: TargetPlatformVariant.desktop());
+}