Skip to content

Commit

Permalink
create and use a custom SelectableText in vm table and details page
Browse files Browse the repository at this point in the history
  • Loading branch information
levkropp committed Dec 20, 2024
1 parent 5f16617 commit 0d04f37
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
43 changes: 43 additions & 0 deletions src/client/gui/lib/selectable_text.dart
Original file line number Diff line number Diff line change
@@ -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,
),
),
);
},
);
}
}
3 changes: 2 additions & 1 deletion src/client/gui/lib/vm_details/ip_addresses.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion src/client/gui/lib/vm_details/memory_usage.dart
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/client/gui/lib/vm_details/vm_details_general.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
3 changes: 2 additions & 1 deletion src/client/gui/lib/vm_table/vm_table_headers.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down

0 comments on commit 0d04f37

Please sign in to comment.