diff --git a/src/client/gui/lib/selectable_text.dart b/src/client/gui/lib/selectable_text.dart new file mode 100644 index 0000000000..d427d643c0 --- /dev/null +++ b/src/client/gui/lib/selectable_text.dart @@ -0,0 +1,43 @@ +import 'package:flutter/material.dart' as fl; + +class SelectableText extends fl.StatelessWidget { + final String text; + final fl.TextStyle? style; + final fl.TextAlign? textAlign; + final int? maxLines; + + const SelectableText( + this.text, { + super.key, + this.style, + this.textAlign, + this.maxLines, + }); + + @override + fl.Widget build(fl.BuildContext context) { + final textButtonStyle = fl.Theme.of(context).textButtonTheme.style?.copyWith( + backgroundColor: const fl.WidgetStatePropertyAll(fl.Colors.transparent), + ); + + return fl.SelectableText( + text, + style: style?.copyWith(overflow: fl.TextOverflow.ellipsis) ?? + const fl.TextStyle(overflow: fl.TextOverflow.ellipsis), + textAlign: textAlign, + maxLines: maxLines, + contextMenuBuilder: (context, editableTextState) { + return fl.TapRegion( + onTapOutside: (_) => fl.ContextMenuController.removeAny(), + child: fl.TextButtonTheme( + data: fl.TextButtonThemeData(style: textButtonStyle), + child: fl.AdaptiveTextSelectionToolbar.buttonItems( + anchors: editableTextState.contextMenuAnchors, + buttonItems: editableTextState.contextMenuButtonItems, + ), + ), + ); + }, + ); + } +} diff --git a/src/client/gui/lib/vm_details/ip_addresses.dart b/src/client/gui/lib/vm_details/ip_addresses.dart index 84ce2c890e..f8716c46c2 100644 --- a/src/client/gui/lib/vm_details/ip_addresses.dart +++ b/src/client/gui/lib/vm_details/ip_addresses.dart @@ -1,6 +1,7 @@ -import 'package:flutter/material.dart' hide Tooltip; +import 'package:flutter/material.dart' hide Tooltip, SelectableText; import '../extensions.dart'; +import '../selectable_text.dart'; import '../tooltip.dart'; class IpAddresses extends StatelessWidget { diff --git a/src/client/gui/lib/vm_details/memory_usage.dart b/src/client/gui/lib/vm_details/memory_usage.dart index 6cba5047c7..61e991d8e1 100644 --- a/src/client/gui/lib/vm_details/memory_usage.dart +++ b/src/client/gui/lib/vm_details/memory_usage.dart @@ -1,4 +1,6 @@ -import 'package:flutter/material.dart'; +import 'package:flutter/material.dart' hide SelectableText; + +import '../selectable_text.dart'; class MemoryUsage extends StatelessWidget { final String used; diff --git a/src/client/gui/lib/vm_details/vm_details_general.dart b/src/client/gui/lib/vm_details/vm_details_general.dart index c8f3a6209c..26dfa016af 100644 --- a/src/client/gui/lib/vm_details/vm_details_general.dart +++ b/src/client/gui/lib/vm_details/vm_details_general.dart @@ -1,10 +1,11 @@ import 'package:basics/basics.dart'; -import 'package:flutter/material.dart'; +import 'package:flutter/material.dart' hide SelectableText; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:intl/intl.dart'; import '../extensions.dart'; import '../providers.dart'; +import '../selectable_text.dart'; import 'cpu_sparkline.dart'; import 'memory_usage.dart'; import 'vm_action_buttons.dart'; diff --git a/src/client/gui/lib/vm_table/vm_table_headers.dart b/src/client/gui/lib/vm_table/vm_table_headers.dart index ebac8f94aa..895dceee18 100644 --- a/src/client/gui/lib/vm_table/vm_table_headers.dart +++ b/src/client/gui/lib/vm_table/vm_table_headers.dart @@ -1,10 +1,11 @@ import 'package:basics/basics.dart'; import 'package:built_collection/built_collection.dart'; -import 'package:flutter/material.dart' hide Tooltip; +import 'package:flutter/material.dart' hide Tooltip, SelectableText; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../extensions.dart'; import '../providers.dart'; +import '../selectable_text.dart'; import '../sidebar.dart'; import '../tooltip.dart'; import '../vm_details/cpu_sparkline.dart';