Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
a2aa2ed0
Unverified
Commit
a2aa2ed0
authored
Dec 02, 2020
by
Dan Field
Committed by
GitHub
Dec 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Fix excessive rebuilds of DSS (#69724)" (#71459)
This reverts commit
16dce765
.
parent
f0f9a819
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
175 deletions
+9
-175
draggable_scrollable_sheet.dart
...s/flutter/lib/src/widgets/draggable_scrollable_sheet.dart
+9
-30
draggable_scrollable_sheet_test.dart
...flutter/test/widgets/draggable_scrollable_sheet_test.dart
+0
-145
No files found.
packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart
View file @
a2aa2ed0
...
...
@@ -288,17 +288,17 @@ class _DraggableSheetExtent {
class
_DraggableScrollableSheetState
extends
State
<
DraggableScrollableSheet
>
{
late
_DraggableScrollableSheetScrollController
_scrollController
;
late
_DraggableSheetExtent
_extent
;
// The child only gets rebuilt when dependencies or the widget change.
// Otherwise, excessive rebuilds of the child are triggered every time the
// scroll extent changes, which is very expensive and does not provide any
// helpful information to the child. If the child needs to rebuild whenever
// the scroll position changes, they can always subscribe to it.
Widget
?
_child
;
@override
void
initState
()
{
super
.
initState
();
_updateExtent
();
_extent
=
_DraggableSheetExtent
(
minExtent:
widget
.
minChildSize
,
maxExtent:
widget
.
maxChildSize
,
initialExtent:
widget
.
initialChildSize
,
listener:
_setExtent
,
);
_scrollController
=
_DraggableScrollableSheetScrollController
(
extent:
_extent
);
}
@override
...
...
@@ -317,33 +317,13 @@ class _DraggableScrollableSheetState extends State<DraggableScrollableSheet> {
}
_extent
.
_currentExtent
.
value
=
_extent
.
initialExtent
;
}
_child
=
widget
.
builder
(
context
,
_scrollController
);
}
@override
void
didUpdateWidget
(
DraggableScrollableSheet
oldWidget
)
{
super
.
didUpdateWidget
(
oldWidget
);
_updateExtent
();
// Call this unconditionally - the closure may not change even though it
// refers to things outside of its identity, e.g. a tearoff from state that
// has an `if (stateVariable)`.
_child
=
widget
.
builder
(
context
,
_scrollController
);
}
void
_updateExtent
()
{
_extent
=
_DraggableSheetExtent
(
minExtent:
widget
.
minChildSize
,
maxExtent:
widget
.
maxChildSize
,
initialExtent:
widget
.
initialChildSize
,
listener:
_setExtent
,
);
_scrollController
=
_DraggableScrollableSheetScrollController
(
extent:
_extent
);
}
void
_setExtent
()
{
setState
(()
{
// _extent has been updated when this is called.
});
}
@override
...
...
@@ -353,7 +333,7 @@ class _DraggableScrollableSheetState extends State<DraggableScrollableSheet> {
_extent
.
availablePixels
=
widget
.
maxChildSize
*
constraints
.
biggest
.
height
;
final
Widget
sheet
=
FractionallySizedBox
(
heightFactor:
_extent
.
currentExtent
,
child:
_child
,
child:
widget
.
builder
(
context
,
_scrollController
)
,
alignment:
Alignment
.
bottomCenter
,
);
return
widget
.
expand
?
SizedBox
.
expand
(
child:
sheet
)
:
sheet
;
...
...
@@ -364,7 +344,6 @@ class _DraggableScrollableSheetState extends State<DraggableScrollableSheet> {
@override
void
dispose
()
{
_scrollController
.
dispose
();
_child
=
null
;
super
.
dispose
();
}
}
...
...
packages/flutter/test/widgets/draggable_scrollable_sheet_test.dart
View file @
a2aa2ed0
...
...
@@ -309,149 +309,4 @@ void main() {
expect
(
notificationTypes
,
types
);
});
}
testWidgets
(
'Builder is not called excessively'
,
(
WidgetTester
tester
)
async
{
int
buildCount
=
0
;
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Stack
(
children:
<
Widget
>[
DraggableScrollableSheet
(
builder:
(
BuildContext
context
,
ScrollController
scrollController
)
{
buildCount
+=
1
;
return
Container
(
color:
const
Color
(
0xFFABCDEF
),
child:
ListView
.
builder
(
controller:
scrollController
,
itemExtent:
100
,
itemCount:
100
,
itemBuilder:
(
BuildContext
context
,
int
index
)
=>
Text
(
'Item
$index
'
),
),
);
},
),
],
),
));
expect
(
buildCount
,
1
);
await
tester
.
flingFrom
(
const
Offset
(
0
,
325
),
const
Offset
(
0
,
-
325
),
200
);
expect
(
buildCount
,
1
);
await
tester
.
pumpAndSettle
();
expect
(
buildCount
,
1
);
});
testWidgets
(
'Builder is called if widget updates'
,
(
WidgetTester
tester
)
async
{
int
buildCount
=
0
;
final
GlobalKey
key
=
GlobalKey
();
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Stack
(
children:
<
Widget
>[
DraggableScrollableSheet
(
key:
key
,
builder:
(
BuildContext
context
,
ScrollController
scrollController
)
{
buildCount
+=
1
;
return
Container
(
color:
const
Color
(
0xFFABCDEF
),
child:
ListView
.
builder
(
controller:
scrollController
,
itemExtent:
100
,
itemCount:
100
,
itemBuilder:
(
BuildContext
context
,
int
index
)
=>
Text
(
'Item
$index
'
),
),
);
},
),
],
),
));
expect
(
buildCount
,
1
);
expect
(
find
.
text
(
'Item 1'
),
findsOneWidget
);
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Stack
(
children:
<
Widget
>[
DraggableScrollableSheet
(
key:
key
,
builder:
(
BuildContext
context
,
ScrollController
scrollController
)
{
buildCount
+=
1
;
return
Container
(
color:
const
Color
(
0xFFFEDCBA
),
child:
ListView
.
builder
(
controller:
scrollController
,
itemExtent:
50
,
itemCount:
100
,
itemBuilder:
(
BuildContext
context
,
int
index
)
=>
Text
(
'New Item
$index
'
),
),
);
},
),
],
),
));
expect
(
buildCount
,
2
);
expect
(
find
.
text
(
'Item 1'
),
findsNothing
);
expect
(
find
.
text
(
'New Item 1'
),
findsOneWidget
);
});
testWidgets
(
'Changes to min/max/initial child size are respected'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
key
=
GlobalKey
();
final
Key
childKey
=
UniqueKey
();
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Stack
(
children:
<
Widget
>[
DraggableScrollableSheet
(
key:
key
,
minChildSize:
.
25
,
maxChildSize:
1.0
,
initialChildSize:
.
5
,
builder:
(
BuildContext
context
,
ScrollController
scrollController
)
{
return
Container
(
key:
childKey
,
color:
const
Color
(
0xFFABCDEF
),
child:
ListView
.
builder
(
controller:
scrollController
,
itemExtent:
100
,
itemCount:
100
,
itemBuilder:
(
BuildContext
context
,
int
index
)
=>
Text
(
'Item
$index
'
),
),
);
},
),
],
),
));
expect
(
find
.
text
(
'Item 1'
),
findsOneWidget
);
expect
(
tester
.
getRect
(
find
.
byKey
(
childKey
)),
const
Rect
.
fromLTRB
(
0
,
300
,
800
,
600
));
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Stack
(
children:
<
Widget
>[
DraggableScrollableSheet
(
key:
key
,
minChildSize:
.
5
,
maxChildSize:
.
75
,
initialChildSize:
.
6
,
builder:
(
BuildContext
context
,
ScrollController
scrollController
)
{
return
Container
(
key:
childKey
,
color:
const
Color
(
0xFFFEDCBA
),
child:
ListView
.
builder
(
controller:
scrollController
,
itemExtent:
50
,
itemCount:
100
,
itemBuilder:
(
BuildContext
context
,
int
index
)
=>
Text
(
'New Item
$index
'
),
),
);
},
),
],
),
));
expect
(
find
.
text
(
'New Item 1'
),
findsOneWidget
);
expect
(
tester
.
getRect
(
find
.
byKey
(
childKey
)),
const
Rect
.
fromLTRB
(
0
,
240
,
800
,
600
));
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment