Skip to content

Commit

Permalink
create and use WhitePopupMenuSelectableText in place of SelectableText
Browse files Browse the repository at this point in the history
  • Loading branch information
levkropp committed Dec 18, 2024
1 parent 5f16617 commit 1719d61
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 13 deletions.
42 changes: 42 additions & 0 deletions src/client/gui/lib/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,45 @@ extension NullableMap<T> on T? {
}
}
}

/// A custom wrapper for SelectableText with a white popup (right-click) menu.
class WhitePopupMenuSelectableText extends StatelessWidget {
final String text;
final TextStyle? style;
final TextAlign? textAlign;
final int? maxLines;

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

@override
Widget build(BuildContext context) {
final textButtonStyle = Theme.of(context).textButtonTheme.style?.copyWith(
backgroundColor: const WidgetStatePropertyAll(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,
),
),
);
},
);
}
}
2 changes: 1 addition & 1 deletion src/client/gui/lib/vm_details/ip_addresses.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class IpAddresses extends StatelessWidget {
Expanded(
child: Tooltip(
message: firstIp,
child: SelectableText(firstIp.nonBreaking, maxLines: 1),
child: WhitePopupMenuSelectableText(text: firstIp.nonBreaking, maxLines: 1),
),
),
if (restIps.isNotEmpty)
Expand Down
6 changes: 4 additions & 2 deletions 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 '../extensions.dart';

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

final label = SelectableText(
value != 0 ? '${_formatMemory(used)} / ${_formatMemory(total)}' : '-',
final label = WhitePopupMenuSelectableText(
text: value != 0 ? '${_formatMemory(used)} / ${_formatMemory(total)}' : '-',
style: const TextStyle(fontSize: 11),
);

Expand Down
16 changes: 8 additions & 8 deletions src/client/gui/lib/vm_details/vm_details_general.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class VmDetailsHeader extends ConsumerWidget {

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

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

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

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

return Column(
Expand Down
4 changes: 2 additions & 2 deletions src/client/gui/lib/vm_table/vm_table_headers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ final headers = <TableHeader<VmInfo>>[
minWidth: 70,
cellBuilder: (info) {
final image = info.instanceInfo.currentRelease;
return SelectableText(
image.isNotBlank ? image.nonBreaking : '-',
return WhitePopupMenuSelectableText(
text: image.isNotBlank ? image.nonBreaking : '-',
maxLines: 1,
);
},
Expand Down

0 comments on commit 1719d61

Please sign in to comment.