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
38805a43
Unverified
Commit
38805a43
authored
Apr 04, 2023
by
Taha Tesser
Committed by
GitHub
Apr 04, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix `clipBehavior` for `Drawer` with shape and add `clipBehavior` property. (#124104)
parent
9e4b5fb7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
3 deletions
+117
-3
drawer.dart
packages/flutter/lib/src/material/drawer.dart
+14
-3
drawer_test.dart
packages/flutter/test/material/drawer_test.dart
+103
-0
No files found.
packages/flutter/lib/src/material/drawer.dart
View file @
38805a43
...
...
@@ -153,6 +153,7 @@ class Drawer extends StatelessWidget {
this
.
width
,
this
.
child
,
this
.
semanticLabel
,
this
.
clipBehavior
,
})
:
assert
(
elevation
==
null
||
elevation
>=
0.0
);
/// Sets the color of the [Material] that holds all of the [Drawer]'s
...
...
@@ -237,6 +238,14 @@ class Drawer extends StatelessWidget {
/// value is used.
final
String
?
semanticLabel
;
/// {@macro flutter.material.Material.clipBehavior}
///
/// The [clipBehavior] argument specifies how to clip the drawer's [shape].
///
/// If the drawer has a [shape], it defaults to [Clip.hardEdge]. Otherwise,
/// defaults to [Clip.none].
final
Clip
?
clipBehavior
;
@override
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasMaterialLocalizations
(
context
));
...
...
@@ -255,6 +264,9 @@ class Drawer extends StatelessWidget {
final
bool
useMaterial3
=
Theme
.
of
(
context
).
useMaterial3
;
final
bool
isDrawerStart
=
DrawerController
.
maybeOf
(
context
)?.
alignment
!=
DrawerAlignment
.
end
;
final
DrawerThemeData
defaults
=
useMaterial3
?
_DrawerDefaultsM3
(
context
):
_DrawerDefaultsM2
(
context
);
final
ShapeBorder
?
effectiveShape
=
shape
??
(
isDrawerStart
?
(
drawerTheme
.
shape
??
defaults
.
shape
)
:
(
drawerTheme
.
endShape
??
defaults
.
endShape
));
return
Semantics
(
scopesRoute:
true
,
namesRoute:
true
,
...
...
@@ -267,9 +279,8 @@ class Drawer extends StatelessWidget {
elevation:
elevation
??
drawerTheme
.
elevation
??
defaults
.
elevation
!,
shadowColor:
shadowColor
??
drawerTheme
.
shadowColor
??
defaults
.
shadowColor
,
surfaceTintColor:
surfaceTintColor
??
drawerTheme
.
surfaceTintColor
??
defaults
.
surfaceTintColor
,
shape:
shape
??
(
isDrawerStart
?
(
drawerTheme
.
shape
??
defaults
.
shape
)
:
(
drawerTheme
.
endShape
??
defaults
.
endShape
)),
shape:
effectiveShape
,
clipBehavior:
effectiveShape
!=
null
?
(
clipBehavior
??
Clip
.
hardEdge
)
:
Clip
.
none
,
child:
child
,
),
),
...
...
packages/flutter/test/material/drawer_test.dart
View file @
38805a43
...
...
@@ -688,6 +688,57 @@ void main() {
);
});
testWidgets
(
'Drawer clip behavior'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
(
useMaterial3:
true
),
home:
const
Scaffold
(
drawer:
Drawer
(),
),
),
);
final
Finder
drawerMaterial
=
find
.
descendant
(
of:
find
.
byType
(
Drawer
),
matching:
find
.
byType
(
Material
),
);
final
ScaffoldState
state
=
tester
.
firstState
(
find
.
byType
(
Scaffold
));
// Open the drawer.
state
.
openDrawer
();
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// Test default clip behavior.
Material
material
=
tester
.
widget
<
Material
>(
drawerMaterial
);
expect
(
material
.
clipBehavior
,
Clip
.
hardEdge
);
state
.
closeDrawer
();
await
tester
.
pumpAndSettle
();
// Provide a custom clip behavior.
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
(
useMaterial3:
true
),
home:
const
Scaffold
(
drawer:
Drawer
(
clipBehavior:
Clip
.
antiAlias
,
),
),
),
);
// Open the drawer again.
state
.
openDrawer
();
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// Clip behavior is now updated.
material
=
tester
.
widget
<
Material
>(
drawerMaterial
);
expect
(
material
.
clipBehavior
,
Clip
.
antiAlias
);
});
group
(
'Material 2'
,
()
{
// Tests that are only relevant for Material 2. Once ThemeData.useMaterial3
// is turned on by default, these tests can be removed.
...
...
@@ -732,5 +783,57 @@ void main() {
material
=
tester
.
widget
<
Material
>(
drawerMaterial
);
expect
(
material
.
shape
,
null
);
});
testWidgets
(
'Drawer clip behavior'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
(
useMaterial3:
false
),
home:
const
Scaffold
(
drawer:
Drawer
(),
),
),
);
final
Finder
drawerMaterial
=
find
.
descendant
(
of:
find
.
byType
(
Drawer
),
matching:
find
.
byType
(
Material
),
);
final
ScaffoldState
state
=
tester
.
firstState
(
find
.
byType
(
Scaffold
));
// Open the drawer.
state
.
openDrawer
();
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// Test default clip behavior.
Material
material
=
tester
.
widget
<
Material
>(
drawerMaterial
);
expect
(
material
.
clipBehavior
,
Clip
.
none
);
state
.
closeDrawer
();
await
tester
.
pumpAndSettle
();
// Provide a shape and custom clip behavior.
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
(
useMaterial3:
false
),
home:
const
Scaffold
(
drawer:
Drawer
(
clipBehavior:
Clip
.
hardEdge
,
shape:
RoundedRectangleBorder
(),
),
),
),
);
// Open the drawer again.
state
.
openDrawer
();
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// Clip behavior is now updated.
material
=
tester
.
widget
<
Material
>(
drawerMaterial
);
expect
(
material
.
clipBehavior
,
Clip
.
hardEdge
);
});
});
}
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