Skip to content

Commit

Permalink
create and use WhiteSelectableText in place of SelectableText
Browse files Browse the repository at this point in the history
  • Loading branch information
levkropp committed Dec 19, 2024
1 parent 5f16617 commit 4ba5a94
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 9 deletions.
42 changes: 42 additions & 0 deletions src/client/gui/lib/selectable_text.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:flutter/material.dart';

class WhiteSelectableText extends StatelessWidget {
final String text;
final TextStyle? style;
final TextAlign? textAlign;
final int? maxLines;

const WhiteSelectableText(
this.text, {
super.key,
this.style,
this.textAlign,
this.maxLines,
});

@override
Widget build(BuildContext context) {
final textButtonStyle = Theme.of(context).textButtonTheme.style?.copyWith(
backgroundColor: const MaterialStatePropertyAll(Colors.white),
);

return SelectableText(
text,
style: style?.copyWith(overflow: TextOverflow.ellipsis) ?? const TextStyle(overflow: TextOverflow.ellipsis),
textAlign: textAlign,
maxLines: maxLines,
contextMenuBuilder: (context, editableTextState) {
return TapRegion(
onTapOutside: (_) => ContextMenuController.removeAny(),
child: TextButtonTheme(
data: TextButtonThemeData(style: textButtonStyle),
child: 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 '../extensions.dart';
import '../selectable_text.dart';
import '../tooltip.dart';

class IpAddresses extends StatelessWidget {
Expand All @@ -17,7 +18,7 @@ class IpAddresses extends StatelessWidget {
Expanded(
child: Tooltip(
message: firstIp,
child: SelectableText(firstIp.nonBreaking, maxLines: 1),
child: WhiteSelectableText(firstIp.nonBreaking, maxLines: 1),
),
),
if (restIps.isNotEmpty)
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,5 +1,7 @@
import 'package:flutter/material.dart';

import '../selectable_text.dart';

class MemoryUsage extends StatelessWidget {
final String used;
final String total;
Expand All @@ -21,7 +23,7 @@ class MemoryUsage extends StatelessWidget {
color: value < 0.8 ? normalColor : almostFullColor,
);

final label = SelectableText(
final label = WhiteSelectableText(
value != 0 ? '${_formatMemory(used)} / ${_formatMemory(total)}' : '-',
style: const TextStyle(fontSize: 11),
);
Expand Down
13 changes: 7 additions & 6 deletions src/client/gui/lib/vm_details/vm_details_general.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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 Expand Up @@ -76,7 +77,7 @@ class VmDetailsHeader extends ConsumerWidget {

final list = [
Expanded(
child: SelectableText(
child: WhiteSelectableText(
name.nonBreaking,
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.w300),
maxLines: 1,
Expand Down Expand Up @@ -150,28 +151,28 @@ class GeneralDetails extends ConsumerWidget {
width: 150,
height: baseVmStatHeight,
label: 'IMAGE',
child: SelectableText(info.instanceInfo.currentRelease),
child: WhiteSelectableText(info.instanceInfo.currentRelease),
);

final privateIp = VmStat(
width: 150,
height: baseVmStatHeight,
label: 'PRIVATE IP',
child: SelectableText(info.instanceInfo.ipv4.firstOrNull ?? '-'),
child: WhiteSelectableText(info.instanceInfo.ipv4.firstOrNull ?? '-'),
);

final publicIp = VmStat(
width: 150,
height: baseVmStatHeight,
label: 'PUBLIC IP',
child: SelectableText(info.instanceInfo.ipv4.skip(1).firstOrNull ?? '-'),
child: WhiteSelectableText(info.instanceInfo.ipv4.skip(1).firstOrNull ?? '-'),
);

final created = VmStat(
width: 140,
height: baseVmStatHeight,
label: 'CREATED',
child: SelectableText(
child: WhiteSelectableText(
DateFormat('yyyy-MM-dd HH:mm:ss')
.format(info.instanceInfo.creationTimestamp.toDateTime()),
),
Expand All @@ -181,7 +182,7 @@ class GeneralDetails extends ConsumerWidget {
width: 300,
height: baseVmStatHeight,
label: 'UPTIME',
child: SelectableText(info.instanceInfo.uptime),
child: WhiteSelectableText(info.instanceInfo.uptime),
);

return Column(
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
Expand Up @@ -5,6 +5,7 @@ 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 Expand Up @@ -72,7 +73,7 @@ final headers = <TableHeader<VmInfo>>[
minWidth: 70,
cellBuilder: (info) {
final image = info.instanceInfo.currentRelease;
return SelectableText(
return WhiteSelectableText(
image.isNotBlank ? image.nonBreaking : '-',
maxLines: 1,
);
Expand Down

0 comments on commit 4ba5a94

Please sign in to comment.