Skip to content

Commit a11b21d

Browse files
authored
ViewportOffset should dispatch creation in constructor. (flutter#135420)
1 parent 9f4f6c4 commit a11b21d

File tree

2 files changed

+54
-15
lines changed

2 files changed

+54
-15
lines changed

packages/flutter/lib/src/rendering/viewport_offset.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ abstract class ViewportOffset extends ChangeNotifier {
9797
/// Default constructor.
9898
///
9999
/// Allows subclasses to construct this object directly.
100-
ViewportOffset();
100+
ViewportOffset() {
101+
if (kFlutterMemoryAllocationsEnabled) {
102+
ChangeNotifier.maybeDispatchObjectCreation(this);
103+
}
104+
}
101105

102106
/// Creates a viewport offset with the given [pixels] value.
103107
///

packages/flutter/test/widgets/two_dimensional_viewport_test.dart

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,10 +1441,15 @@ void main() {
14411441
// Horizontal mismatch
14421442
expect(
14431443
() {
1444+
final ViewportOffset verticalOffset = ViewportOffset.fixed(0.0);
1445+
addTearDown(verticalOffset.dispose);
1446+
final ViewportOffset horizontalOffset = ViewportOffset.fixed(0.0);
1447+
addTearDown(horizontalOffset.dispose);
1448+
14441449
SimpleBuilderTableViewport(
1445-
verticalOffset: ViewportOffset.fixed(0.0),
1450+
verticalOffset: verticalOffset,
14461451
verticalAxisDirection: AxisDirection.left,
1447-
horizontalOffset: ViewportOffset.fixed(0.0),
1452+
horizontalOffset: horizontalOffset,
14481453
horizontalAxisDirection: AxisDirection.right,
14491454
delegate: builderDelegate,
14501455
mainAxis: Axis.vertical,
@@ -1462,10 +1467,15 @@ void main() {
14621467
// Vertical mismatch
14631468
expect(
14641469
() {
1470+
final ViewportOffset verticalOffset = ViewportOffset.fixed(0.0);
1471+
addTearDown(verticalOffset.dispose);
1472+
final ViewportOffset horizontalOffset = ViewportOffset.fixed(0.0);
1473+
addTearDown(horizontalOffset.dispose);
1474+
14651475
SimpleBuilderTableViewport(
1466-
verticalOffset: ViewportOffset.fixed(0.0),
1476+
verticalOffset: verticalOffset,
14671477
verticalAxisDirection: AxisDirection.up,
1468-
horizontalOffset: ViewportOffset.fixed(0.0),
1478+
horizontalOffset: horizontalOffset,
14691479
horizontalAxisDirection: AxisDirection.down,
14701480
delegate: builderDelegate,
14711481
mainAxis: Axis.vertical,
@@ -1483,10 +1493,15 @@ void main() {
14831493
// Both
14841494
expect(
14851495
() {
1496+
final ViewportOffset verticalOffset = ViewportOffset.fixed(0.0);
1497+
addTearDown(verticalOffset.dispose);
1498+
final ViewportOffset horizontalOffset = ViewportOffset.fixed(0.0);
1499+
addTearDown(horizontalOffset.dispose);
1500+
14861501
SimpleBuilderTableViewport(
1487-
verticalOffset: ViewportOffset.fixed(0.0),
1502+
verticalOffset: verticalOffset,
14881503
verticalAxisDirection: AxisDirection.left,
1489-
horizontalOffset: ViewportOffset.fixed(0.0),
1504+
horizontalOffset: horizontalOffset,
14901505
horizontalAxisDirection: AxisDirection.down,
14911506
delegate: builderDelegate,
14921507
mainAxis: Axis.vertical,
@@ -1548,10 +1563,15 @@ void main() {
15481563
// Horizontal mismatch
15491564
expect(
15501565
() {
1566+
final ViewportOffset verticalOffset = ViewportOffset.fixed(0.0);
1567+
addTearDown(verticalOffset.dispose);
1568+
final ViewportOffset horizontalOffset = ViewportOffset.fixed(0.0);
1569+
addTearDown(horizontalOffset.dispose);
1570+
15511571
RenderSimpleBuilderTableViewport(
1552-
verticalOffset: ViewportOffset.fixed(0.0),
1572+
verticalOffset: verticalOffset,
15531573
verticalAxisDirection: AxisDirection.left,
1554-
horizontalOffset: ViewportOffset.fixed(0.0),
1574+
horizontalOffset: horizontalOffset,
15551575
horizontalAxisDirection: AxisDirection.right,
15561576
delegate: builderDelegate,
15571577
mainAxis: Axis.vertical,
@@ -1570,10 +1590,15 @@ void main() {
15701590
// Vertical mismatch
15711591
expect(
15721592
() {
1593+
final ViewportOffset verticalOffset = ViewportOffset.fixed(0.0);
1594+
addTearDown(verticalOffset.dispose);
1595+
final ViewportOffset horizontalOffset = ViewportOffset.fixed(0.0);
1596+
addTearDown(horizontalOffset.dispose);
1597+
15731598
RenderSimpleBuilderTableViewport(
1574-
verticalOffset: ViewportOffset.fixed(0.0),
1599+
verticalOffset: verticalOffset,
15751600
verticalAxisDirection: AxisDirection.up,
1576-
horizontalOffset: ViewportOffset.fixed(0.0),
1601+
horizontalOffset: horizontalOffset,
15771602
horizontalAxisDirection: AxisDirection.down,
15781603
delegate: builderDelegate,
15791604
mainAxis: Axis.vertical,
@@ -1592,10 +1617,15 @@ void main() {
15921617
// Both
15931618
expect(
15941619
() {
1620+
final ViewportOffset verticalOffset = ViewportOffset.fixed(0.0);
1621+
addTearDown(verticalOffset.dispose);
1622+
final ViewportOffset horizontalOffset = ViewportOffset.fixed(0.0);
1623+
addTearDown(horizontalOffset.dispose);
1624+
15951625
RenderSimpleBuilderTableViewport(
1596-
verticalOffset: ViewportOffset.fixed(0.0),
1626+
verticalOffset: verticalOffset,
15971627
verticalAxisDirection: AxisDirection.left,
1598-
horizontalOffset: ViewportOffset.fixed(0.0),
1628+
horizontalOffset: horizontalOffset,
15991629
horizontalAxisDirection: AxisDirection.down,
16001630
delegate: builderDelegate,
16011631
mainAxis: Axis.vertical,
@@ -1622,10 +1652,15 @@ void main() {
16221652
}
16231653
);
16241654
addTearDown(delegate.dispose);
1655+
final ViewportOffset verticalOffset = ViewportOffset.fixed(10.0);
1656+
addTearDown(verticalOffset.dispose);
1657+
final ViewportOffset horizontalOffset = ViewportOffset.fixed(20.0);
1658+
addTearDown(horizontalOffset.dispose);
1659+
16251660
final RenderSimpleBuilderTableViewport renderViewport = RenderSimpleBuilderTableViewport(
1626-
verticalOffset: ViewportOffset.fixed(10.0),
1661+
verticalOffset: verticalOffset,
16271662
verticalAxisDirection: AxisDirection.down,
1628-
horizontalOffset: ViewportOffset.fixed(20.0),
1663+
horizontalOffset: horizontalOffset,
16291664
horizontalAxisDirection: AxisDirection.right,
16301665
delegate: delegate,
16311666
mainAxis: Axis.vertical,

0 commit comments

Comments
 (0)