From 02c2c06a280c684d6d9bdf0e3430a969e0696b1b Mon Sep 17 00:00:00 2001 From: Polina Cherkasova Date: Thu, 25 Apr 2024 16:15:11 -0700 Subject: [PATCH] - --- .../panes/chart/widgets/chart_pane.dart | 14 ++--- .../chart/widgets/charts/android_chart.dart | 53 ------------------ .../chart/widgets/charts/events_chart.dart | 54 ------------------- .../panes/chart/widgets/memory_chart.dart | 18 ++++--- .../memory/framework/memory_screen_test.dart | 2 +- 5 files changed, 16 insertions(+), 125 deletions(-) delete mode 100644 packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/charts/android_chart.dart delete mode 100644 packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/charts/events_chart.dart diff --git a/packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/chart_pane.dart b/packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/chart_pane.dart index 60cdc6544bc..e8c6ad71d00 100644 --- a/packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/chart_pane.dart +++ b/packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/chart_pane.dart @@ -17,10 +17,8 @@ import '../../../shared/primitives/painting.dart'; import '../controller/chart_pane_controller.dart'; import '../data/charts.dart'; import 'chart_control_pane.dart'; -import 'charts/android_chart.dart'; -import 'charts/events_chart.dart'; -import 'memory_chart.dart'; import 'legend.dart'; +import 'memory_chart.dart'; class MemoryChartPane extends StatefulWidget { const MemoryChartPane({ @@ -144,6 +142,7 @@ class _MemoryChartPaneState extends State @override Widget build(BuildContext context) { + final sampleAdded = widget.chart.data.timeline.sampleAdded; const memoryEventsPainHeight = 70.0; return ValueListenableBuilder( valueListenable: preferences.memory.showChart, @@ -168,16 +167,13 @@ class _MemoryChartPaneState extends State children: [ SizedBox( height: memoryEventsPainHeight, - child: MemoryEventsPane(widget.chart.event), + child: MemoryChart(widget.chart.event, sampleAdded), ), - MemoryVMChart(widget.chart.vm), + MemoryChart(widget.chart.vm, sampleAdded), if (widget.chart.isAndroidChartVisible.value) SizedBox( height: defaultChartHeight, - child: MemoryAndroidChart( - widget.chart.android, - widget.chart.data.timeline, - ), + child: MemoryChart(widget.chart.android, sampleAdded), ), ], ), diff --git a/packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/charts/android_chart.dart b/packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/charts/android_chart.dart deleted file mode 100644 index d9141393048..00000000000 --- a/packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/charts/android_chart.dart +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:devtools_app_shared/ui.dart'; -import 'package:devtools_app_shared/utils.dart'; -import 'package:flutter/material.dart'; - -import '../../../../../../shared/charts/chart.dart'; -import '../../../../shared/primitives/memory_timeline.dart'; -import '../../controller/charts/android_chart_controller.dart'; - -class MemoryAndroidChart extends StatefulWidget { - const MemoryAndroidChart(this.chart, this.memoryTimeline, {super.key}); - - final AndroidChartController chart; - final MemoryTimeline memoryTimeline; - - @override - MemoryAndroidChartState createState() => MemoryAndroidChartState(); -} - -class MemoryAndroidChartState extends State - with AutoDisposeMixin { - /// Controller attached to the chart. - AndroidChartController get _chartController => widget.chart; - - @override - void initState() { - super.initState(); - _init(); - } - - @override - void didUpdateWidget(covariant MemoryAndroidChart oldWidget) { - super.didUpdateWidget(oldWidget); - if (oldWidget.memoryTimeline == widget.memoryTimeline) return; - _init(); - } - - void _init() { - cancelListeners(); - addAutoDisposeListener(widget.chart.memoryTimeline.sampleAdded); - } - - @override - Widget build(BuildContext context) { - return SizedBox( - height: defaultChartHeight, - child: Chart(_chartController), - ); - } -} diff --git a/packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/charts/events_chart.dart b/packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/charts/events_chart.dart deleted file mode 100644 index 6e1e1f91f7a..00000000000 --- a/packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/charts/events_chart.dart +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:devtools_app_shared/ui.dart'; -import 'package:devtools_app_shared/utils.dart'; -import 'package:devtools_shared/devtools_shared.dart'; -import 'package:flutter/material.dart'; - -import '../../../../../../shared/charts/chart.dart'; -import '../../../../shared/primitives/memory_timeline.dart'; -import '../../controller/charts/event_chart_controller.dart'; - -class MemoryEventsPane extends StatefulWidget { - const MemoryEventsPane(this.chart, {super.key}); - - final EventChartController chart; - - @override - MemoryEventsPaneState createState() => MemoryEventsPaneState(); -} - -class MemoryEventsPaneState extends State - with AutoDisposeMixin { - MemoryTimeline get _memoryTimeline => widget.chart.memoryTimeline; - - @override - void initState() { - super.initState(); - _init(); - } - - @override - void didUpdateWidget(covariant MemoryEventsPane oldWidget) { - super.didUpdateWidget(oldWidget); - if (oldWidget.chart == widget.chart) return; - _init(); - } - - void _init() { - cancelListeners(); - - addAutoDisposeListener(widget.chart.memoryTimeline.sampleAdded); - } - - @override - Widget build(BuildContext context) { - if (widget.chart.timestamps.isNotEmpty) { - return Chart(widget.chart); - } - - return const SizedBox(width: denseSpacing); - } -} diff --git a/packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/memory_chart.dart b/packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/memory_chart.dart index 0797253cc3d..7a5902f99ef 100644 --- a/packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/memory_chart.dart +++ b/packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/memory_chart.dart @@ -4,22 +4,24 @@ import 'package:devtools_app_shared/ui.dart'; import 'package:devtools_app_shared/utils.dart'; +import 'package:devtools_shared/devtools_shared.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import '../../../../../shared/charts/chart.dart'; import '../../../../../shared/charts/chart_controller.dart'; -import '../controller/charts/vm_chart_controller.dart'; -class MemoryVMChart extends StatefulWidget { - const MemoryVMChart(this.chart, {super.key}); +class MemoryChart extends StatefulWidget { + const MemoryChart(this.chart, this.sampleAdded, {super.key}); - final VMChartController chart; + final ChartController chart; + final ValueListenable sampleAdded; @override - MemoryVMChartState createState() => MemoryVMChartState(); + MemoryChartState createState() => MemoryChartState(); } -class MemoryVMChartState extends State with AutoDisposeMixin { +class MemoryChartState extends State with AutoDisposeMixin { @override void initState() { super.initState(); @@ -28,11 +30,11 @@ class MemoryVMChartState extends State with AutoDisposeMixin { void _init() { cancelListeners(); - addAutoDisposeListener(widget.chart.memoryTimeline.sampleAdded); + addAutoDisposeListener(widget.sampleAdded); } @override - void didUpdateWidget(covariant MemoryVMChart oldWidget) { + void didUpdateWidget(covariant MemoryChart oldWidget) { super.didUpdateWidget(oldWidget); if (oldWidget.chart == widget.chart) return; _init(); diff --git a/packages/devtools_app/test/memory/framework/memory_screen_test.dart b/packages/devtools_app/test/memory/framework/memory_screen_test.dart index dabde9900ec..83ec943d8fa 100644 --- a/packages/devtools_app/test/memory/framework/memory_screen_test.dart +++ b/packages/devtools_app/test/memory/framework/memory_screen_test.dart @@ -101,7 +101,7 @@ void main() { expect(find.text('GC'), findsOneWidget); - expect(find.byType(MemoryVMChart), findsOneWidget); + expect(find.byType(MemoryChart), findsOneWidget); }, ); });