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
4cae568f
Commit
4cae568f
authored
Aug 17, 2015
by
Collin Jackson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move inheritedOfType from Component to Widget so that Switch can use it
parent
74a14d2a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
44 deletions
+46
-44
default_text_style.dart
packages/flutter/lib/widgets/default_text_style.dart
+2
-2
framework.dart
packages/flutter/lib/widgets/framework.dart
+29
-14
switch.dart
packages/flutter/lib/widgets/switch.dart
+13
-26
theme.dart
packages/flutter/lib/widgets/theme.dart
+2
-2
No files found.
packages/flutter/lib/widgets/default_text_style.dart
View file @
4cae568f
...
...
@@ -19,8 +19,8 @@ class DefaultTextStyle extends Inherited {
final
TextStyle
style
;
static
TextStyle
of
(
Component
componen
t
)
{
DefaultTextStyle
result
=
componen
t
.
inheritedOfType
(
DefaultTextStyle
);
static
TextStyle
of
(
Widget
widge
t
)
{
DefaultTextStyle
result
=
widge
t
.
inheritedOfType
(
DefaultTextStyle
);
return
result
==
null
?
null
:
result
.
style
;
}
...
...
packages/flutter/lib/widgets/framework.dart
View file @
4cae568f
...
...
@@ -272,6 +272,27 @@ abstract class Widget {
return
ancestor
;
}
Set
<
Type
>
_dependencies
;
Inherited
inheritedOfType
(
Type
targetType
)
{
if
(
_dependencies
==
null
)
_dependencies
=
new
Set
<
Type
>();
_dependencies
.
add
(
targetType
);
Widget
ancestor
=
parent
;
while
(
ancestor
!=
null
&&
ancestor
.
runtimeType
!=
targetType
)
ancestor
=
ancestor
.
parent
;
return
ancestor
;
}
void
dependenciesChanged
()
{
// This is called if you've use inheritedOfType and the Inherited
// ancestor you were provided was changed. For a widget to use Inherited
// it needs an implementation of dependenciesChanged. If your widget extends
// Component or RenderObjectWrapper this is provided for you automatically.
// If you aren't able to extend one of those classes, you need to
// provide your own implementation of dependenciesChanged.
assert
(
false
);
}
void
remove
()
{
_renderObject
=
null
;
setParent
(
null
);
...
...
@@ -453,10 +474,9 @@ abstract class Inherited extends TagNode {
void
notifyDescendants
()
{
final
Type
ourRuntimeType
=
runtimeType
;
void
notifyChildren
(
Widget
child
)
{
if
(
child
is
Component
&&
child
.
_dependencies
!=
null
&&
if
(
child
.
_dependencies
!=
null
&&
child
.
_dependencies
.
contains
(
ourRuntimeType
))
child
.
_
dependenciesChanged
();
child
.
dependenciesChanged
();
if
(
child
.
runtimeType
!=
ourRuntimeType
)
child
.
walkChildren
(
notifyChildren
);
}
...
...
@@ -608,17 +628,7 @@ abstract class Component extends Widget {
_built
.
detachRoot
();
}
Set
<
Type
>
_dependencies
;
Inherited
inheritedOfType
(
Type
targetType
)
{
if
(
_dependencies
==
null
)
_dependencies
=
new
Set
<
Type
>();
_dependencies
.
add
(
targetType
);
Widget
ancestor
=
parent
;
while
(
ancestor
!=
null
&&
ancestor
.
runtimeType
!=
targetType
)
ancestor
=
ancestor
.
parent
;
return
ancestor
;
}
void
_dependenciesChanged
()
{
void
dependenciesChanged
()
{
// called by Inherited.sync()
_scheduleBuild
();
}
...
...
@@ -937,6 +947,11 @@ abstract class RenderObjectWrapper extends Widget {
}
}
void
dependenciesChanged
()
{
// called by Inherited.sync()
syncRenderObject
(
this
);
}
void
remove
()
{
assert
(
renderObject
!=
null
);
_nodeMap
.
remove
(
renderObject
);
...
...
packages/flutter/lib/widgets/switch.dart
View file @
4cae568f
...
...
@@ -30,47 +30,34 @@ const Duration _kCheckDuration = const Duration(milliseconds: 200);
const
Size
_kSwitchSize
=
const
Size
(
_kSwitchWidth
+
2.0
,
_kSwitchHeight
+
2.0
);
const
double
_kReactionRadius
=
_kSwitchWidth
/
2.0
;
class
Switch
extends
Component
{
Switch
({
Key
key
,
this
.
value
,
this
.
onChanged
})
:
super
(
key:
key
);
final
bool
value
;
final
ValueChanged
onChanged
;
Widget
build
()
{
return
new
_SwitchWrapper
(
value:
value
,
onChanged:
onChanged
,
thumbColor:
Theme
.
of
(
this
).
accentColor
);
}
}
// This wrapper class exists only because Switch needs to be a Component in
// order to get an accent color from a Theme but Components do not know how to
// host RenderObjects.
class
_SwitchWrapper
extends
LeafRenderObjectWrapper
{
_SwitchWrapper
({
Key
key
,
this
.
value
,
this
.
onChanged
,
this
.
thumbColor
})
class
Switch
extends
LeafRenderObjectWrapper
{
Switch
({
Key
key
,
this
.
value
,
this
.
onChanged
})
:
super
(
key:
key
);
final
bool
value
;
final
ValueChanged
onChanged
;
final
Color
thumbColor
;
_RenderSwitch
get
renderObject
=>
super
.
renderObject
;
_RenderSwitch
createNode
()
=>
new
_RenderSwitch
(
value:
value
,
thumbColor:
thumbColor
,
onChanged:
onChanged
);
value:
value
,
thumbColor:
null
,
onChanged:
onChanged
);
void
syncRenderObject
(
_SwitchWrapper
old
)
{
void
syncRenderObject
(
Switch
old
)
{
super
.
syncRenderObject
(
old
);
renderObject
.
value
=
value
;
renderObject
.
onChanged
=
onChanged
;
renderObject
.
thumbColor
=
thumb
Color
;
renderObject
.
thumbColor
=
Theme
.
of
(
this
).
accent
Color
;
}
}
class
_RenderSwitch
extends
RenderToggleable
{
_RenderSwitch
(
{
bool
value
,
Color
thumbColor:
_kThumbOffColor
,
ValueChanged
onChanged
})
:
_thumbColor
=
thumbColor
,
_RenderSwitch
({
bool
value
,
Color
thumbColor:
_kThumbOffColor
,
ValueChanged
onChanged
})
:
_thumbColor
=
thumbColor
,
super
(
value:
value
,
onChanged:
onChanged
,
size:
_kSwitchSize
)
{}
Color
_thumbColor
;
...
...
packages/flutter/lib/widgets/theme.dart
View file @
4cae568f
...
...
@@ -23,8 +23,8 @@ class Theme extends Inherited {
static
final
ThemeData
_kFallbackTheme
=
new
ThemeData
.
fallback
();
static
ThemeData
of
(
Component
componen
t
)
{
Theme
theme
=
componen
t
.
inheritedOfType
(
Theme
);
static
ThemeData
of
(
Widget
widge
t
)
{
Theme
theme
=
widge
t
.
inheritedOfType
(
Theme
);
return
theme
==
null
?
_kFallbackTheme
:
theme
.
data
;
}
...
...
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