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
cf87f68f
Unverified
Commit
cf87f68f
authored
Aug 23, 2019
by
Hans Muller
Committed by
GitHub
Aug 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correct InheritedTheme.captureAll() for multiple theme ancestors of the same type (#39089)
parent
d1e0273e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
114 additions
and
1 deletion
+114
-1
inherited_theme.dart
packages/flutter/lib/src/widgets/inherited_theme.dart
+9
-1
inherited_theme_test.dart
packages/flutter/test/widgets/inherited_theme_test.dart
+105
-0
No files found.
packages/flutter/lib/src/widgets/inherited_theme.dart
View file @
cf87f68f
...
...
@@ -114,10 +114,18 @@ abstract class InheritedTheme extends InheritedWidget {
assert
(
context
!=
null
);
final
List
<
InheritedTheme
>
themes
=
<
InheritedTheme
>[];
final
Set
<
Type
>
themeTypes
=
<
Type
>{};
context
.
visitAncestorElements
((
Element
ancestor
)
{
if
(
ancestor
is
InheritedElement
&&
ancestor
.
widget
is
InheritedTheme
)
{
final
InheritedTheme
theme
=
ancestor
.
widget
;
themes
.
add
(
theme
);
final
Type
themeType
=
theme
.
runtimeType
;
// Only remember the first theme of any type. This assumes
// that inherited themes completely shadow ancestors of the
// the same type.
if
(!
themeTypes
.
contains
(
themeType
))
{
themeTypes
.
add
(
themeType
);
themes
.
add
(
theme
);
}
}
return
true
;
});
...
...
packages/flutter/test/widgets/inherited_theme_test.dart
View file @
cf87f68f
...
...
@@ -144,6 +144,111 @@ void main() {
expect
(
getTextStyle
(
'Hello'
).
fontSize
,
fontSize
);
expect
(
getIconStyle
().
color
,
iconColor
);
expect
(
getIconStyle
().
fontSize
,
iconSize
);
});
testWidgets
(
'InheritedTheme.captureAll() multiple IconTheme ancestors'
,
(
WidgetTester
tester
)
async
{
// This is a regression test for https://github.com/flutter/flutter/issues/39087
const
Color
outerColor
=
Color
(
0xFF0000FF
);
const
Color
innerColor
=
Color
(
0xFF00FF00
);
const
double
iconSize
=
48
;
final
Key
icon1
=
UniqueKey
();
final
Key
icon2
=
UniqueKey
();
await
tester
.
pumpWidget
(
WidgetsApp
(
color:
const
Color
(
0xFFFFFFFF
),
onGenerateRoute:
(
RouteSettings
settings
)
{
return
TestRoute
(
IconTheme
(
data:
const
IconThemeData
(
color:
outerColor
),
child:
IconTheme
(
data:
const
IconThemeData
(
size:
iconSize
,
color:
innerColor
),
child:
Center
(
child:
Row
(
mainAxisSize:
MainAxisSize
.
min
,
children:
<
Widget
>[
Icon
(
const
IconData
(
0x41
,
fontFamily:
'Roboto'
),
key:
icon1
),
Builder
(
builder:
(
BuildContext
context
)
{
// The same IconThemes are visible from this context
// and the context that the widget returned by captureAll()
// is built in. So only the inner green IconTheme should
// apply to the icon, i.e. both icons will be big and green.
return
InheritedTheme
.
captureAll
(
context
,
Icon
(
const
IconData
(
0x41
,
fontFamily:
'Roboto'
),
key:
icon2
),
);
},
),
],
),
),
),
),
);
},
)
);
TextStyle
getIconStyle
(
Key
key
)
{
return
tester
.
widget
<
RichText
>(
find
.
descendant
(
of:
find
.
byKey
(
key
),
matching:
find
.
byType
(
RichText
),
),
).
text
.
style
;
}
expect
(
getIconStyle
(
icon1
).
color
,
innerColor
);
expect
(
getIconStyle
(
icon1
).
fontSize
,
iconSize
);
expect
(
getIconStyle
(
icon2
).
color
,
innerColor
);
expect
(
getIconStyle
(
icon2
).
fontSize
,
iconSize
);
});
testWidgets
(
'InheritedTheme.captureAll() multiple DefaultTextStyle ancestors'
,
(
WidgetTester
tester
)
async
{
// This is a regression test for https://github.com/flutter/flutter/issues/39087
const
Color
textColor
=
Color
(
0xFF00FF00
);
await
tester
.
pumpWidget
(
WidgetsApp
(
color:
const
Color
(
0xFFFFFFFF
),
onGenerateRoute:
(
RouteSettings
settings
)
{
return
TestRoute
(
DefaultTextStyle
(
style:
const
TextStyle
(
fontSize:
48
),
child:
DefaultTextStyle
(
style:
const
TextStyle
(
color:
textColor
),
child:
Row
(
children:
<
Widget
>[
const
Text
(
'Hello'
),
Builder
(
builder:
(
BuildContext
context
)
{
return
InheritedTheme
.
captureAll
(
context
,
const
Text
(
'World'
));
},
),
],
),
),
),
);
},
),
);
TextStyle
getTextStyle
(
String
text
)
{
return
tester
.
widget
<
RichText
>(
find
.
descendant
(
of:
find
.
text
(
text
),
matching:
find
.
byType
(
RichText
),
),
).
text
.
style
;
}
expect
(
getTextStyle
(
'Hello'
).
fontSize
,
null
);
expect
(
getTextStyle
(
'Hello'
).
color
,
textColor
);
expect
(
getTextStyle
(
'World'
).
fontSize
,
null
);
expect
(
getTextStyle
(
'World'
).
color
,
textColor
);
});
}
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