Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use SelectableText in GUI for instance info #3852

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
),
),
);
},
);
}
}
5 changes: 3 additions & 2 deletions 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 All @@ -17,7 +18,7 @@ class IpAddresses extends StatelessWidget {
Expanded(
child: Tooltip(
message: firstIp,
child: Text(firstIp.nonBreaking, overflow: TextOverflow.ellipsis),
child: SelectableText(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,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 All @@ -21,7 +23,7 @@ class MemoryUsage extends StatelessWidget {
color: value < 0.8 ? normalColor : almostFullColor,
);

final label = Text(
final label = SelectableText(
value != 0 ? '${_formatMemory(used)} / ${_formatMemory(total)}' : '-',
style: const TextStyle(fontSize: 11),
);
Expand Down
17 changes: 9 additions & 8 deletions 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 Expand Up @@ -76,11 +77,11 @@ class VmDetailsHeader extends ConsumerWidget {

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

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

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

final created = VmStat(
width: 140,
height: baseVmStatHeight,
label: 'CREATED',
child: Text(
child: SelectableText(
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: Text(info.instanceInfo.uptime),
child: SelectableText(info.instanceInfo.uptime),
);

return Column(
Expand Down
7 changes: 4 additions & 3 deletions 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 Expand Up @@ -72,9 +73,9 @@ final headers = <TableHeader<VmInfo>>[
minWidth: 70,
cellBuilder: (info) {
final image = info.instanceInfo.currentRelease;
return Text(
return SelectableText(
image.isNotBlank ? image.nonBreaking : '-',
overflow: TextOverflow.ellipsis,
maxLines: 1,
);
},
),
Expand Down
Loading