Skip to content

Commit 8212c72

Browse files
authored
Reorganize constants to be closer to place where they are used. (#4895)
1 parent 1608657 commit 8212c72

File tree

7 files changed

+27
-30
lines changed

7 files changed

+27
-30
lines changed

packages/devtools_app/lib/src/screens/memory/panes/chart/chart_control_pane.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import '../../../../shared/theme.dart';
1212
import '../../../../shared/utils.dart';
1313
import '../../memory_controller.dart';
1414
import '../../primitives/ui.dart';
15-
import '../../shared/constants.dart';
1615
import 'chart_pane_controller.dart';
1716
import 'interval_dropdown.dart';
1817

@@ -97,7 +96,6 @@ class _ChartControlPaneState extends State<ChartControlPane>
9796
ValueListenableBuilder<bool>(
9897
valueListenable: controller.legendVisibleNotifier,
9998
builder: (_, legendVisible, __) => IconLabelButton(
100-
key: legendKey,
10199
onPressed: () {
102100
controller.toggleLegendVisibility();
103101
if (legendVisible) {

packages/devtools_app/lib/src/screens/memory/panes/chart/legend.dart

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,22 @@ import 'package:flutter/material.dart';
66

77
import '../../../../shared/common_widgets.dart';
88
import '../../../../shared/theme.dart';
9+
import '../../../../shared/utils.dart';
910
import '../../primitives/painting.dart';
10-
import '../../shared/constants.dart';
1111
import 'chart_pane_controller.dart';
1212
import 'memory_android_chart.dart';
1313
import 'memory_charts.dart';
1414
import 'memory_events_pane.dart';
1515
import 'memory_vm_chart.dart';
1616

17+
late final _legendWidth = scaleByFontFactor(200.0);
18+
late final _legendTextWidth = scaleByFontFactor(55.0);
19+
late final _legendHeight1Chart = scaleByFontFactor(200.0);
20+
late final _legendHeight2Charts = scaleByFontFactor(323.0);
21+
22+
/// Padding for each title in the legend.
23+
const _legendTitlePadding = EdgeInsets.fromLTRB(5, 0, 0, 4);
24+
1725
class MemoryChartLegend extends StatelessWidget {
1826
const MemoryChartLegend({
1927
super.key,
@@ -35,7 +43,7 @@ class MemoryChartLegend extends StatelessWidget {
3543
final events = eventLegendContent(colorScheme.isLight);
3644
legendRows.add(
3745
Container(
38-
padding: legendTitlePadding,
46+
padding: _legendTitlePadding,
3947
child: Text('Events Legend', style: legendHeading),
4048
),
4149
);
@@ -56,7 +64,7 @@ class MemoryChartLegend extends StatelessWidget {
5664
final vms = vmLegendContent(chartController.vm);
5765
legendRows.add(
5866
Container(
59-
padding: legendTitlePadding,
67+
padding: _legendTitlePadding,
6068
child: Text('Memory Legend', style: legendHeading),
6169
),
6270
);
@@ -74,7 +82,7 @@ class MemoryChartLegend extends StatelessWidget {
7482
final androids = androidLegendContent(chartController.android);
7583
legendRows.add(
7684
Container(
77-
padding: legendTitlePadding,
85+
padding: _legendTitlePadding,
7886
child: Text('Android Legend', style: legendHeading),
7987
),
8088
);
@@ -90,10 +98,10 @@ class MemoryChartLegend extends StatelessWidget {
9098
}
9199

92100
return Container(
93-
width: legendWidth,
101+
width: _legendWidth,
94102
// The height is specified here,
95103
// because [legendRows] are designed to take all available space.
96-
height: isAndroidVisible ? legendHeight2Charts : legendHeight1Chart,
104+
height: isAndroidVisible ? _legendHeight2Charts : _legendHeight1Chart,
97105
padding: const EdgeInsets.fromLTRB(0, densePadding, densePadding, 0),
98106
decoration: BoxDecoration(
99107
color: colorScheme.defaultBackgroundColor,
@@ -135,7 +143,7 @@ class LegendRow extends StatelessWidget {
135143
Expanded(
136144
child: Container(
137145
padding: EdgeInsets.fromLTRB(leftEdge, 0, 0, 2),
138-
width: legendTextWidth + leftEdge,
146+
width: _legendTextWidth + leftEdge,
139147
child: Text(name, style: legendEntry),
140148
),
141149
),
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2019 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/foundation.dart';
6+
7+
const memorySourceMenuItemPrefix = 'Source: ';
8+
const sourcesDropdownKey = Key('Sources Dropdown');
9+
const sourcesKey = Key('Sources');

packages/devtools_app/lib/src/screens/memory/panes/control/secondary_controls.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import '../../memory_controller.dart';
1515
import '../../primitives/ui.dart';
1616
import '../../shared/constants.dart';
1717
import '../chart/chart_pane_controller.dart';
18+
import 'primitives.dart';
1819
import 'settings_dialog.dart';
1920
import 'source_dropdown.dart';
2021

packages/devtools_app/lib/src/screens/memory/panes/control/source_dropdown.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:flutter/material.dart';
77
import '../../../../shared/common_widgets.dart';
88
import '../../../../shared/utils.dart';
99
import '../../memory_controller.dart';
10-
import '../../shared/constants.dart';
10+
import 'primitives.dart';
1111

1212
class SourceDropdownMenuItem<T> extends DropdownMenuItem<T> {
1313
const SourceDropdownMenuItem({T? value, required Widget child})

packages/devtools_app/lib/src/screens/memory/shared/constants.dart

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,5 @@
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 'package:flutter/material.dart';
6-
7-
import '../../../shared/utils.dart';
8-
95
/// When to have verbose Dropdown based on media width.
106
const verboseDropDownMinimumWidth = 950;
11-
12-
const legendXOffset = 20;
13-
const legendYOffset = 7.0;
14-
double get legendWidth => scaleByFontFactor(200.0);
15-
double get legendTextWidth => scaleByFontFactor(55.0);
16-
double get legendHeight1Chart => scaleByFontFactor(200.0);
17-
double get legendHeight2Charts => scaleByFontFactor(323.0);
18-
19-
const memorySourceMenuItemPrefix = 'Source: ';
20-
final legendKey = GlobalKey(debugLabel: 'Legend Button');
21-
const sourcesDropdownKey = Key('Sources Dropdown');
22-
const sourcesKey = Key('Sources');
23-
24-
/// Padding for each title in the legend.
25-
const legendTitlePadding = EdgeInsets.fromLTRB(5, 0, 0, 4);

packages/devtools_app/test/memory/memory_screen_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import 'package:devtools_app/src/screens/memory/memory_screen.dart';
99
import 'package:devtools_app/src/screens/memory/panes/chart/chart_control_pane.dart';
1010
import 'package:devtools_app/src/screens/memory/panes/chart/memory_events_pane.dart';
1111
import 'package:devtools_app/src/screens/memory/panes/chart/memory_vm_chart.dart';
12+
import 'package:devtools_app/src/screens/memory/panes/control/primitives.dart';
1213
import 'package:devtools_app/src/screens/memory/panes/control/source_dropdown.dart';
13-
import 'package:devtools_app/src/screens/memory/shared/constants.dart';
1414
import 'package:devtools_app/src/service/service_manager.dart';
1515
import 'package:devtools_app/src/shared/common_widgets.dart';
1616
import 'package:devtools_app/src/shared/globals.dart';

0 commit comments

Comments
 (0)