Skip to content

Commit 0be05d9

Browse files
Move FormattedJson to devtools_app_shared (flutter#6246)
1 parent ede88ab commit 0be05d9

File tree

6 files changed

+37
-38
lines changed

6 files changed

+37
-38
lines changed

packages/devtools_app/lib/src/screens/performance/panes/timeline_events/legacy/event_details.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import 'package:devtools_app_shared/ui.dart';
66
import 'package:flutter/material.dart';
77

8-
import '../../../../../shared/common_widgets.dart';
98
import '../../../../../shared/primitives/trace_event.dart';
109
import '../../../../../shared/primitives/utils.dart';
1110
import '../../../performance_model.dart';

packages/devtools_app/lib/src/shared/common_widgets.dart

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,34 +1252,6 @@ class _BreadcrumbPainter extends CustomPainter {
12521252
}
12531253
}
12541254

1255-
// TODO(bkonyi): replace uses of this class with `JsonViewer`.
1256-
class FormattedJson extends StatelessWidget {
1257-
const FormattedJson({
1258-
super.key,
1259-
this.json,
1260-
this.formattedString,
1261-
this.useSubtleStyle = false,
1262-
}) : assert((json == null) != (formattedString == null));
1263-
1264-
static const encoder = JsonEncoder.withIndent(' ');
1265-
1266-
final Map<String, dynamic>? json;
1267-
1268-
final String? formattedString;
1269-
1270-
final bool useSubtleStyle;
1271-
1272-
@override
1273-
Widget build(BuildContext context) {
1274-
final theme = Theme.of(context);
1275-
// TODO(kenz): we could consider using a prettier format like YAML.
1276-
return SelectableText(
1277-
json != null ? encoder.convert(json) : formattedString!,
1278-
style: useSubtleStyle ? theme.subtleFixedFontStyle : theme.fixedFontStyle,
1279-
);
1280-
}
1281-
}
1282-
12831255
class JsonViewer extends StatefulWidget {
12841256
const JsonViewer({
12851257
super.key,

packages/devtools_app_shared/example/ui/split_example.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:flutter/material.dart';
88
/// Example of using the [Split] widget from
99
/// 'package:devtools_app_shared/ui.dart' with two children laid across a
1010
/// horizontal axis.
11-
///
11+
///
1212
/// This example does not specify the [Split.splitters] parameter, so a
1313
/// default splitter is used.
1414
class SplitExample extends StatelessWidget {
@@ -31,7 +31,7 @@ class SplitExample extends StatelessWidget {
3131
/// Example of using the [Split] widget from
3232
/// 'package:devtools_app_shared/ui.dart' with three children laid across a
3333
/// vertical axis.
34-
///
34+
///
3535
/// This example uses custom splitters.
3636
class MultiSplitExample extends StatelessWidget {
3737
const MultiSplitExample({super.key});

packages/devtools_app_shared/example/utils/auto_dispose_example.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget>
7070
}
7171
}
7272

73-
/// This is an example of a controller that uses the
73+
/// This is an example of a controller that uses the
7474
/// [AutoDisposeControllerMixin] exposed by
7575
/// 'package:devtools_app_shared/utils.dart'.
76-
///
76+
///
7777
/// When [dispose] is called on this controller, any listeners or stream
7878
/// subscriptions added using the [AutoDisposeControllerMixin] will be disposed
7979
/// or canceled.

packages/devtools_app_shared/lib/src/service/eval_on_dart_library.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,7 @@ class EvalOnDartLibrary extends DisposableController
399399

400400
// start awaiting the event before starting the evaluation, in case the
401401
// event is received before the eval function completes.
402-
final future =
403-
serviceManager.service!.onExtensionEvent.firstWhere((event) {
402+
final future = serviceManager.service!.onExtensionEvent.firstWhere((event) {
404403
return event.extensionKind == 'future_completed' &&
405404
event.extensionData!.data['future_id'] == futureId &&
406405
// Using `_clientId` here as if two chrome tabs open the devtool, it is

packages/devtools_app_shared/lib/src/ui/common.dart

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:convert';
6+
57
import 'package:flutter/material.dart';
68

79
import '../utils/utils.dart';
@@ -110,10 +112,10 @@ class AreaPaneHeader extends StatelessWidget implements PreferredSizeWidget {
110112
}
111113

112114
/// Wraps [child] in a rounded border with default styling.
113-
///
115+
///
114116
/// This border can optionally be made non-uniform by setting any of
115117
/// [showTop], [showBottom], [showLeft] or [showRight] to false.
116-
///
118+
///
117119
/// If [clip] is true, the child will be wrapped in a [ClipRRect] to ensure the
118120
/// rounded corner of the border is drawn as expected. This should not be
119121
/// necessary in most cases.
@@ -191,7 +193,7 @@ final class RoundedOutlinedBorder extends StatelessWidget {
191193
}
192194

193195
/// Wraps [child] in a border with default styling.
194-
///
196+
///
195197
/// This border can optionally be made non-uniform by setting any of
196198
/// [showTop], [showBottom], [showLeft] or [showRight] to false.
197199
final class OutlineDecoration extends StatelessWidget {
@@ -684,3 +686,30 @@ Widget maybeWrapWithTooltip({
684686
}
685687
return child;
686688
}
689+
690+
/// Displays a [json] map as selectable, formatted text.
691+
class FormattedJson extends StatelessWidget {
692+
const FormattedJson({
693+
super.key,
694+
this.json,
695+
this.formattedString,
696+
this.useSubtleStyle = false,
697+
}) : assert((json == null) != (formattedString == null));
698+
699+
static const encoder = JsonEncoder.withIndent(' ');
700+
701+
final Map<String, dynamic>? json;
702+
703+
final String? formattedString;
704+
705+
final bool useSubtleStyle;
706+
707+
@override
708+
Widget build(BuildContext context) {
709+
final theme = Theme.of(context);
710+
return SelectableText(
711+
json != null ? encoder.convert(json) : formattedString!,
712+
style: useSubtleStyle ? theme.subtleFixedFontStyle : theme.fixedFontStyle,
713+
);
714+
}
715+
}

0 commit comments

Comments
 (0)