File tree Expand file tree Collapse file tree 6 files changed +31
-0
lines changed
devtools_test/lib/src/mocks Expand file tree Collapse file tree 6 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,14 @@ class MemoryController extends DisposableController
7171 /// Controller for [AllocationProfileTableView] .
7272 final allocationProfileController = AllocationProfileTableViewController ();
7373
74+ /// Index of the selected feature tab.
75+ ///
76+ /// This value is used to set the initial tab selection of the
77+ /// [MemoryTabView] . This widget will be disposed and re-initialized on
78+ /// DevTools screen changes, so we must store this value in the controller
79+ /// instead of the widget state.
80+ int selectedFeatureTabIndex = 0 ;
81+
7482 static const logFilenamePrefix = 'memory_log_' ;
7583
7684 final _shouldShowLeaksTab = ValueNotifier <bool >(false );
Original file line number Diff line number Diff line change @@ -46,7 +46,11 @@ class MemoryTabView extends StatelessWidget {
4646 return AnalyticsTabbedView (
4747 tabs: tabs,
4848 tabViews: tabViews,
49+ initialSelectedIndex: controller.selectedFeatureTabIndex,
4950 gaScreen: gac.memory,
51+ onTabChanged: (int index) {
52+ controller.selectedFeatureTabIndex = index;
53+ },
5054 );
5155 },
5256 );
Original file line number Diff line number Diff line change @@ -54,6 +54,14 @@ class PerformanceController extends DisposableController
5454 //(https://github.com/flutter/devtools/pull/4566).
5555 final rebuildCountModel = RebuildCountModel ();
5656
57+ /// Index of the selected feature tab.
58+ ///
59+ /// This value is used to set the initial tab selection of the
60+ /// [TabbedPerformanceView] . This widget will be disposed and re-initialized
61+ /// on DevTools screen changes, so we must store this value in the controller
62+ /// instead of the widget state.
63+ int selectedFeatureTabIndex = 0 ;
64+
5765 bool _fetchMissingLocationsStarted = false ;
5866 IsolateRef ? _currentRebuildWidgetsIsolate;
5967
Original file line number Diff line number Diff line change @@ -101,8 +101,10 @@ class _TabbedPerformanceViewState extends State<TabbedPerformanceView>
101101 return AnalyticsTabbedView (
102102 tabs: tabs,
103103 tabViews: tabViews,
104+ initialSelectedIndex: controller.selectedFeatureTabIndex,
104105 gaScreen: gac.performance,
105106 onTabChanged: (int index) {
107+ controller.selectedFeatureTabIndex = index;
106108 final featureController = featureControllers[index];
107109 unawaited (controller.setActiveFeature (featureController));
108110 },
Original file line number Diff line number Diff line change @@ -82,6 +82,7 @@ class AnalyticsTabbedView<T> extends StatefulWidget {
8282 this .outlined = true ,
8383 this .sendAnalytics = true ,
8484 this .onTabChanged,
85+ this .initialSelectedIndex,
8586 }) : trailingWidgets = List .generate (
8687 tabs.length,
8788 (index) => tabs[index].trailing ?? const SizedBox (),
@@ -98,6 +99,8 @@ class AnalyticsTabbedView<T> extends StatefulWidget {
9899
99100 final bool outlined;
100101
102+ final int ? initialSelectedIndex;
103+
101104 /// Whether to send analytics events to GA.
102105 ///
103106 /// Only set this to false if [AnalyticsTabbedView] is being used for
@@ -124,6 +127,11 @@ class _AnalyticsTabbedViewState extends State<AnalyticsTabbedView>
124127 length: widget.tabs.length,
125128 vsync: this ,
126129 );
130+
131+ final initialIndex = widget.initialSelectedIndex;
132+ if (initialIndex != null ) {
133+ _currentTabControllerIndex = initialIndex;
134+ }
127135 if (_currentTabControllerIndex >= _tabController! .length) {
128136 _currentTabControllerIndex = 0 ;
129137 }
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ MockPerformanceController createMockPerformanceControllerWithDefaults() {
2020 when (controller.enhanceTracingController)
2121 .thenReturn (EnhanceTracingController ());
2222 when (controller.offlinePerformanceData).thenReturn (null );
23+ when (controller.selectedFeatureTabIndex).thenReturn (0 );
2324
2425 // Stubs for Flutter Frames feature.
2526 when (controller.flutterFramesController).thenReturn (flutterFramesController);
You can’t perform that action at this time.
0 commit comments