From 25f1ed29d1b3e0624f765c6d1556e95afe0e367f Mon Sep 17 00:00:00 2001 From: CryptoFish Date: Wed, 1 Feb 2023 12:05:52 +0100 Subject: [PATCH] Define contextMenuBuilder for InputField widget --- lib/utils/app_theme.dart | 2 ++ .../input_fields/input_field.dart | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/utils/app_theme.dart b/lib/utils/app_theme.dart index 556772c7..784e4fa2 100644 --- a/lib/utils/app_theme.dart +++ b/lib/utils/app_theme.dart @@ -139,6 +139,7 @@ class AppTheme { scaffoldBackgroundColor: AppColors.backgroundLight, textSelectionTheme: const TextSelectionThemeData( cursorColor: AppColors.znnColor, + selectionHandleColor: AppColors.znnColor, ), fontFamily: 'Roboto', inputDecorationTheme: InputDecorationTheme( @@ -276,6 +277,7 @@ class AppTheme { textSelectionTheme: TextSelectionThemeData( selectionColor: Colors.white.withOpacity(0.1), cursorColor: AppColors.znnColor, + selectionHandleColor: AppColors.znnColor, ), fontFamily: 'Roboto', inputDecorationTheme: InputDecorationTheme( diff --git a/lib/widgets/reusable_widgets/input_fields/input_field.dart b/lib/widgets/reusable_widgets/input_fields/input_field.dart index 7c3b9601..d40fc02c 100644 --- a/lib/widgets/reusable_widgets/input_fields/input_field.dart +++ b/lib/widgets/reusable_widgets/input_fields/input_field.dart @@ -64,6 +64,26 @@ class _InputFieldState extends State { @override Widget build(BuildContext context) { return TextFormField( + contextMenuBuilder: (context, editableTextState) { + return AdaptiveTextSelectionToolbar( + anchors: editableTextState.contextMenuAnchors, + children: editableTextState.contextMenuButtonItems + .map((ContextMenuButtonItem buttonItem) { + return Row(children: [ + Expanded( + child: TextButton( + onPressed: buttonItem.onPressed, + style: TextButton.styleFrom( + shape: const RoundedRectangleBorder(), + ), + child: Text( + AdaptiveTextSelectionToolbar.getButtonLabel( + context, buttonItem), + style: const TextStyle(color: Colors.white)), + )) + ]); + }).toList()); + }, maxLines: widget.maxLines, obscureText: widget.obscureText, onChanged: widget.onChanged,