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
2c2c8a75
Unverified
Commit
2c2c8a75
authored
Mar 22, 2021
by
Justin McCandless
Committed by
GitHub
Mar 22, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
InteractiveViewer.builder (#77414)
parent
e58ee0fb
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
408 additions
and
41 deletions
+408
-41
interactive_viewer.dart
packages/flutter/lib/src/widgets/interactive_viewer.dart
+301
-41
interactive_viewer_test.dart
packages/flutter/test/widgets/interactive_viewer_test.dart
+107
-0
No files found.
packages/flutter/lib/src/widgets/interactive_viewer.dart
View file @
2c2c8a75
This diff is collapsed.
Click to expand it.
packages/flutter/test/widgets/interactive_viewer_test.dart
View file @
2c2c8a75
...
@@ -1026,6 +1026,89 @@ void main() {
...
@@ -1026,6 +1026,89 @@ void main() {
findsOneWidget
,
findsOneWidget
,
);
);
});
});
testWidgets
(
'builder can change widgets that are off-screen'
,
(
WidgetTester
tester
)
async
{
final
TransformationController
transformationController
=
TransformationController
();
const
double
childHeight
=
10.0
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Center
(
child:
SizedBox
(
height:
50.0
,
child:
InteractiveViewer
.
builder
(
transformationController:
transformationController
,
scaleEnabled:
false
,
boundaryMargin:
const
EdgeInsets
.
all
(
double
.
infinity
),
// Build visible children green, off-screen children red.
builder:
(
BuildContext
context
,
Quad
viewportQuad
)
{
final
Rect
viewport
=
_axisAlignedBoundingBox
(
viewportQuad
);
final
List
<
Container
>
children
=
<
Container
>[];
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
final
double
childTop
=
i
*
childHeight
;
final
double
childBottom
=
childTop
+
childHeight
;
final
bool
visible
=
(
childBottom
>=
viewport
.
top
&&
childBottom
<=
viewport
.
bottom
)
||
(
childTop
>=
viewport
.
top
&&
childTop
<=
viewport
.
bottom
);
children
.
add
(
Container
(
height:
childHeight
,
color:
visible
?
Colors
.
green
:
Colors
.
red
,
));
}
return
Column
(
children:
children
,
);
},
),
),
),
),
),
);
expect
(
transformationController
.
value
,
equals
(
Matrix4
.
identity
()));
// The first six are partially visible and therefore green.
int
i
=
0
;
for
(
final
Element
element
in
find
.
byType
(
Container
,
skipOffstage:
false
).
evaluate
())
{
final
Container
container
=
element
.
widget
as
Container
;
if
(
i
<
6
)
{
expect
(
container
.
color
,
Colors
.
green
);
}
else
{
expect
(
container
.
color
,
Colors
.
red
);
}
i
++;
}
// Drag to pan down past the first child.
final
Offset
childOffset
=
tester
.
getTopLeft
(
find
.
byType
(
SizedBox
));
const
double
translationY
=
15.0
;
final
Offset
childInterior
=
Offset
(
childOffset
.
dx
,
childOffset
.
dy
+
translationY
,
);
final
TestGesture
gesture
=
await
tester
.
startGesture
(
childInterior
);
addTearDown
(
gesture
.
removePointer
);
await
tester
.
pump
();
await
gesture
.
moveTo
(
childOffset
);
await
tester
.
pump
();
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
transformationController
.
value
,
isNot
(
Matrix4
.
identity
()));
expect
(
transformationController
.
value
.
getTranslation
().
y
,
-
translationY
);
// After scrolling down a bit, the first child is not visible, the next
// six are, and the final three are not.
i
=
0
;
for
(
final
Element
element
in
find
.
byType
(
Container
,
skipOffstage:
false
).
evaluate
())
{
final
Container
container
=
element
.
widget
as
Container
;
if
(
i
>
0
&&
i
<
7
)
{
expect
(
container
.
color
,
Colors
.
green
);
}
else
{
expect
(
container
.
color
,
Colors
.
red
);
}
i
++;
}
});
});
});
group
(
'getNearestPointOnLine'
,
()
{
group
(
'getNearestPointOnLine'
,
()
{
...
@@ -1235,3 +1318,27 @@ void main() {
...
@@ -1235,3 +1318,27 @@ void main() {
});
});
});
});
}
}
// Returns the axis aligned bounding box for the given Quad, which might not
// be axis aligned.
Rect
_axisAlignedBoundingBox
(
Quad
quad
)
{
double
?
xMin
;
double
?
xMax
;
double
?
yMin
;
double
?
yMax
;
for
(
final
Vector3
point
in
<
Vector3
>[
quad
.
point0
,
quad
.
point1
,
quad
.
point2
,
quad
.
point3
])
{
if
(
xMin
==
null
||
point
.
x
<
xMin
)
{
xMin
=
point
.
x
;
}
if
(
xMax
==
null
||
point
.
x
>
xMax
)
{
xMax
=
point
.
x
;
}
if
(
yMin
==
null
||
point
.
y
<
yMin
)
{
yMin
=
point
.
y
;
}
if
(
yMax
==
null
||
point
.
y
>
yMax
)
{
yMax
=
point
.
y
;
}
}
return
Rect
.
fromLTRB
(
xMin
!,
yMin
!,
xMax
!,
yMax
!);
}
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