From 7244daf4212dbc7a73b8b4d332b68a9146c81dd9 Mon Sep 17 00:00:00 2001 From: Birgitt Majas Date: Thu, 6 Jun 2024 21:29:55 +0300 Subject: [PATCH] [MDS-1176] Fix input components context menu --- example/lib/main.dart | 43 ++++------------------ lib/src/widgets/text_input/text_input.dart | 15 +++++--- 2 files changed, 17 insertions(+), 41 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index de859d27..425fd221 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -16,19 +16,10 @@ void main() async { runApp(const MyApp()); } -class MyApp extends StatefulWidget { +class MyApp extends StatelessWidget { const MyApp({super.key}); - @override - State createState() => _MyAppState(); -} - -class _MyAppState extends State { - bool _isInStorybookMode = true; - - void toggleStorybookMode() { - setState(() => _isInStorybookMode = !_isInStorybookMode); - } + bool get _isInStorybookMode => true; @override Widget build(BuildContext context) { @@ -47,31 +38,11 @@ class _MyAppState extends State { ), home: Scaffold( body: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - "Moon Design for Flutter", - style: TextStyle( - fontSize: - MediaQuery.of(context).size.width > 800 ? 72 : 32, - ), - ), - SizedBox( - height: MediaQuery.of(context).size.width > 800 ? 36 : 16, - ), - GestureDetector( - onLongPress: toggleStorybookMode, - child: Text( - "Coming soon...", - style: TextStyle( - fontSize: - MediaQuery.of(context).size.width > 800 ? 24 : 20, - color: const Color(0xFF999CA0), - ), - ), - ), - ], + child: Text( + "Moon Design for Flutter", + style: TextStyle( + fontSize: MediaQuery.of(context).size.width > 800 ? 72 : 32, + ), ), ), ), diff --git a/lib/src/widgets/text_input/text_input.dart b/lib/src/widgets/text_input/text_input.dart index 6de0a990..dc0b94b5 100644 --- a/lib/src/widgets/text_input/text_input.dart +++ b/lib/src/widgets/text_input/text_input.dart @@ -1117,16 +1117,16 @@ class _MoonTextInputState extends State ? hoverBorder : defaultBorder; + final bool paintCursorAboveText; + final Color cursorColor; + final Color selectionColor; + bool? cursorOpacityAnimates = widget.cursorOpacityAnimates; Color? autocorrectionTextRectColor; Offset? cursorOffset; Radius? cursorRadius = widget.cursorRadius; VoidCallback? handleDidGainAccessibilityFocus; - - final bool paintCursorAboveText; - final Color cursorColor; - final Color selectionColor; - final TextSelectionControls? textSelectionControls = widget.selectionControls; + TextSelectionControls? textSelectionControls = widget.selectionControls; final MouseCursor effectiveMouseCursor = MaterialStateProperty.resolveAs( widget.mouseCursor ?? MaterialStateMouseCursor.textable, @@ -1169,6 +1169,7 @@ class _MoonTextInputState extends State case TargetPlatform.iOS: final CupertinoThemeData cupertinoTheme = CupertinoTheme.of(context); forcePressEnabled = true; + textSelectionControls ??= cupertinoTextSelectionHandleControls; paintCursorAboveText = true; cursorOpacityAnimates ??= true; cursorColor = _hasError ? effectiveCursorErrorColor : widget.cursorColor ?? effectiveTextColor; @@ -1180,6 +1181,7 @@ class _MoonTextInputState extends State case TargetPlatform.macOS: final CupertinoThemeData cupertinoTheme = CupertinoTheme.of(context); forcePressEnabled = false; + textSelectionControls ??= cupertinoDesktopTextSelectionHandleControls; paintCursorAboveText = true; cursorOpacityAnimates ??= false; cursorColor = _hasError ? effectiveCursorErrorColor : widget.cursorColor ?? effectiveTextColor; @@ -1196,6 +1198,7 @@ class _MoonTextInputState extends State case TargetPlatform.android: case TargetPlatform.fuchsia: forcePressEnabled = false; + textSelectionControls ??= materialTextSelectionHandleControls; paintCursorAboveText = false; cursorOpacityAnimates ??= false; cursorColor = _hasError ? effectiveCursorErrorColor : widget.cursorColor ?? effectiveTextColor; @@ -1203,6 +1206,7 @@ class _MoonTextInputState extends State case TargetPlatform.linux: forcePressEnabled = false; + textSelectionControls ??= desktopTextSelectionHandleControls; paintCursorAboveText = false; cursorOpacityAnimates ??= false; cursorColor = _hasError ? effectiveCursorErrorColor : widget.cursorColor ?? effectiveTextColor; @@ -1210,6 +1214,7 @@ class _MoonTextInputState extends State case TargetPlatform.windows: forcePressEnabled = false; + textSelectionControls ??= desktopTextSelectionHandleControls; paintCursorAboveText = false; cursorOpacityAnimates ??= false; cursorColor = _hasError ? effectiveCursorErrorColor : widget.cursorColor ?? effectiveTextColor;