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
b429ec1e
Unverified
Commit
b429ec1e
authored
Jun 16, 2020
by
Justin McCandless
Committed by
GitHub
Jun 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
InteractiveViewer mouse scale bug (#59478)
parent
5a4bb505
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
17 deletions
+78
-17
interactive_viewer.dart
packages/flutter/lib/src/widgets/interactive_viewer.dart
+13
-9
gesture_utils.dart
packages/flutter/test/widgets/gesture_utils.dart
+16
-0
interactive_viewer_test.dart
packages/flutter/test/widgets/interactive_viewer_test.dart
+48
-0
listener_test.dart
packages/flutter/test/widgets/listener_test.dart
+1
-8
No files found.
packages/flutter/lib/src/widgets/interactive_viewer.dart
View file @
b429ec1e
...
...
@@ -659,16 +659,17 @@ class _InteractiveViewerState extends State<InteractiveViewer> with TickerProvid
// Returns true iff the given _GestureType is enabled.
bool
_gestureIsSupported
(
_GestureType
gestureType
)
{
if
(
_gestureType
==
_GestureType
.
pan
&&
!
widget
.
panEnabled
)
{
return
false
;
}
if
(
_gestureType
==
_GestureType
.
scale
&&
!
widget
.
scaleEnabled
)
{
return
false
;
}
if
(
_gestureType
==
_GestureType
.
rotate
&&
!
_rotateEnabled
)
{
return
false
;
switch
(
gestureType
)
{
case
_GestureType
.
rotate
:
return
_rotateEnabled
;
case
_GestureType
.
scale
:
return
widget
.
scaleEnabled
;
case
_GestureType
.
pan
:
default
:
return
widget
.
panEnabled
;
}
return
true
;
}
// Handle the start of a gesture. All of pan, scale, and rotate are handled
...
...
@@ -841,6 +842,9 @@ class _InteractiveViewerState extends State<InteractiveViewer> with TickerProvid
// Handle mousewheel scroll events.
void
_receivedPointerSignal
(
PointerSignalEvent
event
)
{
if
(!
_gestureIsSupported
(
_GestureType
.
scale
))
{
return
;
}
if
(
event
is
PointerScrollEvent
)
{
final
RenderBox
childRenderBox
=
_childKey
.
currentContext
.
findRenderObject
()
as
RenderBox
;
final
Size
childSize
=
childRenderBox
.
size
;
...
...
packages/flutter/test/widgets/gesture_utils.dart
0 → 100644
View file @
b429ec1e
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import
'package:flutter/gestures.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
Future
<
void
>
scrollAt
(
Offset
position
,
WidgetTester
tester
)
{
final
TestPointer
testPointer
=
TestPointer
(
1
,
PointerDeviceKind
.
mouse
);
// Create a hover event so that |testPointer| has a location when generating the scroll.
testPointer
.
hover
(
position
);
final
HitTestResult
result
=
tester
.
hitTestOnBinding
(
position
);
return
tester
.
sendEventToBinding
(
testPointer
.
scroll
(
const
Offset
(
0.0
,
20.0
)),
result
);
}
packages/flutter/test/widgets/interactive_viewer_test.dart
View file @
b429ec1e
...
...
@@ -4,11 +4,14 @@
// @dart = 2.8
import
'package:flutter/gestures.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:vector_math/vector_math_64.dart'
show
Quad
,
Vector3
,
Matrix4
;
import
'gesture_utils.dart'
;
void
main
(
)
{
group
(
'InteractiveViewer'
,
()
{
testWidgets
(
'child fits in viewport'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -402,6 +405,51 @@ void main() {
expect
(
newSceneFocalPoint
.
dx
,
closeTo
(
sceneFocalPoint
.
dx
,
1.0
));
expect
(
newSceneFocalPoint
.
dy
,
closeTo
(
sceneFocalPoint
.
dy
,
1.0
));
});
testWidgets
(
'Can scale with mouse'
,
(
WidgetTester
tester
)
async
{
final
TransformationController
transformationController
=
TransformationController
();
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Center
(
child:
InteractiveViewer
(
transformationController:
transformationController
,
child:
Container
(
width:
200.0
,
height:
200.0
),
),
),
),
),
);
final
Offset
center
=
tester
.
getCenter
(
find
.
byType
(
InteractiveViewer
));
await
scrollAt
(
center
,
tester
);
await
tester
.
pumpAndSettle
();
expect
(
transformationController
.
value
.
getMaxScaleOnAxis
(),
greaterThan
(
1.0
));
});
testWidgets
(
'Cannot scale with mouse when scale is disabled'
,
(
WidgetTester
tester
)
async
{
final
TransformationController
transformationController
=
TransformationController
();
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Center
(
child:
InteractiveViewer
(
transformationController:
transformationController
,
scaleEnabled:
false
,
child:
Container
(
width:
200.0
,
height:
200.0
),
),
),
),
),
);
final
Offset
center
=
tester
.
getCenter
(
find
.
byType
(
InteractiveViewer
));
await
scrollAt
(
center
,
tester
);
await
tester
.
pumpAndSettle
();
expect
(
transformationController
.
value
.
getMaxScaleOnAxis
(),
equals
(
1.0
));
});
});
group
(
'getNearestPointOnLine'
,
()
{
...
...
packages/flutter/test/widgets/listener_test.dart
View file @
b429ec1e
...
...
@@ -12,6 +12,7 @@ import 'package:flutter_test/flutter_test.dart';
import
'package:flutter/widgets.dart'
;
import
'package:flutter/gestures.dart'
;
import
'gesture_utils.dart'
;
void
main
(
)
{
testWidgets
(
'Events bubble up the tree'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -400,11 +401,3 @@ void main() {
]);
});
}
Future
<
void
>
scrollAt
(
Offset
position
,
WidgetTester
tester
)
{
final
TestPointer
testPointer
=
TestPointer
(
1
,
PointerDeviceKind
.
mouse
);
// Create a hover event so that |testPointer| has a location when generating the scroll.
testPointer
.
hover
(
position
);
final
HitTestResult
result
=
tester
.
hitTestOnBinding
(
position
);
return
tester
.
sendEventToBinding
(
testPointer
.
scroll
(
const
Offset
(
0.0
,
20.0
)),
result
);
}
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