Skip to content

Commit 16b24b5

Browse files
committed
Reuse OverflowingText for debugger variable rows
1 parent 9cd9fed commit 16b24b5

1 file changed

Lines changed: 77 additions & 68 deletions

File tree

packages/devtools_app/lib/src/shared/console/widgets/display_provider.dart

Lines changed: 77 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@ import '../../primitives/utils.dart';
1919
import '../../ui/colors.dart';
2020
import 'description.dart';
2121

22+
class OverflowingText extends StatelessWidget {
23+
const OverflowingText({
24+
super.key,
25+
required this.textSpan,
26+
this.tooltipMessage,
27+
});
28+
29+
final InlineSpan textSpan;
30+
final String? tooltipMessage;
31+
32+
@override
33+
Widget build(BuildContext context) {
34+
final textWidget = Text.rich(
35+
textSpan,
36+
maxLines: 1,
37+
softWrap: false,
38+
overflow: TextOverflow.ellipsis,
39+
);
40+
final message = tooltipMessage;
41+
if (message == null) return textWidget;
42+
return DevToolsTooltip(message: message, child: textWidget);
43+
}
44+
}
45+
2246
/// The display provider for variables fetched via the VM service protocol.
2347
class DisplayProvider extends StatefulWidget {
2448
const DisplayProvider({
@@ -46,17 +70,12 @@ class _DisplayProviderState extends State<DisplayProvider> {
4670
return InteractivityWrapper(
4771
onTap: widget.onTap,
4872
menuButtons: _getMenuButtons(context),
49-
child: DevToolsTooltip(
50-
message: widget.variable.text,
51-
child: Text.rich(
52-
maxLines: 1,
53-
softWrap: false,
54-
overflow: TextOverflow.ellipsis,
55-
TextSpan(
56-
children: textSpansFromAnsi(
57-
widget.variable.text!,
58-
theme.subtleFixedFontStyle,
59-
),
73+
child: OverflowingText(
74+
tooltipMessage: widget.variable.text,
75+
textSpan: TextSpan(
76+
children: textSpansFromAnsi(
77+
widget.variable.text!,
78+
theme.subtleFixedFontStyle,
6079
),
6180
),
6281
),
@@ -85,45 +104,40 @@ class _DisplayProviderState extends State<DisplayProvider> {
85104
final contents = InteractivityWrapper(
86105
onTap: widget.onTap,
87106
menuButtons: _getMenuButtons(context),
88-
child: DevToolsTooltip(
89-
message: originalDisplayValue,
90-
child: Container(
91-
color: isHovered ? Theme.of(context).highlightColor : null,
92-
child: Row(
93-
children: [
94-
Expanded(
95-
child: Text.rich(
96-
maxLines: 1,
97-
softWrap: false,
98-
overflow: TextOverflow.ellipsis,
99-
TextSpan(
100-
text: hasName ? widget.variable.name : null,
101-
style: widget.variable.artificialName
102-
? theme.subtleFixedFontStyle
103-
: theme.fixedFontStyle.apply(
104-
color: theme.colorScheme.controlFlowSyntaxColor,
105-
),
106-
children: [
107-
if (hasName)
108-
TextSpan(text: ': ', style: theme.fixedFontStyle),
109-
TextSpan(
110-
text: displayValue,
111-
style: widget.variable.artificialValue
112-
? theme.subtleFixedFontStyle
113-
: _variableDisplayStyle(theme, widget.variable),
114-
),
115-
],
116-
),
107+
child: Container(
108+
color: isHovered ? Theme.of(context).highlightColor : null,
109+
child: Row(
110+
children: [
111+
Expanded(
112+
child: OverflowingText(
113+
tooltipMessage: originalDisplayValue,
114+
textSpan: TextSpan(
115+
text: hasName ? widget.variable.name : null,
116+
style: widget.variable.artificialName
117+
? theme.subtleFixedFontStyle
118+
: theme.fixedFontStyle.apply(
119+
color: theme.colorScheme.controlFlowSyntaxColor,
120+
),
121+
children: [
122+
if (hasName)
123+
TextSpan(text: ': ', style: theme.fixedFontStyle),
124+
TextSpan(
125+
text: displayValue,
126+
style: widget.variable.artificialValue
127+
? theme.subtleFixedFontStyle
128+
: _variableDisplayStyle(theme, widget.variable),
129+
),
130+
],
117131
),
118132
),
119-
if (isHovered && widget.onCopy != null)
120-
DevToolsButton(
121-
icon: Icons.copy_outlined,
122-
outlined: false,
123-
onPressed: () => widget.onCopy!.call(widget.variable),
124-
),
125-
],
126-
),
133+
),
134+
if (isHovered && widget.onCopy != null)
135+
DevToolsButton(
136+
icon: Icons.copy_outlined,
137+
outlined: false,
138+
onPressed: () => widget.onCopy!.call(widget.variable),
139+
),
140+
],
127141
),
128142
),
129143
);
@@ -255,27 +269,22 @@ class DapDisplayProvider extends StatelessWidget {
255269
// TODO(https://github.com/flutter/devtools/issues/6056): Wrap in
256270
// interactivity wrapper to provide inspect and re-root functionality. Add
257271
// tooltip on hover to provide type information.
258-
return DevToolsTooltip(
259-
message: value,
260-
child: Text.rich(
261-
maxLines: 1,
262-
softWrap: false,
263-
overflow: TextOverflow.ellipsis,
264-
TextSpan(
265-
text: name,
266-
style: theme.fixedFontStyle.apply(
267-
color: theme.colorScheme.controlFlowSyntaxColor,
268-
),
269-
children: [
270-
TextSpan(text: ': ', style: theme.fixedFontStyle),
271-
// TODO(https://github.com/flutter/devtools/issues/6056): Change text
272-
// style based on variable type.
273-
TextSpan(
274-
text: value.replaceAll('\n', '\\n'),
275-
style: theme.subtleFixedFontStyle,
276-
),
277-
],
272+
return OverflowingText(
273+
tooltipMessage: value,
274+
textSpan: TextSpan(
275+
text: name,
276+
style: theme.fixedFontStyle.apply(
277+
color: theme.colorScheme.controlFlowSyntaxColor,
278278
),
279+
children: [
280+
TextSpan(text: ': ', style: theme.fixedFontStyle),
281+
// TODO(https://github.com/flutter/devtools/issues/6056): Change text
282+
// style based on variable type.
283+
TextSpan(
284+
text: value.replaceAll('\n', '\\n'),
285+
style: theme.subtleFixedFontStyle,
286+
),
287+
],
279288
),
280289
);
281290
}

0 commit comments

Comments
 (0)