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
a671b283
Unverified
Commit
a671b283
authored
Aug 22, 2019
by
LongCatIsLooong
Committed by
GitHub
Aug 22, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CupertinoDynamicColor and friends (#37719)
parent
ffa37854
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
2466 additions
and
238 deletions
+2466
-238
cupertino.dart
packages/flutter/lib/cupertino.dart
+1
-0
app.dart
packages/flutter/lib/src/cupertino/app.dart
+46
-39
colors.dart
packages/flutter/lib/src/cupertino/colors.dart
+1126
-0
interface_level.dart
packages/flutter/lib/src/cupertino/interface_level.dart
+76
-0
slider.dart
packages/flutter/lib/src/cupertino/slider.dart
+21
-4
text_theme.dart
packages/flutter/lib/src/cupertino/text_theme.dart
+26
-0
theme.dart
packages/flutter/lib/src/cupertino/theme.dart
+66
-1
theme_data.dart
packages/flutter/lib/src/material/theme_data.dart
+48
-33
media_query.dart
packages/flutter/lib/src/widgets/media_query.dart
+17
-0
colors_test.dart
packages/flutter/test/cupertino/colors_test.dart
+748
-0
slider_test.dart
packages/flutter/test/cupertino/slider_test.dart
+291
-161
No files found.
packages/flutter/lib/cupertino.dart
View file @
a671b283
...
@@ -18,6 +18,7 @@ export 'src/cupertino/colors.dart';
...
@@ -18,6 +18,7 @@ export 'src/cupertino/colors.dart';
export
'src/cupertino/date_picker.dart'
;
export
'src/cupertino/date_picker.dart'
;
export
'src/cupertino/dialog.dart'
;
export
'src/cupertino/dialog.dart'
;
export
'src/cupertino/icons.dart'
;
export
'src/cupertino/icons.dart'
;
export
'src/cupertino/interface_level.dart'
;
export
'src/cupertino/localizations.dart'
;
export
'src/cupertino/localizations.dart'
;
export
'src/cupertino/nav_bar.dart'
;
export
'src/cupertino/nav_bar.dart'
;
export
'src/cupertino/page_scaffold.dart'
;
export
'src/cupertino/page_scaffold.dart'
;
...
...
packages/flutter/lib/src/cupertino/app.dart
View file @
a671b283
...
@@ -8,6 +8,7 @@ import 'package:flutter/widgets.dart';
...
@@ -8,6 +8,7 @@ import 'package:flutter/widgets.dart';
import
'button.dart'
;
import
'button.dart'
;
import
'colors.dart'
;
import
'colors.dart'
;
import
'icons.dart'
;
import
'icons.dart'
;
import
'interface_level.dart'
;
import
'localizations.dart'
;
import
'localizations.dart'
;
import
'route.dart'
;
import
'route.dart'
;
import
'theme.dart'
;
import
'theme.dart'
;
...
@@ -268,45 +269,51 @@ class _CupertinoAppState extends State<CupertinoApp> {
...
@@ -268,45 +269,51 @@ class _CupertinoAppState extends State<CupertinoApp> {
return
ScrollConfiguration
(
return
ScrollConfiguration
(
behavior:
_AlwaysCupertinoScrollBehavior
(),
behavior:
_AlwaysCupertinoScrollBehavior
(),
child:
CupertinoTheme
(
child:
CupertinoUserInterfaceLevel
(
data:
effectiveThemeData
,
data:
CupertinoUserInterfaceLevelData
.
base
,
child:
WidgetsApp
(
child:
CupertinoTheme
(
key:
GlobalObjectKey
(
this
),
data:
effectiveThemeData
,
navigatorKey:
widget
.
navigatorKey
,
child:
CupertinoSystemColors
(
navigatorObservers:
_navigatorObservers
,
data:
CupertinoSystemColors
.
of
(
context
,
useFallbackValues:
true
),
pageRouteBuilder:
<
T
>(
RouteSettings
settings
,
WidgetBuilder
builder
)
=>
child:
WidgetsApp
(
CupertinoPageRoute
<
T
>(
settings:
settings
,
builder:
builder
),
key:
GlobalObjectKey
(
this
),
home:
widget
.
home
,
navigatorKey:
widget
.
navigatorKey
,
routes:
widget
.
routes
,
navigatorObservers:
_navigatorObservers
,
initialRoute:
widget
.
initialRoute
,
pageRouteBuilder:
<
T
>(
RouteSettings
settings
,
WidgetBuilder
builder
)
=>
onGenerateRoute:
widget
.
onGenerateRoute
,
CupertinoPageRoute
<
T
>(
settings:
settings
,
builder:
builder
),
onUnknownRoute:
widget
.
onUnknownRoute
,
home:
widget
.
home
,
builder:
widget
.
builder
,
routes:
widget
.
routes
,
title:
widget
.
title
,
initialRoute:
widget
.
initialRoute
,
onGenerateTitle:
widget
.
onGenerateTitle
,
onGenerateRoute:
widget
.
onGenerateRoute
,
textStyle:
effectiveThemeData
.
textTheme
.
textStyle
,
onUnknownRoute:
widget
.
onUnknownRoute
,
color:
widget
.
color
??
CupertinoColors
.
activeBlue
,
builder:
widget
.
builder
,
locale:
widget
.
locale
,
title:
widget
.
title
,
localizationsDelegates:
_localizationsDelegates
,
onGenerateTitle:
widget
.
onGenerateTitle
,
localeResolutionCallback:
widget
.
localeResolutionCallback
,
textStyle:
effectiveThemeData
.
textTheme
.
textStyle
,
localeListResolutionCallback:
widget
.
localeListResolutionCallback
,
color:
widget
.
color
??
CupertinoColors
.
activeBlue
,
supportedLocales:
widget
.
supportedLocales
,
locale:
widget
.
locale
,
showPerformanceOverlay:
widget
.
showPerformanceOverlay
,
localizationsDelegates:
_localizationsDelegates
,
checkerboardRasterCacheImages:
widget
.
checkerboardRasterCacheImages
,
localeResolutionCallback:
widget
.
localeResolutionCallback
,
checkerboardOffscreenLayers:
widget
.
checkerboardOffscreenLayers
,
localeListResolutionCallback:
widget
.
localeListResolutionCallback
,
showSemanticsDebugger:
widget
.
showSemanticsDebugger
,
supportedLocales:
widget
.
supportedLocales
,
debugShowCheckedModeBanner:
widget
.
debugShowCheckedModeBanner
,
showPerformanceOverlay:
widget
.
showPerformanceOverlay
,
inspectorSelectButtonBuilder:
(
BuildContext
context
,
VoidCallback
onPressed
)
{
checkerboardRasterCacheImages:
widget
.
checkerboardRasterCacheImages
,
return
CupertinoButton
.
filled
(
checkerboardOffscreenLayers:
widget
.
checkerboardOffscreenLayers
,
child:
const
Icon
(
showSemanticsDebugger:
widget
.
showSemanticsDebugger
,
CupertinoIcons
.
search
,
debugShowCheckedModeBanner:
widget
.
debugShowCheckedModeBanner
,
size:
28.0
,
inspectorSelectButtonBuilder:
(
BuildContext
context
,
VoidCallback
onPressed
)
{
color:
CupertinoColors
.
white
,
return
CupertinoButton
.
filled
(
),
child:
const
Icon
(
padding:
EdgeInsets
.
zero
,
CupertinoIcons
.
search
,
onPressed:
onPressed
,
size:
28.0
,
);
color:
CupertinoColors
.
white
,
},
),
padding:
EdgeInsets
.
zero
,
onPressed:
onPressed
,
);
},
),
),
),
),
),
),
);
);
...
...
packages/flutter/lib/src/cupertino/colors.dart
View file @
a671b283
This diff is collapsed.
Click to expand it.
packages/flutter/lib/src/cupertino/interface_level.dart
0 → 100644
View file @
a671b283
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'../widgets/framework.dart'
;
/// Indicates the visual level for a piece of content. Equivalent to `UIUserInterfaceLevel`
/// from `UIKit`.
///
/// See also:
///
/// * `UIUserInterfaceLevel`, the UIKit equivalent: https://developer.apple.com/documentation/uikit/uiuserinterfacelevel.
enum
CupertinoUserInterfaceLevelData
{
/// The level for your window's main content.
base
,
/// The level for content visually above [base].
elevated
,
}
/// Establishes a subtree in which [CupertinoUserInterfaceLevel.of] resolves to
/// the given data.
///
/// Querying the current elevation status using [CupertinoUserInterfaceLevel.of]
/// will cause your widget to rebuild automatically whenever the [CupertinoUserInterfaceLevelData]
/// changes.
///
/// If no [CupertinoUserInterfaceLevel] is in scope then the [CupertinoUserInterfaceLevel.of]
/// method will throw an exception, unless the `nullOk` argument is set to true,
/// in which case it returns null.
///
/// See also:
///
/// * [CupertinoUserInterfaceLevelData], specifies the visual level for the content
/// in the subtree [CupertinoUserInterfaceLevel] established.
class
CupertinoUserInterfaceLevel
extends
InheritedWidget
{
/// Creates a [CupertinoUserInterfaceLevel] to change descendant Cupertino widget's
/// visual level.
const
CupertinoUserInterfaceLevel
({
Key
key
,
@required
CupertinoUserInterfaceLevelData
data
,
Widget
child
,
})
:
assert
(
data
!=
null
),
_data
=
data
,
super
(
key:
key
,
child:
child
);
final
CupertinoUserInterfaceLevelData
_data
;
@override
bool
updateShouldNotify
(
CupertinoUserInterfaceLevel
oldWidget
)
=>
oldWidget
.
_data
!=
_data
;
/// The data from the closest instance of this class that encloses the given
/// context.
///
/// You can use this function to query the user interface elevation level within
/// the given [BuildContext]. When that information changes, your widget will
/// be scheduled to be rebuilt, keeping your widget up-to-date.
static
CupertinoUserInterfaceLevelData
of
(
BuildContext
context
,
{
bool
nullOk
=
false
})
{
assert
(
context
!=
null
);
assert
(
nullOk
!=
null
);
final
CupertinoUserInterfaceLevel
query
=
context
.
inheritFromWidgetOfExactType
(
CupertinoUserInterfaceLevel
);
if
(
query
!=
null
)
return
query
.
_data
;
if
(
nullOk
)
return
null
;
throw
FlutterError
(
'CupertinoUserInterfaceLevel.of() called with a context that does not contain a CupertinoUserInterfaceLevel.
\n
'
'No CupertinoUserInterfaceLevel ancestor could be found starting from the context that was passed '
'to CupertinoUserInterfaceLevel.of(). This can happen because you do not have a WidgetsApp or '
'MaterialApp widget (those widgets introduce a CupertinoUserInterfaceLevel), or it can happen '
'if the context you use comes from a widget above those widgets.
\n
'
'The context used was:
\n
'
'
$context
'
);
}
}
packages/flutter/lib/src/cupertino/slider.dart
View file @
a671b283
...
@@ -9,6 +9,7 @@ import 'package:flutter/gestures.dart';
...
@@ -9,6 +9,7 @@ import 'package:flutter/gestures.dart';
import
'package:flutter/rendering.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter/widgets.dart'
;
import
'colors.dart'
;
import
'theme.dart'
;
import
'theme.dart'
;
import
'thumb_painter.dart'
;
import
'thumb_painter.dart'
;
...
@@ -228,7 +229,10 @@ class _CupertinoSliderState extends State<CupertinoSlider> with TickerProviderSt
...
@@ -228,7 +229,10 @@ class _CupertinoSliderState extends State<CupertinoSlider> with TickerProviderSt
return
_CupertinoSliderRenderObjectWidget
(
return
_CupertinoSliderRenderObjectWidget
(
value:
(
widget
.
value
-
widget
.
min
)
/
(
widget
.
max
-
widget
.
min
),
value:
(
widget
.
value
-
widget
.
min
)
/
(
widget
.
max
-
widget
.
min
),
divisions:
widget
.
divisions
,
divisions:
widget
.
divisions
,
activeColor:
widget
.
activeColor
??
CupertinoTheme
.
of
(
context
).
primaryColor
,
activeColor:
CupertinoDynamicColor
.
resolve
(
widget
.
activeColor
??
CupertinoTheme
.
of
(
context
).
primaryColor
,
context
),
onChanged:
widget
.
onChanged
!=
null
?
_handleChanged
:
null
,
onChanged:
widget
.
onChanged
!=
null
?
_handleChanged
:
null
,
onChangeStart:
widget
.
onChangeStart
!=
null
?
_handleDragStart
:
null
,
onChangeStart:
widget
.
onChangeStart
!=
null
?
_handleDragStart
:
null
,
onChangeEnd:
widget
.
onChangeEnd
!=
null
?
_handleDragEnd
:
null
,
onChangeEnd:
widget
.
onChangeEnd
!=
null
?
_handleDragEnd
:
null
,
...
@@ -257,12 +261,14 @@ class _CupertinoSliderRenderObjectWidget extends LeafRenderObjectWidget {
...
@@ -257,12 +261,14 @@ class _CupertinoSliderRenderObjectWidget extends LeafRenderObjectWidget {
final
ValueChanged
<
double
>
onChangeEnd
;
final
ValueChanged
<
double
>
onChangeEnd
;
final
TickerProvider
vsync
;
final
TickerProvider
vsync
;
@override
@override
_RenderCupertinoSlider
createRenderObject
(
BuildContext
context
)
{
_RenderCupertinoSlider
createRenderObject
(
BuildContext
context
)
{
return
_RenderCupertinoSlider
(
return
_RenderCupertinoSlider
(
value:
value
,
value:
value
,
divisions:
divisions
,
divisions:
divisions
,
activeColor:
activeColor
,
activeColor:
activeColor
,
trackColor:
CupertinoDynamicColor
.
resolve
(
CupertinoSystemColors
.
of
(
context
).
systemFill
,
context
),
onChanged:
onChanged
,
onChanged:
onChanged
,
onChangeStart:
onChangeStart
,
onChangeStart:
onChangeStart
,
onChangeEnd:
onChangeEnd
,
onChangeEnd:
onChangeEnd
,
...
@@ -277,6 +283,7 @@ class _CupertinoSliderRenderObjectWidget extends LeafRenderObjectWidget {
...
@@ -277,6 +283,7 @@ class _CupertinoSliderRenderObjectWidget extends LeafRenderObjectWidget {
..
value
=
value
..
value
=
value
..
divisions
=
divisions
..
divisions
=
divisions
..
activeColor
=
activeColor
..
activeColor
=
activeColor
..
trackColor
=
CupertinoDynamicColor
.
resolve
(
CupertinoSystemColors
.
of
(
context
).
systemFill
,
context
)
..
onChanged
=
onChanged
..
onChanged
=
onChanged
..
onChangeStart
=
onChangeStart
..
onChangeStart
=
onChangeStart
..
onChangeEnd
=
onChangeEnd
..
onChangeEnd
=
onChangeEnd
...
@@ -287,7 +294,6 @@ class _CupertinoSliderRenderObjectWidget extends LeafRenderObjectWidget {
...
@@ -287,7 +294,6 @@ class _CupertinoSliderRenderObjectWidget extends LeafRenderObjectWidget {
}
}
const
double
_kPadding
=
8.0
;
const
double
_kPadding
=
8.0
;
const
Color
_kTrackColor
=
Color
(
0xFFB5B5B5
);
const
double
_kSliderHeight
=
2.0
*
(
CupertinoThumbPainter
.
radius
+
_kPadding
);
const
double
_kSliderHeight
=
2.0
*
(
CupertinoThumbPainter
.
radius
+
_kPadding
);
const
double
_kSliderWidth
=
176.0
;
// Matches Material Design slider.
const
double
_kSliderWidth
=
176.0
;
// Matches Material Design slider.
const
Duration
_kDiscreteTransitionDuration
=
Duration
(
milliseconds:
500
);
const
Duration
_kDiscreteTransitionDuration
=
Duration
(
milliseconds:
500
);
...
@@ -299,6 +305,7 @@ class _RenderCupertinoSlider extends RenderConstrainedBox {
...
@@ -299,6 +305,7 @@ class _RenderCupertinoSlider extends RenderConstrainedBox {
@required
double
value
,
@required
double
value
,
int
divisions
,
int
divisions
,
Color
activeColor
,
Color
activeColor
,
Color
trackColor
,
ValueChanged
<
double
>
onChanged
,
ValueChanged
<
double
>
onChanged
,
this
.
onChangeStart
,
this
.
onChangeStart
,
this
.
onChangeEnd
,
this
.
onChangeEnd
,
...
@@ -309,6 +316,7 @@ class _RenderCupertinoSlider extends RenderConstrainedBox {
...
@@ -309,6 +316,7 @@ class _RenderCupertinoSlider extends RenderConstrainedBox {
_value
=
value
,
_value
=
value
,
_divisions
=
divisions
,
_divisions
=
divisions
,
_activeColor
=
activeColor
,
_activeColor
=
activeColor
,
_trackColor
=
trackColor
,
_onChanged
=
onChanged
,
_onChanged
=
onChanged
,
_textDirection
=
textDirection
,
_textDirection
=
textDirection
,
super
(
additionalConstraints:
const
BoxConstraints
.
tightFor
(
width:
_kSliderWidth
,
height:
_kSliderHeight
))
{
super
(
additionalConstraints:
const
BoxConstraints
.
tightFor
(
width:
_kSliderWidth
,
height:
_kSliderHeight
))
{
...
@@ -355,6 +363,15 @@ class _RenderCupertinoSlider extends RenderConstrainedBox {
...
@@ -355,6 +363,15 @@ class _RenderCupertinoSlider extends RenderConstrainedBox {
markNeedsPaint
();
markNeedsPaint
();
}
}
Color
get
trackColor
=>
_trackColor
;
Color
_trackColor
;
set
trackColor
(
Color
value
)
{
if
(
value
==
_trackColor
)
return
;
_trackColor
=
value
;
markNeedsPaint
();
}
ValueChanged
<
double
>
get
onChanged
=>
_onChanged
;
ValueChanged
<
double
>
get
onChanged
=>
_onChanged
;
ValueChanged
<
double
>
_onChanged
;
ValueChanged
<
double
>
_onChanged
;
set
onChanged
(
ValueChanged
<
double
>
value
)
{
set
onChanged
(
ValueChanged
<
double
>
value
)
{
...
@@ -468,11 +485,11 @@ class _RenderCupertinoSlider extends RenderConstrainedBox {
...
@@ -468,11 +485,11 @@ class _RenderCupertinoSlider extends RenderConstrainedBox {
case
TextDirection
.
rtl
:
case
TextDirection
.
rtl
:
visualPosition
=
1.0
-
_position
.
value
;
visualPosition
=
1.0
-
_position
.
value
;
leftColor
=
_activeColor
;
leftColor
=
_activeColor
;
rightColor
=
_kT
rackColor
;
rightColor
=
t
rackColor
;
break
;
break
;
case
TextDirection
.
ltr
:
case
TextDirection
.
ltr
:
visualPosition
=
_position
.
value
;
visualPosition
=
_position
.
value
;
leftColor
=
_kT
rackColor
;
leftColor
=
t
rackColor
;
rightColor
=
_activeColor
;
rightColor
=
_activeColor
;
break
;
break
;
}
}
...
...
packages/flutter/lib/src/cupertino/text_theme.dart
View file @
a671b283
...
@@ -213,6 +213,32 @@ class CupertinoTextThemeData extends Diagnosticable {
...
@@ -213,6 +213,32 @@ class CupertinoTextThemeData extends Diagnosticable {
(
_isLight
?
_kDefaultDateTimePickerLightTextStyle
:
_kDefaultDateTimePickerDarkTextStyle
);
(
_isLight
?
_kDefaultDateTimePickerLightTextStyle
:
_kDefaultDateTimePickerDarkTextStyle
);
}
}
/// Returns a copy of the current [CupertinoTextThemeData] with all the colors
/// resolved against the given [BuildContext].
CupertinoTextThemeData
resolveFrom
(
BuildContext
context
,
{
bool
nullOk
=
false
})
{
Color
convertColor
(
Color
color
)
=>
color
==
null
?
null
:
CupertinoDynamicColor
.
resolve
(
color
,
context
,
nullOk:
nullOk
);
TextStyle
resolveTextStyle
(
TextStyle
textStyle
)
{
return
textStyle
?.
copyWith
(
color:
convertColor
(
textStyle
.
color
),
backgroundColor:
convertColor
(
textStyle
.
backgroundColor
),
decorationColor:
convertColor
(
textStyle
.
decorationColor
),
);
}
return
copyWith
(
primaryColor:
convertColor
(
_primaryColor
),
textStyle:
resolveTextStyle
(
_textStyle
),
actionTextStyle:
resolveTextStyle
(
_actionTextStyle
),
tabLabelTextStyle:
resolveTextStyle
(
_tabLabelTextStyle
),
navTitleTextStyle
:
resolveTextStyle
(
_navTitleTextStyle
),
navLargeTitleTextStyle:
resolveTextStyle
(
_navLargeTitleTextStyle
),
navActionTextStyle:
resolveTextStyle
(
_navActionTextStyle
),
pickerTextStyle:
resolveTextStyle
(
_pickerTextStyle
),
dateTimePickerTextStyle:
resolveTextStyle
(
_dateTimePickerTextStyle
),
);
}
/// Returns a copy of the current [CupertinoTextThemeData] instance with
/// Returns a copy of the current [CupertinoTextThemeData] instance with
/// specified overrides.
/// specified overrides.
CupertinoTextThemeData
copyWith
({
CupertinoTextThemeData
copyWith
({
...
...
packages/flutter/lib/src/cupertino/theme.dart
View file @
a671b283
...
@@ -54,7 +54,20 @@ class CupertinoTheme extends StatelessWidget {
...
@@ -54,7 +54,20 @@ class CupertinoTheme extends StatelessWidget {
/// exist in the ancestry tree.
/// exist in the ancestry tree.
static
CupertinoThemeData
of
(
BuildContext
context
)
{
static
CupertinoThemeData
of
(
BuildContext
context
)
{
final
_InheritedCupertinoTheme
inheritedTheme
=
context
.
inheritFromWidgetOfExactType
(
_InheritedCupertinoTheme
);
final
_InheritedCupertinoTheme
inheritedTheme
=
context
.
inheritFromWidgetOfExactType
(
_InheritedCupertinoTheme
);
return
inheritedTheme
?.
theme
?.
data
??
const
CupertinoThemeData
();
return
(
inheritedTheme
?.
theme
?.
data
??
const
CupertinoThemeData
()).
resolveFrom
(
context
,
nullOk:
true
);
}
/// Retrieve the [Brightness] value from the closest ancestor [CupertinoTheme]
/// widget.
///
/// If no ancestral [CupertinoTheme] widget with explicit brightness value could
/// be found, the method will resort to the closest ancestor [MediaQuery] widget.
///
/// Throws an exception if no such [CupertinoTheme] or [MediaQuery] widgets exist
/// in the ancestry tree, unless [nullOk] is set to true.
static
Brightness
brightnessOf
(
BuildContext
context
,
{
bool
nullOk
=
false
})
{
final
_InheritedCupertinoTheme
inheritedTheme
=
context
.
inheritFromWidgetOfExactType
(
_InheritedCupertinoTheme
);
return
inheritedTheme
?.
theme
?.
data
?.
_brightness
??
MediaQuery
.
of
(
context
,
nullOk:
nullOk
)?.
platformBrightness
;
}
}
/// The widget below this widget in the tree.
/// The widget below this widget in the tree.
...
@@ -229,6 +242,23 @@ class CupertinoThemeData extends Diagnosticable {
...
@@ -229,6 +242,23 @@ class CupertinoThemeData extends Diagnosticable {
);
);
}
}
/// Return a new `CupertinoThemeData` whose colors are from this `CupertinoThemeData`,
/// but resolved aginst the given [BuildContext].
///
/// It will be called in [CupertinoTheme.of].
@protected
CupertinoThemeData
resolveFrom
(
BuildContext
context
,
{
bool
nullOk
=
false
})
{
Color
convertColor
(
Color
color
)
=>
color
==
null
?
null
:
CupertinoDynamicColor
.
resolve
(
color
,
context
,
nullOk:
nullOk
);
return
copyWith
(
primaryColor:
convertColor
(
primaryColor
),
primaryContrastingColor:
convertColor
(
primaryContrastingColor
),
textTheme:
textTheme
?.
resolveFrom
(
context
,
nullOk:
nullOk
),
barBackgroundColor:
convertColor
(
barBackgroundColor
),
scaffoldBackgroundColor:
convertColor
(
scaffoldBackgroundColor
),
);
}
/// Create a copy of [CupertinoThemeData] with specified attributes overridden.
/// Create a copy of [CupertinoThemeData] with specified attributes overridden.
///
///
/// Only the current instance's specified attributes are copied instead of
/// Only the current instance's specified attributes are copied instead of
...
@@ -296,4 +326,39 @@ class _NoDefaultCupertinoThemeData extends CupertinoThemeData {
...
@@ -296,4 +326,39 @@ class _NoDefaultCupertinoThemeData extends CupertinoThemeData {
final
Color
barBackgroundColor
;
final
Color
barBackgroundColor
;
@override
@override
final
Color
scaffoldBackgroundColor
;
final
Color
scaffoldBackgroundColor
;
@override
_NoDefaultCupertinoThemeData
resolveFrom
(
BuildContext
context
,
{
bool
nullOk
=
false
})
{
Color
convertColor
(
Color
color
)
=>
color
==
null
?
null
:
CupertinoDynamicColor
.
resolve
(
color
,
context
,
nullOk:
nullOk
);
return
_NoDefaultCupertinoThemeData
(
brightness
,
convertColor
(
primaryColor
),
convertColor
(
primaryContrastingColor
),
textTheme
?.
resolveFrom
(
context
,
nullOk:
nullOk
),
convertColor
(
barBackgroundColor
),
convertColor
(
scaffoldBackgroundColor
),
);
}
@override
CupertinoThemeData
copyWith
({
Brightness
brightness
,
Color
primaryColor
,
Color
primaryContrastingColor
,
CupertinoTextThemeData
textTheme
,
Color
barBackgroundColor
,
Color
scaffoldBackgroundColor
})
{
return
_NoDefaultCupertinoThemeData
(
brightness
??
this
.
brightness
,
primaryColor
??
this
.
primaryColor
,
primaryContrastingColor
??
this
.
primaryContrastingColor
,
textTheme
??
this
.
textTheme
,
barBackgroundColor
??
this
.
barBackgroundColor
,
scaffoldBackgroundColor
??
this
.
scaffoldBackgroundColor
,
);
}
}
}
packages/flutter/lib/src/material/theme_data.dart
View file @
a671b283
...
@@ -1416,34 +1416,43 @@ class MaterialBasedCupertinoThemeData extends CupertinoThemeData {
...
@@ -1416,34 +1416,43 @@ class MaterialBasedCupertinoThemeData extends CupertinoThemeData {
///
///
/// The [materialTheme] parameter must not be null.
/// The [materialTheme] parameter must not be null.
MaterialBasedCupertinoThemeData
({
MaterialBasedCupertinoThemeData
({
@required
ThemeData
materialTheme
,
@required
ThemeData
materialTheme
,
})
:
assert
(
materialTheme
!=
null
),
})
:
this
.
_
(
_materialTheme
=
materialTheme
,
materialTheme
,
// Pass all values to the superclass so Material-agnostic properties
(
materialTheme
.
cupertinoOverrideTheme
??
const
CupertinoThemeData
()).
noDefault
(),
// like barBackgroundColor can still behave like a normal
);
// CupertinoThemeData.
super
.
raw
(
MaterialBasedCupertinoThemeData
.
_
(
materialTheme
.
cupertinoOverrideTheme
?.
brightness
,
this
.
_materialTheme
,
materialTheme
.
cupertinoOverrideTheme
?.
primaryColor
,
this
.
_cupertinoOverrideTheme
,
materialTheme
.
cupertinoOverrideTheme
?.
primaryContrastingColor
,
)
:
assert
(
_materialTheme
!=
null
),
materialTheme
.
cupertinoOverrideTheme
?.
textTheme
,
assert
(
_cupertinoOverrideTheme
!=
null
),
materialTheme
.
cupertinoOverrideTheme
?.
barBackgroundColor
,
// Pass all values to the superclass so Material-agnostic properties
materialTheme
.
cupertinoOverrideTheme
?.
scaffoldBackgroundColor
,
// like barBackgroundColor can still behave like a normal
);
// CupertinoThemeData.
super
.
raw
(
_cupertinoOverrideTheme
.
brightness
,
_cupertinoOverrideTheme
.
primaryColor
,
_cupertinoOverrideTheme
.
primaryContrastingColor
,
_cupertinoOverrideTheme
.
textTheme
,
_cupertinoOverrideTheme
.
barBackgroundColor
,
_cupertinoOverrideTheme
.
scaffoldBackgroundColor
,
);
final
ThemeData
_materialTheme
;
final
ThemeData
_materialTheme
;
final
CupertinoThemeData
_cupertinoOverrideTheme
;
@override
@override
Brightness
get
brightness
=>
_
materialTheme
.
cupertinoOverrideTheme
?
.
brightness
??
_materialTheme
.
brightness
;
Brightness
get
brightness
=>
_
cupertinoOverrideTheme
.
brightness
??
_materialTheme
.
brightness
;
@override
@override
Color
get
primaryColor
=>
_
materialTheme
.
cupertinoOverrideTheme
?
.
primaryColor
??
_materialTheme
.
colorScheme
.
primary
;
Color
get
primaryColor
=>
_
cupertinoOverrideTheme
.
primaryColor
??
_materialTheme
.
colorScheme
.
primary
;
@override
@override
Color
get
primaryContrastingColor
=>
_
materialTheme
.
cupertinoOverrideTheme
?
.
primaryContrastingColor
??
_materialTheme
.
colorScheme
.
onPrimary
;
Color
get
primaryContrastingColor
=>
_
cupertinoOverrideTheme
.
primaryContrastingColor
??
_materialTheme
.
colorScheme
.
onPrimary
;
@override
@override
Color
get
scaffoldBackgroundColor
=>
_
materialTheme
.
cupertinoOverrideTheme
?
.
scaffoldBackgroundColor
??
_materialTheme
.
scaffoldBackgroundColor
;
Color
get
scaffoldBackgroundColor
=>
_
cupertinoOverrideTheme
.
scaffoldBackgroundColor
??
_materialTheme
.
scaffoldBackgroundColor
;
/// Copies the [ThemeData]'s `cupertinoOverrideTheme`.
/// Copies the [ThemeData]'s `cupertinoOverrideTheme`.
///
///
...
@@ -1457,7 +1466,7 @@ class MaterialBasedCupertinoThemeData extends CupertinoThemeData {
...
@@ -1457,7 +1466,7 @@ class MaterialBasedCupertinoThemeData extends CupertinoThemeData {
/// new Material [Theme] and use `copyWith` on the Material [ThemeData]
/// new Material [Theme] and use `copyWith` on the Material [ThemeData]
/// instead.
/// instead.
@override
@override
CupertinoThemeData
copyWith
({
MaterialBased
CupertinoThemeData
copyWith
({
Brightness
brightness
,
Brightness
brightness
,
Color
primaryColor
,
Color
primaryColor
,
Color
primaryContrastingColor
,
Color
primaryContrastingColor
,
...
@@ -1465,20 +1474,26 @@ class MaterialBasedCupertinoThemeData extends CupertinoThemeData {
...
@@ -1465,20 +1474,26 @@ class MaterialBasedCupertinoThemeData extends CupertinoThemeData {
Color
barBackgroundColor
,
Color
barBackgroundColor
,
Color
scaffoldBackgroundColor
,
Color
scaffoldBackgroundColor
,
})
{
})
{
return
_materialTheme
.
cupertinoOverrideTheme
?.
copyWith
(
return
MaterialBasedCupertinoThemeData
.
_
(
brightness:
brightness
,
_materialTheme
,
primaryColor:
primaryColor
,
_cupertinoOverrideTheme
.
copyWith
(
primaryContrastingColor:
primaryContrastingColor
,
brightness:
brightness
,
textTheme:
textTheme
,
primaryColor:
primaryColor
,
barBackgroundColor:
barBackgroundColor
,
primaryContrastingColor:
primaryContrastingColor
,
scaffoldBackgroundColor:
scaffoldBackgroundColor
,
textTheme:
textTheme
,
)
??
CupertinoThemeData
(
barBackgroundColor:
barBackgroundColor
,
brightness:
brightness
,
scaffoldBackgroundColor:
scaffoldBackgroundColor
,
primaryColor:
primaryColor
,
),
primaryContrastingColor:
primaryContrastingColor
,
);
textTheme:
textTheme
,
}
barBackgroundColor:
barBackgroundColor
,
scaffoldBackgroundColor:
scaffoldBackgroundColor
,
@override
CupertinoThemeData
resolveFrom
(
BuildContext
context
,
{
bool
nullOk
=
false
})
{
// Only the cupertino override theme part will be resolved.
// If the color comes from the material theme it's not resolved.
return
MaterialBasedCupertinoThemeData
.
_
(
_materialTheme
,
_cupertinoOverrideTheme
.
resolveFrom
(
context
,
nullOk:
nullOk
),
);
);
}
}
}
}
...
...
packages/flutter/lib/src/widgets/media_query.dart
View file @
a671b283
...
@@ -98,6 +98,7 @@ class MediaQueryData {
...
@@ -98,6 +98,7 @@ class MediaQueryData {
this
.
alwaysUse24HourFormat
=
false
,
this
.
alwaysUse24HourFormat
=
false
,
this
.
accessibleNavigation
=
false
,
this
.
accessibleNavigation
=
false
,
this
.
invertColors
=
false
,
this
.
invertColors
=
false
,
this
.
highContrast
=
false
,
this
.
disableAnimations
=
false
,
this
.
disableAnimations
=
false
,
this
.
boldText
=
false
,
this
.
boldText
=
false
,
});
});
...
@@ -121,6 +122,7 @@ class MediaQueryData {
...
@@ -121,6 +122,7 @@ class MediaQueryData {
invertColors
=
window
.
accessibilityFeatures
.
invertColors
,
invertColors
=
window
.
accessibilityFeatures
.
invertColors
,
disableAnimations
=
window
.
accessibilityFeatures
.
disableAnimations
,
disableAnimations
=
window
.
accessibilityFeatures
.
disableAnimations
,
boldText
=
window
.
accessibilityFeatures
.
boldText
,
boldText
=
window
.
accessibilityFeatures
.
boldText
,
highContrast
=
false
,
alwaysUse24HourFormat
=
window
.
alwaysUse24HourFormat
;
alwaysUse24HourFormat
=
window
.
alwaysUse24HourFormat
;
/// The size of the media in logical pixels (e.g, the size of the screen).
/// The size of the media in logical pixels (e.g, the size of the screen).
...
@@ -259,6 +261,13 @@ class MediaQueryData {
...
@@ -259,6 +261,13 @@ class MediaQueryData {
/// * [Window.AccessibilityFeatures], where the setting originates.
/// * [Window.AccessibilityFeatures], where the setting originates.
final
bool
invertColors
;
final
bool
invertColors
;
/// Whether the user requested a high contrast between foreground and background
/// content on iOS, via Settings -> Accessibility -> Increase Contrast.
///
/// This flag is currently only updated on iOS devices that are running iOS 13
/// or above.
final
bool
highContrast
;
/// Whether the platform is requesting that animations be disabled or reduced
/// Whether the platform is requesting that animations be disabled or reduced
/// as much as possible.
/// as much as possible.
///
///
...
@@ -293,6 +302,7 @@ class MediaQueryData {
...
@@ -293,6 +302,7 @@ class MediaQueryData {
EdgeInsets
viewInsets
,
EdgeInsets
viewInsets
,
double
physicalDepth
,
double
physicalDepth
,
bool
alwaysUse24HourFormat
,
bool
alwaysUse24HourFormat
,
bool
highContrast
,
bool
disableAnimations
,
bool
disableAnimations
,
bool
invertColors
,
bool
invertColors
,
bool
accessibleNavigation
,
bool
accessibleNavigation
,
...
@@ -309,6 +319,7 @@ class MediaQueryData {
...
@@ -309,6 +319,7 @@ class MediaQueryData {
physicalDepth:
physicalDepth
??
this
.
physicalDepth
,
physicalDepth:
physicalDepth
??
this
.
physicalDepth
,
alwaysUse24HourFormat:
alwaysUse24HourFormat
??
this
.
alwaysUse24HourFormat
,
alwaysUse24HourFormat:
alwaysUse24HourFormat
??
this
.
alwaysUse24HourFormat
,
invertColors:
invertColors
??
this
.
invertColors
,
invertColors:
invertColors
??
this
.
invertColors
,
highContrast:
highContrast
??
this
.
highContrast
,
disableAnimations:
disableAnimations
??
this
.
disableAnimations
,
disableAnimations:
disableAnimations
??
this
.
disableAnimations
,
accessibleNavigation:
accessibleNavigation
??
this
.
accessibleNavigation
,
accessibleNavigation:
accessibleNavigation
??
this
.
accessibleNavigation
,
boldText:
boldText
??
this
.
boldText
,
boldText:
boldText
??
this
.
boldText
,
...
@@ -357,6 +368,7 @@ class MediaQueryData {
...
@@ -357,6 +368,7 @@ class MediaQueryData {
),
),
viewInsets:
viewInsets
,
viewInsets:
viewInsets
,
alwaysUse24HourFormat:
alwaysUse24HourFormat
,
alwaysUse24HourFormat:
alwaysUse24HourFormat
,
highContrast:
highContrast
,
disableAnimations:
disableAnimations
,
disableAnimations:
disableAnimations
,
invertColors:
invertColors
,
invertColors:
invertColors
,
accessibleNavigation:
accessibleNavigation
,
accessibleNavigation:
accessibleNavigation
,
...
@@ -404,6 +416,7 @@ class MediaQueryData {
...
@@ -404,6 +416,7 @@ class MediaQueryData {
bottom:
removeBottom
?
0.0
:
null
,
bottom:
removeBottom
?
0.0
:
null
,
),
),
alwaysUse24HourFormat:
alwaysUse24HourFormat
,
alwaysUse24HourFormat:
alwaysUse24HourFormat
,
highContrast:
highContrast
,
disableAnimations:
disableAnimations
,
disableAnimations:
disableAnimations
,
invertColors:
invertColors
,
invertColors:
invertColors
,
accessibleNavigation:
accessibleNavigation
,
accessibleNavigation:
accessibleNavigation
,
...
@@ -451,6 +464,7 @@ class MediaQueryData {
...
@@ -451,6 +464,7 @@ class MediaQueryData {
bottom:
removeBottom
?
0.0
:
null
,
bottom:
removeBottom
?
0.0
:
null
,
),
),
alwaysUse24HourFormat:
alwaysUse24HourFormat
,
alwaysUse24HourFormat:
alwaysUse24HourFormat
,
highContrast:
highContrast
,
disableAnimations:
disableAnimations
,
disableAnimations:
disableAnimations
,
invertColors:
invertColors
,
invertColors:
invertColors
,
accessibleNavigation:
accessibleNavigation
,
accessibleNavigation:
accessibleNavigation
,
...
@@ -472,6 +486,7 @@ class MediaQueryData {
...
@@ -472,6 +486,7 @@ class MediaQueryData {
&&
typedOther
.
viewInsets
==
viewInsets
&&
typedOther
.
viewInsets
==
viewInsets
&&
typedOther
.
physicalDepth
==
physicalDepth
&&
typedOther
.
physicalDepth
==
physicalDepth
&&
typedOther
.
alwaysUse24HourFormat
==
alwaysUse24HourFormat
&&
typedOther
.
alwaysUse24HourFormat
==
alwaysUse24HourFormat
&&
typedOther
.
highContrast
==
highContrast
&&
typedOther
.
disableAnimations
==
disableAnimations
&&
typedOther
.
disableAnimations
==
disableAnimations
&&
typedOther
.
invertColors
==
invertColors
&&
typedOther
.
invertColors
==
invertColors
&&
typedOther
.
accessibleNavigation
==
accessibleNavigation
&&
typedOther
.
accessibleNavigation
==
accessibleNavigation
...
@@ -490,6 +505,7 @@ class MediaQueryData {
...
@@ -490,6 +505,7 @@ class MediaQueryData {
viewInsets
,
viewInsets
,
physicalDepth
,
physicalDepth
,
alwaysUse24HourFormat
,
alwaysUse24HourFormat
,
highContrast
,
disableAnimations
,
disableAnimations
,
invertColors
,
invertColors
,
accessibleNavigation
,
accessibleNavigation
,
...
@@ -510,6 +526,7 @@ class MediaQueryData {
...
@@ -510,6 +526,7 @@ class MediaQueryData {
'physicalDepth:
$physicalDepth
, '
'physicalDepth:
$physicalDepth
, '
'alwaysUse24HourFormat:
$alwaysUse24HourFormat
, '
'alwaysUse24HourFormat:
$alwaysUse24HourFormat
, '
'accessibleNavigation:
$accessibleNavigation
, '
'accessibleNavigation:
$accessibleNavigation
, '
'highContrast:
$highContrast
,'
'disableAnimations:
$disableAnimations
, '
'disableAnimations:
$disableAnimations
, '
'invertColors:
$invertColors
, '
'invertColors:
$invertColors
, '
'boldText:
$boldText
'
'boldText:
$boldText
'
...
...
packages/flutter/test/cupertino/colors_test.dart
0 → 100644
View file @
a671b283
This diff is collapsed.
Click to expand it.
packages/flutter/test/cupertino/slider_test.dart
View file @
a671b283
This diff is collapsed.
Click to expand it.
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