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
aafdbc6d
Unverified
Commit
aafdbc6d
authored
Jul 21, 2023
by
hangyu
Committed by
GitHub
Jul 21, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for navigation_drawer_theme_test.dart (#130465)
fixes:
https://github.com/flutter/flutter/issues/129618
parent
d67d2c3d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
296 additions
and
4 deletions
+296
-4
navigation_drawer.dart
packages/flutter/lib/src/material/navigation_drawer.dart
+5
-4
navigation_drawer_theme_test.dart
...s/flutter/test/material/navigation_drawer_theme_test.dart
+291
-0
No files found.
packages/flutter/lib/src/material/navigation_drawer.dart
View file @
aafdbc6d
...
...
@@ -165,12 +165,13 @@ class NavigationDrawer extends StatelessWidget {
destinationIndex
+=
1
;
}
}
final
NavigationDrawerThemeData
navigationDrawerTheme
=
NavigationDrawerTheme
.
of
(
context
);
return
Drawer
(
backgroundColor:
backgroundColor
,
shadowColor:
shadowColor
,
surfaceTintColor:
surfaceTintColor
,
elevation:
elevation
,
backgroundColor:
backgroundColor
??
navigationDrawerTheme
.
backgroundColor
,
shadowColor:
shadowColor
??
navigationDrawerTheme
.
shadowColor
,
surfaceTintColor:
surfaceTintColor
??
navigationDrawerTheme
.
surfaceTintColor
,
elevation:
elevation
??
navigationDrawerTheme
.
elevation
,
child:
SafeArea
(
bottom:
false
,
child:
ListView
(
...
...
packages/flutter/test/material/navigation_drawer_theme_test.dart
View file @
aafdbc6d
...
...
@@ -3,6 +3,7 @@
// found in the LICENSE file.
import
'package:flutter/material.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
...
...
@@ -16,4 +17,294 @@ void main() {
const
NavigationDrawerThemeData
data
=
NavigationDrawerThemeData
();
expect
(
identical
(
NavigationDrawerThemeData
.
lerp
(
data
,
data
,
0.5
),
data
),
true
);
});
testWidgets
(
'Default debugFillProperties'
,
(
WidgetTester
tester
)
async
{
final
DiagnosticPropertiesBuilder
builder
=
DiagnosticPropertiesBuilder
();
const
NavigationDrawerThemeData
().
debugFillProperties
(
builder
);
final
List
<
String
>
description
=
builder
.
properties
.
where
((
DiagnosticsNode
node
)
=>
!
node
.
isFiltered
(
DiagnosticLevel
.
info
))
.
map
((
DiagnosticsNode
node
)
=>
node
.
toString
())
.
toList
();
expect
(
description
,
<
String
>[]);
});
testWidgets
(
'NavigationDrawerThemeData implements debugFillProperties'
,
(
WidgetTester
tester
)
async
{
final
DiagnosticPropertiesBuilder
builder
=
DiagnosticPropertiesBuilder
();
const
NavigationDrawerThemeData
(
tileHeight:
50
,
backgroundColor:
Color
(
0x00000099
),
elevation:
5.0
,
shadowColor:
Color
(
0x00000098
),
surfaceTintColor:
Color
(
0x00000097
),
indicatorColor:
Color
(
0x00000096
),
indicatorShape:
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
all
(
Radius
.
circular
(
2.0
))),
indicatorSize:
Size
(
10
,
10
),
labelTextStyle:
MaterialStatePropertyAll
<
TextStyle
>(
TextStyle
(
fontSize:
7.0
)),
iconTheme:
MaterialStatePropertyAll
<
IconThemeData
>(
IconThemeData
(
color:
Color
(
0x00000095
))),
).
debugFillProperties
(
builder
);
final
List
<
String
>
description
=
builder
.
properties
.
where
((
DiagnosticsNode
node
)
=>
!
node
.
isFiltered
(
DiagnosticLevel
.
info
))
.
map
((
DiagnosticsNode
node
)
=>
node
.
toString
())
.
toList
();
expect
(
description
,
equalsIgnoringHashCodes
(
<
String
>[
'tileHeight: 50.0'
,
'backgroundColor: Color(0x00000099)'
,
'elevation: 5.0'
,
'shadowColor: Color(0x00000098)'
,
'surfaceTintColor: Color(0x00000097)'
,
'indicatorColor: Color(0x00000096)'
,
'indicatorShape: RoundedRectangleBorder(BorderSide(width: 0.0, style: none), BorderRadius.circular(2.0))'
,
'indicatorSize: Size(10.0, 10.0)'
,
'labelTextStyle: MaterialStatePropertyAll(TextStyle(inherit: true, size: 7.0))'
,
'iconTheme: MaterialStatePropertyAll(IconThemeData#00000(color: Color(0x00000095)))'
],
));
});
testWidgets
(
'NavigationDrawerThemeData values are used when no NavigationDrawer properties are specified'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
ScaffoldState
>
scaffoldKey
=
GlobalKey
<
ScaffoldState
>();
const
NavigationDrawerThemeData
navigationDrawerTheme
=
NavigationDrawerThemeData
(
backgroundColor:
Color
(
0x00000001
),
elevation:
7.0
,
shadowColor:
Color
(
0x00000002
),
surfaceTintColor:
Color
(
0x00000003
),
indicatorColor:
Color
(
0x00000004
),
indicatorShape:
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
only
(
topRight:
Radius
.
circular
(
16.0
))),
labelTextStyle:
MaterialStatePropertyAll
<
TextStyle
>(
TextStyle
(
fontSize:
7.0
)),
iconTheme:
MaterialStatePropertyAll
<
IconThemeData
>(
IconThemeData
(
color:
Color
(
0x00000005
))),
);
await
tester
.
pumpWidget
(
_buildWidget
(
scaffoldKey
,
NavigationDrawer
(
children:
const
<
Widget
>[
Text
(
'Headline'
),
NavigationDrawerDestination
(
icon:
Icon
(
Icons
.
ac_unit
),
label:
Text
(
'AC'
),
),
NavigationDrawerDestination
(
icon:
Icon
(
Icons
.
access_alarm
),
label:
Text
(
'Alarm'
),
),
],
onDestinationSelected:
(
int
i
)
{},
),
theme:
ThemeData
(
navigationDrawerTheme:
navigationDrawerTheme
,
),
),
);
scaffoldKey
.
currentState
!.
openDrawer
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// Test drawer Material.
expect
(
_getMaterial
(
tester
).
color
,
navigationDrawerTheme
.
backgroundColor
);
expect
(
_getMaterial
(
tester
).
surfaceTintColor
,
navigationDrawerTheme
.
surfaceTintColor
);
expect
(
_getMaterial
(
tester
).
shadowColor
,
navigationDrawerTheme
.
shadowColor
);
expect
(
_getMaterial
(
tester
).
elevation
,
7
);
// Test indicator decoration.
expect
(
_getIndicatorDecoration
(
tester
)?.
color
,
navigationDrawerTheme
.
indicatorColor
);
expect
(
_getIndicatorDecoration
(
tester
)?.
shape
,
navigationDrawerTheme
.
indicatorShape
);
// Test icon.
expect
(
_iconStyle
(
tester
,
Icons
.
ac_unit
)?.
color
,
navigationDrawerTheme
.
iconTheme
?.
resolve
(<
MaterialState
>{})?.
color
,
);
expect
(
_iconStyle
(
tester
,
Icons
.
access_alarm
)?.
color
,
navigationDrawerTheme
.
iconTheme
?.
resolve
(<
MaterialState
>{})?.
color
,
);
// Test label.
expect
(
_labelStyle
(
tester
,
'AC'
),
navigationDrawerTheme
.
labelTextStyle
?.
resolve
(<
MaterialState
>{})
);
expect
(
_labelStyle
(
tester
,
'Alarm'
),
navigationDrawerTheme
.
labelTextStyle
?.
resolve
(<
MaterialState
>{})
);
});
testWidgets
(
'NavigationDrawer values take priority over NavigationDrawerThemeData values when both properties are specified'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
ScaffoldState
>
scaffoldKey
=
GlobalKey
<
ScaffoldState
>();
const
NavigationDrawerThemeData
navigationDrawerTheme
=
NavigationDrawerThemeData
(
backgroundColor:
Color
(
0x00000001
),
elevation:
7.0
,
shadowColor:
Color
(
0x00000002
),
surfaceTintColor:
Color
(
0x00000003
),
indicatorColor:
Color
(
0x00000004
),
indicatorShape:
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
only
(
topRight:
Radius
.
circular
(
16.0
))),
labelTextStyle:
MaterialStatePropertyAll
<
TextStyle
>(
TextStyle
(
fontSize:
7.0
)),
iconTheme:
MaterialStatePropertyAll
<
IconThemeData
>(
IconThemeData
(
color:
Color
(
0x00000005
))),
);
const
Color
backgroundColor
=
Color
(
0x00000009
);
const
double
elevation
=
14.0
;
const
Color
shadowColor
=
Color
(
0x00000008
);
const
Color
surfaceTintColor
=
Color
(
0x00000007
);
const
RoundedRectangleBorder
indicatorShape
=
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
all
(
Radius
.
circular
(
32.0
)));
const
Color
indicatorColor
=
Color
(
0x00000006
);
await
tester
.
pumpWidget
(
_buildWidget
(
scaffoldKey
,
NavigationDrawer
(
backgroundColor:
backgroundColor
,
elevation:
elevation
,
shadowColor:
shadowColor
,
surfaceTintColor:
surfaceTintColor
,
indicatorShape:
indicatorShape
,
indicatorColor:
indicatorColor
,
children:
const
<
Widget
>[
Text
(
'Headline'
),
NavigationDrawerDestination
(
icon:
Icon
(
Icons
.
ac_unit
),
label:
Text
(
'AC'
),
),
NavigationDrawerDestination
(
icon:
Icon
(
Icons
.
access_alarm
),
label:
Text
(
'Alarm'
),
),
],
onDestinationSelected:
(
int
i
)
{},
),
theme:
ThemeData
(
navigationDrawerTheme:
navigationDrawerTheme
,
),
),
);
scaffoldKey
.
currentState
!.
openDrawer
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// Test drawer Material.
expect
(
_getMaterial
(
tester
).
color
,
backgroundColor
);
expect
(
_getMaterial
(
tester
).
surfaceTintColor
,
surfaceTintColor
);
expect
(
_getMaterial
(
tester
).
shadowColor
,
shadowColor
);
expect
(
_getMaterial
(
tester
).
elevation
,
elevation
);
// Test indicator decoration.
expect
(
_getIndicatorDecoration
(
tester
)?.
color
,
indicatorColor
);
expect
(
_getIndicatorDecoration
(
tester
)?.
shape
,
indicatorShape
);
});
testWidgets
(
'Local NavigationDrawerTheme takes priority over ThemeData.navigationDrawerTheme'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
ScaffoldState
>
scaffoldKey
=
GlobalKey
<
ScaffoldState
>();
const
Color
backgroundColor
=
Color
(
0x00000009
);
const
double
elevation
=
7.0
;
const
Color
shadowColor
=
Color
(
0x00000008
);
const
Color
surfaceTintColor
=
Color
(
0x00000007
);
const
Color
iconColor
=
Color
(
0x00000006
);
const
TextStyle
labelStyle
=
TextStyle
(
fontSize:
7.0
);
const
ShapeBorder
indicatorShape
=
CircleBorder
();
const
Color
indicatorColor
=
Color
(
0x00000005
);
await
tester
.
pumpWidget
(
_buildWidget
(
scaffoldKey
,
NavigationDrawerTheme
(
data:
const
NavigationDrawerThemeData
(
backgroundColor:
backgroundColor
,
elevation:
elevation
,
shadowColor:
shadowColor
,
surfaceTintColor:
surfaceTintColor
,
indicatorShape:
indicatorShape
,
indicatorColor:
indicatorColor
,
labelTextStyle:
MaterialStatePropertyAll
<
TextStyle
>(
TextStyle
(
fontSize:
7.0
)),
iconTheme:
MaterialStatePropertyAll
<
IconThemeData
>(
IconThemeData
(
color:
iconColor
)),
),
child:
NavigationDrawer
(
children:
const
<
Widget
>[
Text
(
'Headline'
),
NavigationDrawerDestination
(
icon:
Icon
(
Icons
.
ac_unit
),
label:
Text
(
'AC'
),
),
NavigationDrawerDestination
(
icon:
Icon
(
Icons
.
access_alarm
),
label:
Text
(
'Alarm'
),
),
],
onDestinationSelected:
(
int
i
)
{},
),
),
theme:
ThemeData
(
navigationDrawerTheme:
const
NavigationDrawerThemeData
(
backgroundColor:
Color
(
0x00000001
),
elevation:
7.0
,
shadowColor:
Color
(
0x00000002
),
surfaceTintColor:
Color
(
0x00000003
),
indicatorColor:
Color
(
0x00000004
),
indicatorShape:
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
only
(
topRight:
Radius
.
circular
(
16.0
))),
labelTextStyle:
MaterialStatePropertyAll
<
TextStyle
>(
TextStyle
(
fontSize:
7.0
)),
iconTheme:
MaterialStatePropertyAll
<
IconThemeData
>(
IconThemeData
(
color:
Color
(
0x00000005
))),
),
),
),
);
scaffoldKey
.
currentState
!.
openDrawer
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// Test drawer Material.
expect
(
_getMaterial
(
tester
).
color
,
backgroundColor
);
expect
(
_getMaterial
(
tester
).
surfaceTintColor
,
surfaceTintColor
);
expect
(
_getMaterial
(
tester
).
shadowColor
,
shadowColor
);
expect
(
_getMaterial
(
tester
).
elevation
,
elevation
);
// Test indicator decoration.
expect
(
_getIndicatorDecoration
(
tester
)?.
color
,
indicatorColor
);
expect
(
_getIndicatorDecoration
(
tester
)?.
shape
,
indicatorShape
);
// Test icon.
expect
(
_iconStyle
(
tester
,
Icons
.
ac_unit
)?.
color
,
iconColor
);
expect
(
_iconStyle
(
tester
,
Icons
.
access_alarm
)?.
color
,
iconColor
);
// Test label.
expect
(
_labelStyle
(
tester
,
'AC'
),
labelStyle
);
expect
(
_labelStyle
(
tester
,
'Alarm'
),
labelStyle
);
});
}
Widget
_buildWidget
(
GlobalKey
<
ScaffoldState
>
scaffoldKey
,
Widget
child
,
{
ThemeData
?
theme
})
{
return
MaterialApp
(
theme:
theme
,
home:
Scaffold
(
key:
scaffoldKey
,
drawer:
child
,
body:
Container
(),
),
);
}
Material
_getMaterial
(
WidgetTester
tester
)
{
return
tester
.
firstWidget
<
Material
>(
find
.
descendant
(
of:
find
.
byType
(
NavigationDrawer
),
matching:
find
.
byType
(
Material
),
));
}
ShapeDecoration
?
_getIndicatorDecoration
(
WidgetTester
tester
)
{
return
tester
.
firstWidget
<
Container
>(
find
.
descendant
(
of:
find
.
byType
(
FadeTransition
),
matching:
find
.
byType
(
Container
),
)).
decoration
as
ShapeDecoration
?;
}
TextStyle
?
_iconStyle
(
WidgetTester
tester
,
IconData
icon
)
{
return
tester
.
widget
<
RichText
>(
find
.
descendant
(
of:
find
.
byIcon
(
icon
),
matching:
find
.
byType
(
RichText
)),
).
text
.
style
;
}
TextStyle
?
_labelStyle
(
WidgetTester
tester
,
String
label
)
{
return
tester
.
widget
<
RichText
>(
find
.
descendant
(
of:
find
.
text
(
label
),
matching:
find
.
byType
(
RichText
),
)).
text
.
style
;
}
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