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
a499e05f
Commit
a499e05f
authored
Jan 22, 2020
by
LongCatIsLooong
Committed by
Flutter GitHub Bot
Jan 22, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Let material ThemeData dictate brightness if cupertinoOverrideTheme.brightness is null (#47249)
parent
8a3c9863
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
25 deletions
+55
-25
text_field.dart
packages/flutter/lib/src/cupertino/text_field.dart
+1
-1
theme.dart
packages/flutter/lib/src/cupertino/theme.dart
+26
-20
theme_test.dart
packages/flutter/test/cupertino/theme_test.dart
+1
-1
theme_test.dart
packages/flutter/test/material/theme_test.dart
+27
-3
No files found.
packages/flutter/lib/src/cupertino/text_field.dart
View file @
a499e05f
...
...
@@ -847,7 +847,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK
final
TextStyle
placeholderStyle
=
textStyle
.
merge
(
resolvedPlaceholderStyle
);
final
Brightness
keyboardAppearance
=
widget
.
keyboardAppearance
??
themeData
.
brightness
;
final
Brightness
keyboardAppearance
=
widget
.
keyboardAppearance
??
CupertinoTheme
.
brightnessOf
(
context
)
;
final
Color
cursorColor
=
CupertinoDynamicColor
.
resolve
(
widget
.
cursorColor
,
context
)
??
themeData
.
primaryColor
;
final
Color
disabledColor
=
CupertinoDynamicColor
.
resolve
(
_kDisabledBackground
,
context
);
...
...
packages/flutter/lib/src/cupertino/theme.dart
View file @
a499e05f
...
...
@@ -71,17 +71,22 @@ class CupertinoTheme extends StatelessWidget {
return
(
inheritedTheme
?.
theme
?.
data
??
const
CupertinoThemeData
()).
resolveFrom
(
context
,
nullOk:
true
);
}
/// Retrieves the [Brightness]
value from the closest ancestor [CupertinoTheme]
///
widget
.
/// Retrieves the [Brightness]
to use for descendant Cupertino widgets, based
///
on the value of [CupertinoThemeData.brightness] in the given [context]
.
///
/// If no [CupertinoTheme]
ancestor with an explicit brightness value could be
///
found, this method will resort to the closest ancestor [MediaQuery] widget
.
/// If no [CupertinoTheme]
can be found in the given [context], or its `brightness`
///
is null, it will fall back to [MediaQueryData.brightness]
.
///
/// Throws an exception if no such [CupertinoTheme] or [MediaQuery] widgets exist
/// in the ancestry tree, unless [nullOk] is set to true.
/// Throws an exception if no valid [CupertinoTheme] or [MediaQuery] widgets
/// exist in the ancestry tree, unless [nullOk] is set to true.
///
/// See also:
///
/// * [CupertinoThemeData.brightness], the property takes precedence over
/// [MediaQueryData.platformBrightness] for descendant Cupertino widgets.
static
Brightness
brightnessOf
(
BuildContext
context
,
{
bool
nullOk
=
false
})
{
final
_InheritedCupertinoTheme
inheritedTheme
=
context
.
dependOnInheritedWidgetOfExactType
<
_InheritedCupertinoTheme
>();
return
inheritedTheme
?.
theme
?.
data
?.
_
brightness
??
MediaQuery
.
of
(
context
,
nullOk:
nullOk
)?.
platformBrightness
;
return
inheritedTheme
?.
theme
?.
data
?.
brightness
??
MediaQuery
.
of
(
context
,
nullOk:
nullOk
)?.
platformBrightness
;
}
/// The widget below this widget in the tree.
...
...
@@ -181,7 +186,7 @@ class CupertinoThemeData extends Diagnosticable {
);
const
CupertinoThemeData
.
_rawWithDefaults
(
this
.
_
brightness
,
this
.
brightness
,
this
.
_primaryColor
,
this
.
_primaryContrastingColor
,
this
.
_textTheme
,
...
...
@@ -192,10 +197,11 @@ class CupertinoThemeData extends Diagnosticable {
final
_CupertinoThemeDefaults
_defaults
;
/// The
general brightness theme of the [CupertinoThemeData]
.
/// The
brightness override for Cupertino descendants
.
///
/// Overrides the ambient [MediaQueryData.platformBrightness] when specified.
/// Defaults to [Brightness.light].
/// Defaults to null. If a non-null [Brightness] is specified, the value will
/// take precedence over the ambient [MediaQueryData.platformBrightness], when
/// determining the brightness of descendant Cupertino widgets.
///
/// If coming from a Material [Theme] and unspecified, [brightness] will be
/// derived from the Material [ThemeData]'s `brightness`.
...
...
@@ -204,8 +210,10 @@ class CupertinoThemeData extends Diagnosticable {
///
/// * [MaterialBasedCupertinoThemeData], a [CupertinoThemeData] that defers
/// [brightness] to its Material [Theme] parent if it's unspecified.
Brightness
get
brightness
=>
_brightness
??
Brightness
.
light
;
final
Brightness
_brightness
;
///
/// * [CupertinoTheme.brightnessOf], a method used to retrieve the overall
/// [Brightness] from a [BuildContext], for Cupertino widgets.
final
Brightness
brightness
;
/// A color used on interactive elements of the theme.
///
...
...
@@ -268,7 +276,7 @@ class CupertinoThemeData extends Diagnosticable {
/// theme properties instead of iOS defaults.
CupertinoThemeData
noDefault
()
{
return
_NoDefaultCupertinoThemeData
(
_
brightness
,
brightness
,
_primaryColor
,
_primaryContrastingColor
,
_textTheme
,
...
...
@@ -287,7 +295,7 @@ class CupertinoThemeData extends Diagnosticable {
Color
convertColor
(
Color
color
)
=>
CupertinoDynamicColor
.
resolve
(
color
,
context
,
nullOk:
nullOk
);
return
CupertinoThemeData
.
_rawWithDefaults
(
_
brightness
,
brightness
,
convertColor
(
_primaryColor
),
convertColor
(
_primaryContrastingColor
),
_textTheme
?.
resolveFrom
(
context
,
nullOk:
nullOk
),
...
...
@@ -313,7 +321,7 @@ class CupertinoThemeData extends Diagnosticable {
Color
scaffoldBackgroundColor
,
})
{
return
CupertinoThemeData
.
_rawWithDefaults
(
brightness
??
_
brightness
,
brightness
??
this
.
brightness
,
primaryColor
??
_primaryColor
,
primaryContrastingColor
??
_primaryContrastingColor
,
textTheme
??
_textTheme
,
...
...
@@ -327,7 +335,7 @@ class CupertinoThemeData extends Diagnosticable {
void
debugFillProperties
(
DiagnosticPropertiesBuilder
properties
)
{
super
.
debugFillProperties
(
properties
);
const
CupertinoThemeData
defaultData
=
CupertinoThemeData
();
properties
.
add
(
EnumProperty
<
Brightness
>(
'brightness'
,
brightness
,
defaultValue:
defaultData
.
brightness
));
properties
.
add
(
EnumProperty
<
Brightness
>(
'brightness'
,
brightness
,
defaultValue:
null
));
properties
.
add
(
createCupertinoColorProperty
(
'primaryColor'
,
primaryColor
,
defaultValue:
defaultData
.
primaryColor
));
properties
.
add
(
createCupertinoColorProperty
(
'primaryContrastingColor'
,
primaryContrastingColor
,
defaultValue:
defaultData
.
primaryContrastingColor
));
properties
.
add
(
createCupertinoColorProperty
(
'barBackgroundColor'
,
barBackgroundColor
,
defaultValue:
defaultData
.
barBackgroundColor
));
...
...
@@ -338,7 +346,7 @@ class CupertinoThemeData extends Diagnosticable {
class
_NoDefaultCupertinoThemeData
extends
CupertinoThemeData
{
const
_NoDefaultCupertinoThemeData
(
this
.
brightness
,
Brightness
brightness
,
this
.
primaryColor
,
this
.
primaryContrastingColor
,
this
.
textTheme
,
...
...
@@ -354,8 +362,6 @@ class _NoDefaultCupertinoThemeData extends CupertinoThemeData {
null
,
);
@override
final
Brightness
brightness
;
@override
final
Color
primaryColor
;
@override
...
...
packages/flutter/test/cupertino/theme_test.dart
View file @
a499e05f
...
...
@@ -52,7 +52,7 @@ void main() {
testWidgets
(
'Default theme has defaults'
,
(
WidgetTester
tester
)
async
{
final
CupertinoThemeData
theme
=
await
testTheme
(
tester
,
const
CupertinoThemeData
());
expect
(
theme
.
brightness
,
Brightness
.
light
);
expect
(
theme
.
brightness
,
isNull
);
expect
(
theme
.
primaryColor
,
CupertinoColors
.
activeBlue
);
expect
(
theme
.
textTheme
.
textStyle
.
fontSize
,
17.0
);
});
...
...
packages/flutter/test/material/theme_test.dart
View file @
a499e05f
...
...
@@ -418,12 +418,14 @@ void main() {
int
buildCount
;
CupertinoThemeData
actualTheme
;
IconThemeData
actualIconTheme
;
BuildContext
context
;
final
Widget
singletonThemeSubtree
=
Builder
(
builder:
(
BuildContext
c
ontext
)
{
builder:
(
BuildContext
localC
ontext
)
{
buildCount
++;
actualTheme
=
CupertinoTheme
.
of
(
context
);
actualIconTheme
=
IconTheme
.
of
(
context
);
actualTheme
=
CupertinoTheme
.
of
(
localContext
);
actualIconTheme
=
IconTheme
.
of
(
localContext
);
context
=
localContext
;
return
const
Placeholder
();
},
);
...
...
@@ -437,6 +439,7 @@ void main() {
buildCount
=
0
;
actualTheme
=
null
;
actualIconTheme
=
null
;
context
=
null
;
});
testWidgets
(
'Default theme has defaults'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -461,6 +464,27 @@ void main() {
expect
(
theme
.
textTheme
.
textStyle
.
fontSize
,
17.0
);
});
testWidgets
(
'MaterialTheme overrides the brightness'
,
(
WidgetTester
tester
)
async
{
await
testTheme
(
tester
,
ThemeData
.
dark
());
expect
(
CupertinoTheme
.
brightnessOf
(
context
),
Brightness
.
dark
);
await
testTheme
(
tester
,
ThemeData
.
light
());
expect
(
CupertinoTheme
.
brightnessOf
(
context
),
Brightness
.
light
);
// Overridable by cupertinoOverrideTheme.
await
testTheme
(
tester
,
ThemeData
(
brightness:
Brightness
.
light
,
cupertinoOverrideTheme:
const
CupertinoThemeData
(
brightness:
Brightness
.
dark
),
));
expect
(
CupertinoTheme
.
brightnessOf
(
context
),
Brightness
.
dark
);
await
testTheme
(
tester
,
ThemeData
(
brightness:
Brightness
.
dark
,
cupertinoOverrideTheme:
const
CupertinoThemeData
(
brightness:
Brightness
.
light
),
));
expect
(
CupertinoTheme
.
brightnessOf
(
context
),
Brightness
.
light
);
});
testWidgets
(
'Can override material theme'
,
(
WidgetTester
tester
)
async
{
final
CupertinoThemeData
theme
=
await
testTheme
(
tester
,
ThemeData
(
cupertinoOverrideTheme:
const
CupertinoThemeData
(
...
...
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