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
729ba11b
Unverified
Commit
729ba11b
authored
Jun 02, 2020
by
Tong Mu
Committed by
GitHub
Jun 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add doc and test for Container's hitTest behavior (#57522)
parent
0bda6335
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
0 deletions
+60
-0
container.dart
packages/flutter/lib/src/widgets/container.dart
+5
-0
container_test.dart
packages/flutter/test/widgets/container_test.dart
+55
-0
No files found.
packages/flutter/lib/src/widgets/container.dart
View file @
729ba11b
...
...
@@ -184,6 +184,11 @@ class DecoratedBox extends SingleChildRenderObjectWidget {
/// `width`, `height`, and [constraints] arguments to the constructor override
/// this.
///
/// By default, containers return false for all hit tests. If the [color]
/// property is specified, the hit testing is handled by [ColoredBox], which
/// always returns true. If the [decoration] or [foregroundDecoration] properties
/// are specified, hit testing is handled by [Decoration.hitTest].
///
/// ## Layout behavior
///
/// _See [BoxConstraints] for an introduction to box layout models._
...
...
packages/flutter/test/widgets/container_test.dart
View file @
729ba11b
...
...
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/material.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:mockito/mockito.dart'
;
...
...
@@ -502,6 +503,60 @@ void main() {
findsOneWidget
,
);
});
testWidgets
(
'Container is hittable only when having decorations'
,
(
WidgetTester
tester
)
async
{
bool
tapped
=
false
;
await
tester
.
pumpWidget
(
GestureDetector
(
onTap:
()
{
tapped
=
true
;
},
child:
Container
(
decoration:
const
BoxDecoration
(
color:
Colors
.
black
),
),
));
await
tester
.
tap
(
find
.
byType
(
Container
));
expect
(
tapped
,
true
);
tapped
=
false
;
await
tester
.
pumpWidget
(
GestureDetector
(
onTap:
()
{
tapped
=
true
;
},
child:
Container
(
foregroundDecoration:
const
BoxDecoration
(
color:
Colors
.
black
),
),
));
await
tester
.
tap
(
find
.
byType
(
Container
));
expect
(
tapped
,
true
);
tapped
=
false
;
await
tester
.
pumpWidget
(
GestureDetector
(
onTap:
()
{
tapped
=
true
;
},
child:
Container
(
color:
Colors
.
black
,
),
));
await
tester
.
tap
(
find
.
byType
(
Container
));
expect
(
tapped
,
true
);
tapped
=
false
;
// Everything but color or decorations
await
tester
.
pumpWidget
(
GestureDetector
(
onTap:
()
{
tapped
=
true
;
},
child:
Center
(
child:
Container
(
alignment:
Alignment
.
bottomRight
,
padding:
const
EdgeInsets
.
all
(
2
),
width:
50
,
height:
50
,
margin:
const
EdgeInsets
.
all
(
2
),
transform:
Matrix4
.
rotationZ
(
1
),
),
),
));
await
tester
.
tap
(
find
.
byType
(
Container
));
expect
(
tapped
,
false
);
});
}
class
_MockPaintingContext
extends
Mock
implements
PaintingContext
{}
...
...
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