Skip to content

Commit

Permalink
Replace DualValueListenableBuilder with `MultiValueListenableBuilde…
Browse files Browse the repository at this point in the history
…r` (flutter#6129)
  • Loading branch information
kenzieschmoll authored Aug 1, 2023
1 parent 13839ef commit d20816e
Show file tree
Hide file tree
Showing 21 changed files with 201 additions and 128 deletions.
11 changes: 6 additions & 5 deletions packages/devtools_app/lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'dart:async';

import 'package:devtools_shared/devtools_extensions.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -250,10 +249,12 @@ class DevToolsAppState extends State<DevToolsApp> with AutoDisposeMixin {
Widget scaffoldBuilder() {
// Force regeneration of visible screens when VM developer mode is
// enabled and when the list of available extensions change.
return DualValueListenableBuilder<bool, List<DevToolsExtensionConfig>>(
firstListenable: preferences.vmDeveloperModeEnabled,
secondListenable: extensionService.availableExtensions,
builder: (_, __, ___, child) {
return MultiValueListenableBuilder(
listenables: [
preferences.vmDeveloperModeEnabled,
extensionService.availableExtensions,
],
builder: (_, __, child) {
final screens = _visibleScreens()
.where((p) => embed && page != null ? p.screenId == page : true)
.where((p) => !hide.contains(p.screenId))
Expand Down
18 changes: 11 additions & 7 deletions packages/devtools_app/lib/src/framework/status_line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import '../service/service_manager.dart';
import '../shared/analytics/constants.dart' as gac;
import '../shared/common_widgets.dart';
import '../shared/globals.dart';
import '../shared/primitives/utils.dart';
import '../shared/screen.dart';
import '../shared/theme.dart';
import '../shared/ui/utils.dart';
Expand Down Expand Up @@ -219,20 +220,23 @@ class IsolateSelector extends StatelessWidget {
@override
Widget build(BuildContext context) {
final IsolateManager isolateManager = serviceManager.isolateManager;
return DualValueListenableBuilder<List<IsolateRef?>, IsolateRef?>(
firstListenable: isolateManager.isolates,
secondListenable: isolateManager.selectedIsolate,
builder: (context, isolates, selectedIsolateRef, _) {
return MultiValueListenableBuilder(
listenables: [
isolateManager.isolates,
isolateManager.selectedIsolate,
],
builder: (context, values, _) {
final isolates = values.first as List<IsolateRef>;
final selectedIsolateRef = values.second as IsolateRef?;
return PopupMenuButton<IsolateRef?>(
tooltip: 'Selected Isolate',
initialValue: selectedIsolateRef,
onSelected: isolateManager.selectIsolate,
itemBuilder: (BuildContext context) =>
isolates.where((ref) => ref != null).map(
itemBuilder: (BuildContext context) => isolates.map(
(ref) {
return PopupMenuItem<IsolateRef>(
value: ref,
child: IsolateOption(ref!),
child: IsolateOption(ref),
);
},
).toList(),
Expand Down
14 changes: 9 additions & 5 deletions packages/devtools_app/lib/src/screens/debugger/breakpoints.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ class _BreakpointsState extends State<Breakpoints>

@override
Widget build(BuildContext context) {
return DualValueListenableBuilder<List<BreakpointAndSourcePosition>,
BreakpointAndSourcePosition?>(
firstListenable: breakpointManager.breakpointsWithLocation,
secondListenable: controller.selectedBreakpoint,
builder: (context, breakpoints, selectedBreakpoint, _) {
return MultiValueListenableBuilder(
listenables: [
breakpointManager.breakpointsWithLocation,
controller.selectedBreakpoint,
],
builder: (context, values, _) {
final breakpoints = values.first as List<BreakpointAndSourcePosition>;
final selectedBreakpoint =
values.second as BreakpointAndSourcePosition?;
return ListView.builder(
itemCount: breakpoints.length,
itemExtent: defaultListItemHeight,
Expand Down
14 changes: 9 additions & 5 deletions packages/devtools_app/lib/src/screens/debugger/call_stack.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter/material.dart' hide Stack;
import 'package:vm_service/vm_service.dart';

import '../../shared/common_widgets.dart';
import '../../shared/primitives/utils.dart';
import '../../shared/theme.dart';
import '../../shared/utils.dart';
import 'debugger_controller.dart';
Expand All @@ -32,11 +33,14 @@ class _CallStackState extends State<CallStack>

@override
Widget build(BuildContext context) {
return DualValueListenableBuilder<List<StackFrameAndSourcePosition>,
StackFrameAndSourcePosition?>(
firstListenable: controller.stackFramesWithLocation,
secondListenable: controller.selectedStackFrame,
builder: (context, stackFrames, selectedFrame, _) {
return MultiValueListenableBuilder(
listenables: [
controller.stackFramesWithLocation,
controller.selectedStackFrame,
],
builder: (context, values, _) {
final stackFrames = values.first as List<StackFrameAndSourcePosition>;
final selectedFrame = values.second as StackFrameAndSourcePosition?;
return ListView.builder(
itemCount: stackFrames.length,
itemExtent: defaultListItemHeight,
Expand Down
13 changes: 9 additions & 4 deletions packages/devtools_app/lib/src/screens/debugger/codeview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -788,10 +788,15 @@ class Gutters extends StatelessWidget {

return Row(
children: [
DualValueListenableBuilder<List<BreakpointAndSourcePosition>, bool>(
firstListenable: breakpointManager.breakpointsWithLocation,
secondListenable: codeViewController.showCodeCoverage,
builder: (context, breakpoints, showCodeCoverage, _) {
MultiValueListenableBuilder(
listenables: [
breakpointManager.breakpointsWithLocation,
codeViewController.showCodeCoverage,
],
builder: (context, values, _) {
final breakpoints =
values.first as List<BreakpointAndSourcePosition>;
final showCodeCoverage = values.second as bool;
return Gutter(
gutterWidth: gutterWidth,
scrollController: gutterController,
Expand Down
13 changes: 9 additions & 4 deletions packages/devtools_app/lib/src/screens/debugger/controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import '../../shared/analytics/constants.dart' as gac;
import '../../shared/common_widgets.dart';
import '../../shared/globals.dart';
import '../../shared/primitives/auto_dispose.dart';
import '../../shared/primitives/utils.dart';
import '../../shared/theme.dart';
import '../../shared/ui/label.dart';
import '../../shared/utils.dart';
Expand Down Expand Up @@ -167,10 +168,14 @@ class CodeStatisticsControls extends StatelessWidget {

@override
Widget build(BuildContext context) {
return DualValueListenableBuilder<bool, bool>(
firstListenable: controller.codeViewController.showCodeCoverage,
secondListenable: controller.codeViewController.showProfileInformation,
builder: (context, showCodeCoverage, showProfileInformation, _) {
return MultiValueListenableBuilder(
listenables: [
controller.codeViewController.showCodeCoverage,
controller.codeViewController.showProfileInformation,
],
builder: (context, values, _) {
final showCodeCoverage = values.first as bool;
final showProfileInformation = values.second as bool;
return Row(
children: [
// TODO(kenz): clean up this button group when records are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import '../../shared/flex_split_column.dart';
import '../../shared/globals.dart';
import '../../shared/primitives/auto_dispose.dart';
import '../../shared/primitives/listenable.dart';
import '../../shared/primitives/utils.dart';
import '../../shared/routing.dart';
import '../../shared/screen.dart';
import '../../shared/split.dart';
Expand Down Expand Up @@ -179,10 +180,14 @@ class DebuggerScreenBodyState extends State<DebuggerScreenBody>
return child!;
}
},
child: DualValueListenableBuilder<ScriptRef?, ParsedScript?>(
firstListenable: codeViewController.currentScriptRef,
secondListenable: codeViewController.currentParsedScript,
builder: (context, scriptRef, parsedScript, _) {
child: MultiValueListenableBuilder(
listenables: [
codeViewController.currentScriptRef,
codeViewController.currentParsedScript,
],
builder: (context, values, _) {
final scriptRef = values.first as ScriptRef?;
final parsedScript = values.second as ParsedScript?;
if (scriptRef != null &&
parsedScript != null &&
!_shownFirstScript) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,14 @@ class _MemoryChartPaneState extends State<MemoryChartPane>
),
),
// The legend.
DualValueListenableBuilder<bool, bool>(
firstListenable: widget.chartController.legendVisibleNotifier,
secondListenable: controller.isAndroidChartVisibleNotifier,
builder: (_, isLegendVisible, isAndroidChartVisible, __) {
MultiValueListenableBuilder(
listenables: [
widget.chartController.legendVisibleNotifier,
controller.isAndroidChartVisibleNotifier,
],
builder: (_, values, __) {
final isLegendVisible = values.first as bool;
final isAndroidChartVisible = values.second as bool;
if (!isLegendVisible) return const SizedBox.shrink();
return Padding(
padding: const EdgeInsets.only(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
import '../../../../../../shared/analytics/analytics.dart' as ga;
import '../../../../../../shared/analytics/constants.dart' as gac;
import '../../../../../../shared/common_widgets.dart';
import '../../../../../../shared/primitives/utils.dart';
import '../../../../../../shared/theme.dart';
import '../../../../shared/heap/model.dart';
import '../../controller/class_data.dart';
Expand Down Expand Up @@ -123,18 +124,24 @@ class _PathView extends StatelessWidget {

@override
Widget build(BuildContext context) {
return DualValueListenableBuilder<bool, bool>(
firstListenable: controller.hideStandard,
secondListenable: controller.invert,
builder: (_, hideStandard, invert, __) => SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: SingleChildScrollView(
child: Text(
path.toLongString(inverted: invert, hideStandard: hideStandard),
overflow: TextOverflow.visible,
return MultiValueListenableBuilder(
listenables: [
controller.hideStandard,
controller.invert,
],
builder: (_, values, __) {
final hideStandard = values.first as bool;
final invert = values.second as bool;
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: SingleChildScrollView(
child: Text(
path.toLongString(inverted: invert, hideStandard: hideStandard),
overflow: TextOverflow.visible,
),
),
),
),
);
},
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,14 @@ class _SnapshotListItemsState extends State<_SnapshotListItems>
Widget build(BuildContext context) {
final core = widget.controller.core;

return DualValueListenableBuilder<List<SnapshotItem>, int>(
firstListenable: core.snapshots,
secondListenable: core.selectedSnapshotIndex,
builder: (_, snapshots, selectedIndex, __) {
return MultiValueListenableBuilder(
listenables: [
core.snapshots,
core.selectedSnapshotIndex,
],
builder: (_, values, __) {
final snapshots = values.first as List<SnapshotItem>;
final selectedIndex = values.second as int;
return ListView.builder(
controller: _scrollController,
itemCount: snapshots.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'package:flutter/material.dart';

import '../../../../../shared/common_widgets.dart';
import '../../../../../shared/primitives/utils.dart';
import '../../../../../shared/split.dart';
import '../../../shared/heap/heap.dart';
import '../controller/diff_pane_controller.dart';
Expand All @@ -20,11 +21,14 @@ class SnapshotView extends StatelessWidget {

@override
Widget build(BuildContext context) {
return DualValueListenableBuilder<List<SingleClassStats>?,
List<DiffClassStats>?>(
firstListenable: controller.derived.singleClassesToShow,
secondListenable: controller.derived.diffClassesToShow,
builder: (_, singleClasses, diffClasses, __) {
return MultiValueListenableBuilder(
listenables: [
controller.derived.singleClassesToShow,
controller.derived.diffClassesToShow,
],
builder: (_, values, __) {
final singleClasses = values.first as List<SingleClassStats>?;
final diffClasses = values.second as List<DiffClassStats>?;
if (controller.derived.updatingValues) {
return const Center(child: Text('Calculating...'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'package:flutter/material.dart';

import '../../../../../shared/common_widgets.dart';
import '../../../../../shared/primitives/utils.dart';
import '../../../../../shared/theme.dart';

enum AnalysisStatus {
Expand Down Expand Up @@ -67,10 +68,14 @@ class AnalysisStatusView extends StatelessWidget {

@override
Widget build(BuildContext context) {
return DualValueListenableBuilder<AnalysisStatus, String>(
firstListenable: controller.status,
secondListenable: controller.message,
builder: (_, status, message, __) {
return MultiValueListenableBuilder(
listenables: [
controller.status,
controller.message,
],
builder: (_, values, __) {
final status = values.first as AnalysisStatus;
final message = values.second as String;
if (status == AnalysisStatus.notStarted) {
return analysisStarter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,13 @@ class _AllocationTracingTableState extends State<AllocationTracingTable> {
),
),
Expanded(
child: DualValueListenableBuilder<bool, TracingIsolateState>(
firstListenable: widget.controller.refreshing,
secondListenable: widget.controller.stateForIsolate,
builder: (context, _, state, __) {
child: MultiValueListenableBuilder(
listenables: [
widget.controller.refreshing,
widget.controller.stateForIsolate,
],
builder: (context, values, __) {
final state = values.second as TracingIsolateState;
return ValueListenableBuilder<List<TracedClass>>(
valueListenable: state.filteredClassList,
builder: (context, filteredClassList, _) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ class NetworkScreen extends Screen {
final networkController = Provider.of<NetworkController>(context);
final color = Theme.of(context).textTheme.bodyMedium!.color!;

return DualValueListenableBuilder<NetworkRequests, List<NetworkRequest>>(
firstListenable: networkController.requests,
secondListenable: networkController.filteredData,
builder: (context, networkRequests, filteredRequests, child) {
return MultiValueListenableBuilder(
listenables: [
networkController.requests,
networkController.filteredData,
],
builder: (context, values, child) {
final networkRequests = values.first as NetworkRequests;
final filteredRequests = values.second as List<NetworkRequest>;
final filteredCount = filteredRequests.length;
final totalCount = networkRequests.requests.length;
return Row(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import '../../../../../service/service_extensions.dart' as extensions;
import '../../../../../shared/common_widgets.dart';
import '../../../../../shared/globals.dart';
import '../../../../../shared/primitives/auto_dispose.dart';
import '../../../../../shared/primitives/utils.dart';
import '../../../../../shared/theme.dart';
import '../performance_controls.dart';
import 'enhance_tracing_controller.dart';
Expand Down Expand Up @@ -230,10 +231,14 @@ class _TrackWidgetBuildsSettingState extends State<TrackWidgetBuildsSetting>
);
},
),
DualValueListenableBuilder<bool, TrackWidgetBuildsScope?>(
firstListenable: _tracked,
secondListenable: _selectedScope,
builder: (context, tracked, selectedScope, _) {
MultiValueListenableBuilder(
listenables: [
_tracked,
_selectedScope,
],
builder: (context, values, _) {
final tracked = values.first as bool;
final selectedScope = values.second as TrackWidgetBuildsScope?;
return Padding(
padding: const EdgeInsets.only(left: _scopeSelectorPadding),
child: TrackWidgetBuildsScopeSelector(
Expand Down
Loading

0 comments on commit d20816e

Please sign in to comment.