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
f78b27e4
Unverified
Commit
f78b27e4
authored
Sep 11, 2020
by
Justin McCandless
Committed by
GitHub
Sep 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix InteractiveViewer minScale bug (#65432)
parent
551a2a6b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
15 deletions
+51
-15
interactive_viewer.dart
packages/flutter/lib/src/widgets/interactive_viewer.dart
+10
-15
interactive_viewer_test.dart
packages/flutter/test/widgets/interactive_viewer_test.dart
+41
-0
No files found.
packages/flutter/lib/src/widgets/interactive_viewer.dart
View file @
f78b27e4
...
...
@@ -646,26 +646,21 @@ class _InteractiveViewerState extends State<InteractiveViewer> with TickerProvid
// Don't allow a scale that results in an overall scale beyond min/max
// scale.
final
double
currentScale
=
_transformationController
.
value
.
getMaxScaleOnAxis
();
final
double
totalScale
=
currentScale
*
scale
;
final
double
totalScale
=
math
.
max
(
currentScale
*
scale
,
// Ensure that the scale cannot make the child so big that it can't fit
// inside the boundaries (in either direction).
math
.
max
(
_viewport
.
width
/
_boundaryRect
.
width
,
_viewport
.
height
/
_boundaryRect
.
height
,
),
);
final
double
clampedTotalScale
=
totalScale
.
clamp
(
widget
.
minScale
,
widget
.
maxScale
,
)
as
double
;
final
double
clampedScale
=
clampedTotalScale
/
currentScale
;
final
Matrix4
nextMatrix
=
matrix
.
clone
()..
scale
(
clampedScale
);
// Ensure that the scale cannot make the child so big that it can't fit
// inside the boundaries (in either direction).
final
double
minScale
=
math
.
max
(
_viewport
.
width
/
_boundaryRect
.
width
,
_viewport
.
height
/
_boundaryRect
.
height
,
);
if
(
clampedTotalScale
<
minScale
)
{
final
double
minCurrentScale
=
minScale
/
currentScale
;
return
matrix
.
clone
()..
scale
(
minCurrentScale
);
}
return
nextMatrix
;
return
matrix
.
clone
()..
scale
(
clampedScale
);
}
// Return a new matrix representing the given matrix after applying the given
...
...
packages/flutter/test/widgets/interactive_viewer_test.dart
View file @
f78b27e4
...
...
@@ -729,6 +729,47 @@ void main() {
await
tester
.
pumpAndSettle
();
expect
(
transformationController
.
value
.
getMaxScaleOnAxis
(),
greaterThan
(
1.0
));
});
// Regression test for https://github.com/flutter/flutter/issues/65304
testWidgets
(
'can view beyond boundary when necessary for a small child'
,
(
WidgetTester
tester
)
async
{
final
TransformationController
transformationController
=
TransformationController
();
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Center
(
child:
InteractiveViewer
(
constrained:
false
,
minScale:
1.0
,
maxScale:
1.0
,
transformationController:
transformationController
,
child:
const
SizedBox
(
width:
200.0
,
height:
200.0
),
),
),
),
),
);
expect
(
transformationController
.
value
,
equals
(
Matrix4
.
identity
()));
// Pinch to zoom does nothing because minScale and maxScale are 1.0.
final
Offset
center
=
tester
.
getCenter
(
find
.
byType
(
SizedBox
));
final
Offset
scaleStart1
=
Offset
(
center
.
dx
-
10.0
,
center
.
dy
-
10.0
);
final
Offset
scaleStart2
=
Offset
(
center
.
dx
+
10.0
,
center
.
dy
+
10.0
);
final
Offset
scaleEnd1
=
Offset
(
center
.
dx
-
20.0
,
center
.
dy
-
20.0
);
final
Offset
scaleEnd2
=
Offset
(
center
.
dx
+
20.0
,
center
.
dy
+
20.0
);
final
TestGesture
gesture
=
await
tester
.
createGesture
();
final
TestGesture
gesture2
=
await
tester
.
createGesture
();
await
gesture
.
down
(
scaleStart1
);
await
gesture2
.
down
(
scaleStart2
);
await
tester
.
pump
();
await
gesture
.
moveTo
(
scaleEnd1
);
await
gesture2
.
moveTo
(
scaleEnd2
);
await
tester
.
pump
();
await
gesture
.
up
();
await
gesture2
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
transformationController
.
value
,
equals
(
Matrix4
.
identity
()));
});
});
group
(
'getNearestPointOnLine'
,
()
{
...
...
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