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
c130dfff
Commit
c130dfff
authored
Dec 08, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #812 from abarth/check_material
Widgets that depend on Material should assert that
parents
c0f068ce
8dc607a9
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
82 additions
and
25 deletions
+82
-25
checkbox.dart
packages/flutter/lib/src/material/checkbox.dart
+2
-0
chip.dart
packages/flutter/lib/src/material/chip.dart
+2
-0
debug.dart
packages/flutter/lib/src/material/debug.dart
+18
-0
drawer_header.dart
packages/flutter/lib/src/material/drawer_header.dart
+2
-0
dropdown.dart
packages/flutter/lib/src/material/dropdown.dart
+2
-0
ink_well.dart
packages/flutter/lib/src/material/ink_well.dart
+2
-0
input.dart
packages/flutter/lib/src/material/input.dart
+2
-0
material_button.dart
packages/flutter/lib/src/material/material_button.dart
+2
-0
radio.dart
packages/flutter/lib/src/material/radio.dart
+2
-0
slider.dart
packages/flutter/lib/src/material/slider.dart
+2
-0
switch.dart
packages/flutter/lib/src/material/switch.dart
+2
-0
binding.dart
packages/flutter/lib/src/widgets/binding.dart
+9
-2
framework.dart
packages/flutter/lib/src/widgets/framework.dart
+13
-9
input_test.dart
packages/unit/test/widget/input_test.dart
+22
-14
No files found.
packages/flutter/lib/src/material/checkbox.dart
View file @
c130dfff
...
@@ -8,6 +8,7 @@ import 'package:flutter/rendering.dart';
...
@@ -8,6 +8,7 @@ import 'package:flutter/rendering.dart';
import
'package:flutter/widgets.dart'
;
import
'package:flutter/widgets.dart'
;
import
'constants.dart'
;
import
'constants.dart'
;
import
'debug.dart'
;
import
'theme.dart'
;
import
'theme.dart'
;
import
'toggleable.dart'
;
import
'toggleable.dart'
;
...
@@ -35,6 +36,7 @@ class Checkbox extends StatelessComponent {
...
@@ -35,6 +36,7 @@ class Checkbox extends StatelessComponent {
final
ValueChanged
<
bool
>
onChanged
;
final
ValueChanged
<
bool
>
onChanged
;
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasMaterial
(
context
));
ThemeData
themeData
=
Theme
.
of
(
context
);
ThemeData
themeData
=
Theme
.
of
(
context
);
return
new
_CheckboxRenderObjectWidget
(
return
new
_CheckboxRenderObjectWidget
(
value:
value
,
value:
value
,
...
...
packages/flutter/lib/src/material/chip.dart
View file @
c130dfff
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
import
'package:flutter/widgets.dart'
;
import
'package:flutter/widgets.dart'
;
import
'colors.dart'
;
import
'colors.dart'
;
import
'debug.dart'
;
import
'icon.dart'
;
import
'icon.dart'
;
const
double
_kChipHeight
=
32.0
;
const
double
_kChipHeight
=
32.0
;
...
@@ -34,6 +35,7 @@ class Chip extends StatelessComponent {
...
@@ -34,6 +35,7 @@ class Chip extends StatelessComponent {
final
VoidCallback
onDeleted
;
final
VoidCallback
onDeleted
;
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasMaterial
(
context
));
final
bool
deletable
=
onDeleted
!=
null
;
final
bool
deletable
=
onDeleted
!=
null
;
double
leftPadding
=
12.0
;
double
leftPadding
=
12.0
;
double
rightPadding
=
12.0
;
double
rightPadding
=
12.0
;
...
...
packages/flutter/lib/src/material/debug.dart
0 → 100644
View file @
c130dfff
// Copyright 2015 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
'package:flutter/widgets.dart'
;
import
'material.dart'
;
bool
debugCheckHasMaterial
(
BuildContext
context
)
{
assert
(()
{
if
(
context
.
widget
is
Material
||
context
.
ancestorWidgetOfType
(
Material
)
!=
null
)
return
true
;
Element
element
=
context
;
debugPrint
(
'
${context.widget}
needs to be placed inside a Material widget. Ownership chain:
\n
${element.debugGetOwnershipChain(10)}
'
);
return
false
;
});
return
true
;
}
packages/flutter/lib/src/material/drawer_header.dart
View file @
c130dfff
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
import
'package:flutter/widgets.dart'
;
import
'package:flutter/widgets.dart'
;
import
'constants.dart'
;
import
'constants.dart'
;
import
'debug.dart'
;
import
'theme.dart'
;
import
'theme.dart'
;
// TODO(jackson): This class should usually render the user's
// TODO(jackson): This class should usually render the user's
...
@@ -16,6 +17,7 @@ class DrawerHeader extends StatelessComponent {
...
@@ -16,6 +17,7 @@ class DrawerHeader extends StatelessComponent {
final
Widget
child
;
final
Widget
child
;
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasMaterial
(
context
));
return
new
Container
(
return
new
Container
(
height:
kStatusBarHeight
+
kMaterialDrawerHeight
,
height:
kStatusBarHeight
+
kMaterialDrawerHeight
,
decoration:
new
BoxDecoration
(
decoration:
new
BoxDecoration
(
...
...
packages/flutter/lib/src/material/dropdown.dart
View file @
c130dfff
...
@@ -9,6 +9,7 @@ import 'package:flutter/painting.dart';
...
@@ -9,6 +9,7 @@ import 'package:flutter/painting.dart';
import
'package:flutter/rendering.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter/widgets.dart'
;
import
'debug.dart'
;
import
'icon.dart'
;
import
'icon.dart'
;
import
'ink_well.dart'
;
import
'ink_well.dart'
;
import
'shadows.dart'
;
import
'shadows.dart'
;
...
@@ -262,6 +263,7 @@ class _DropDownButtonState<T> extends State<DropDownButton<T>> {
...
@@ -262,6 +263,7 @@ class _DropDownButtonState<T> extends State<DropDownButton<T>> {
}
}
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasMaterial
(
context
));
return
new
GestureDetector
(
return
new
GestureDetector
(
onTap:
_handleTap
,
onTap:
_handleTap
,
child:
new
Container
(
child:
new
Container
(
...
...
packages/flutter/lib/src/material/ink_well.dart
View file @
c130dfff
...
@@ -6,6 +6,7 @@ import 'package:flutter/gestures.dart';
...
@@ -6,6 +6,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
'debug.dart'
;
import
'material.dart'
;
import
'material.dart'
;
import
'theme.dart'
;
import
'theme.dart'
;
...
@@ -137,6 +138,7 @@ class _InkResponseState<T extends InkResponse> extends State<T> {
...
@@ -137,6 +138,7 @@ class _InkResponseState<T extends InkResponse> extends State<T> {
}
}
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasMaterial
(
context
));
final
bool
enabled
=
config
.
onTap
!=
null
||
config
.
onDoubleTap
!=
null
||
config
.
onLongPress
!=
null
;
final
bool
enabled
=
config
.
onTap
!=
null
||
config
.
onDoubleTap
!=
null
||
config
.
onLongPress
!=
null
;
return
new
GestureDetector
(
return
new
GestureDetector
(
onTapDown:
enabled
?
_handleTapDown
:
null
,
onTapDown:
enabled
?
_handleTapDown
:
null
,
...
...
packages/flutter/lib/src/material/input.dart
View file @
c130dfff
...
@@ -7,6 +7,7 @@ import 'package:flutter/rendering.dart';
...
@@ -7,6 +7,7 @@ import 'package:flutter/rendering.dart';
import
'package:flutter/services.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter/widgets.dart'
;
import
'debug.dart'
;
import
'theme.dart'
;
import
'theme.dart'
;
export
'package:flutter/rendering.dart'
show
ValueChanged
;
export
'package:flutter/rendering.dart'
show
ValueChanged
;
...
@@ -75,6 +76,7 @@ class InputState extends ScrollableState<Input> {
...
@@ -75,6 +76,7 @@ class InputState extends ScrollableState<Input> {
}
}
Widget
buildContent
(
BuildContext
context
)
{
Widget
buildContent
(
BuildContext
context
)
{
assert
(
debugCheckHasMaterial
(
context
));
ThemeData
themeData
=
Theme
.
of
(
context
);
ThemeData
themeData
=
Theme
.
of
(
context
);
bool
focused
=
Focus
.
at
(
context
,
config
);
bool
focused
=
Focus
.
at
(
context
,
config
);
...
...
packages/flutter/lib/src/material/material_button.dart
View file @
c130dfff
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
import
'package:flutter/widgets.dart'
;
import
'package:flutter/widgets.dart'
;
import
'colors.dart'
;
import
'colors.dart'
;
import
'debug.dart'
;
import
'ink_well.dart'
;
import
'ink_well.dart'
;
import
'material.dart'
;
import
'material.dart'
;
import
'theme.dart'
;
import
'theme.dart'
;
...
@@ -98,6 +99,7 @@ abstract class MaterialButtonState<T extends MaterialButton> extends State<T> {
...
@@ -98,6 +99,7 @@ abstract class MaterialButtonState<T extends MaterialButton> extends State<T> {
}
}
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasMaterial
(
context
));
Widget
contents
=
new
InkWell
(
Widget
contents
=
new
InkWell
(
onTap:
config
.
onPressed
,
onTap:
config
.
onPressed
,
onHighlightChanged:
_handleHighlightChanged
,
onHighlightChanged:
_handleHighlightChanged
,
...
...
packages/flutter/lib/src/material/radio.dart
View file @
c130dfff
...
@@ -8,6 +8,7 @@ import 'package:flutter/rendering.dart';
...
@@ -8,6 +8,7 @@ import 'package:flutter/rendering.dart';
import
'package:flutter/widgets.dart'
;
import
'package:flutter/widgets.dart'
;
import
'constants.dart'
;
import
'constants.dart'
;
import
'debug.dart'
;
import
'theme.dart'
;
import
'theme.dart'
;
import
'toggleable.dart'
;
import
'toggleable.dart'
;
...
@@ -39,6 +40,7 @@ class Radio<T> extends StatelessComponent {
...
@@ -39,6 +40,7 @@ class Radio<T> extends StatelessComponent {
}
}
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasMaterial
(
context
));
ThemeData
themeData
=
Theme
.
of
(
context
);
ThemeData
themeData
=
Theme
.
of
(
context
);
return
new
_RadioRenderObjectWidget
(
return
new
_RadioRenderObjectWidget
(
selected:
value
==
groupValue
,
selected:
value
==
groupValue
,
...
...
packages/flutter/lib/src/material/slider.dart
View file @
c130dfff
...
@@ -10,6 +10,7 @@ import 'package:flutter/widgets.dart';
...
@@ -10,6 +10,7 @@ import 'package:flutter/widgets.dart';
import
'colors.dart'
;
import
'colors.dart'
;
import
'constants.dart'
;
import
'constants.dart'
;
import
'debug.dart'
;
import
'theme.dart'
;
import
'theme.dart'
;
class
Slider
extends
StatelessComponent
{
class
Slider
extends
StatelessComponent
{
...
@@ -37,6 +38,7 @@ class Slider extends StatelessComponent {
...
@@ -37,6 +38,7 @@ class Slider extends StatelessComponent {
}
}
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasMaterial
(
context
));
return
new
_SliderRenderObjectWidget
(
return
new
_SliderRenderObjectWidget
(
value:
(
value
-
min
)
/
(
max
-
min
),
value:
(
value
-
min
)
/
(
max
-
min
),
primaryColor:
Theme
.
of
(
context
).
accentColor
,
primaryColor:
Theme
.
of
(
context
).
accentColor
,
...
...
packages/flutter/lib/src/material/switch.dart
View file @
c130dfff
...
@@ -11,6 +11,7 @@ import 'package:flutter/widgets.dart';
...
@@ -11,6 +11,7 @@ import 'package:flutter/widgets.dart';
import
'colors.dart'
;
import
'colors.dart'
;
import
'constants.dart'
;
import
'constants.dart'
;
import
'debug.dart'
;
import
'shadows.dart'
;
import
'shadows.dart'
;
import
'theme.dart'
;
import
'theme.dart'
;
import
'toggleable.dart'
;
import
'toggleable.dart'
;
...
@@ -23,6 +24,7 @@ class Switch extends StatelessComponent {
...
@@ -23,6 +24,7 @@ class Switch extends StatelessComponent {
final
ValueChanged
<
bool
>
onChanged
;
final
ValueChanged
<
bool
>
onChanged
;
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasMaterial
(
context
));
ThemeData
themeData
=
Theme
.
of
(
context
);
ThemeData
themeData
=
Theme
.
of
(
context
);
final
isDark
=
themeData
.
brightness
==
ThemeBrightness
.
dark
;
final
isDark
=
themeData
.
brightness
==
ThemeBrightness
.
dark
;
...
...
packages/flutter/lib/src/widgets/binding.dart
View file @
c130dfff
...
@@ -76,6 +76,7 @@ class WidgetFlutterBinding extends FlutterBinding {
...
@@ -76,6 +76,7 @@ class WidgetFlutterBinding extends FlutterBinding {
void
_runApp
(
Widget
app
)
{
void
_runApp
(
Widget
app
)
{
_renderViewElement
=
new
RenderObjectToWidgetAdapter
<
RenderBox
>(
_renderViewElement
=
new
RenderObjectToWidgetAdapter
<
RenderBox
>(
container:
renderView
,
container:
renderView
,
debugShortDescription:
'[root]'
,
child:
app
child:
app
).
attachToRenderTree
(
_renderViewElement
);
).
attachToRenderTree
(
_renderViewElement
);
beginFrame
();
beginFrame
();
...
@@ -102,11 +103,15 @@ void debugDumpApp() {
...
@@ -102,11 +103,15 @@ void debugDumpApp() {
/// RenderObjectWithChildMixin protocol. The type argument T is the kind of
/// RenderObjectWithChildMixin protocol. The type argument T is the kind of
/// RenderObject that the container expects as its child.
/// RenderObject that the container expects as its child.
class
RenderObjectToWidgetAdapter
<
T
extends
RenderObject
>
extends
RenderObjectWidget
{
class
RenderObjectToWidgetAdapter
<
T
extends
RenderObject
>
extends
RenderObjectWidget
{
RenderObjectToWidgetAdapter
({
this
.
child
,
RenderObjectWithChildMixin
<
T
>
container
})
RenderObjectToWidgetAdapter
({
:
container
=
container
,
super
(
key:
new
GlobalObjectKey
(
container
));
this
.
child
,
RenderObjectWithChildMixin
<
T
>
container
,
this
.
debugShortDescription
})
:
container
=
container
,
super
(
key:
new
GlobalObjectKey
(
container
));
final
Widget
child
;
final
Widget
child
;
final
RenderObjectWithChildMixin
<
T
>
container
;
final
RenderObjectWithChildMixin
<
T
>
container
;
final
String
debugShortDescription
;
RenderObjectToWidgetElement
<
T
>
createElement
()
=>
new
RenderObjectToWidgetElement
<
T
>(
this
);
RenderObjectToWidgetElement
<
T
>
createElement
()
=>
new
RenderObjectToWidgetElement
<
T
>(
this
);
...
@@ -125,6 +130,8 @@ class RenderObjectToWidgetAdapter<T extends RenderObject> extends RenderObjectWi
...
@@ -125,6 +130,8 @@ class RenderObjectToWidgetAdapter<T extends RenderObject> extends RenderObjectWi
},
building:
true
);
},
building:
true
);
return
element
;
return
element
;
}
}
String
toStringShort
()
=>
debugShortDescription
??
super
.
toStringShort
();
}
}
/// This element class is the instantiation of a [RenderObjectToWidgetAdapter].
/// This element class is the instantiation of a [RenderObjectToWidgetAdapter].
...
...
packages/flutter/lib/src/widgets/framework.dart
View file @
c130dfff
...
@@ -875,6 +875,18 @@ abstract class Element<T extends Widget> implements BuildContext {
...
@@ -875,6 +875,18 @@ abstract class Element<T extends Widget> implements BuildContext {
assert
(
false
);
assert
(
false
);
}
}
String
debugGetOwnershipChain
(
int
limit
)
{
List
<
String
>
chain
=
<
String
>[];
Element
node
=
this
;
while
(
chain
.
length
<
limit
&&
node
!=
null
)
{
chain
.
add
(
node
.
toStringShort
());
node
=
node
.
_parent
;
}
if
(
node
!=
null
)
chain
.
add
(
'
\
u22EF'
);
return
chain
.
join
(
'
\
u2190 '
);
}
String
toStringShort
()
{
String
toStringShort
()
{
return
widget
!=
null
?
'
${widget.toStringShort()}
'
:
'[
$runtimeType
]'
;
return
widget
!=
null
?
'
${widget.toStringShort()}
'
:
'[
$runtimeType
]'
;
}
}
...
@@ -1354,15 +1366,7 @@ abstract class RenderObjectElement<T extends RenderObjectWidget> extends Buildab
...
@@ -1354,15 +1366,7 @@ abstract class RenderObjectElement<T extends RenderObjectWidget> extends Buildab
}
}
void
debugUpdateRenderObjectOwner
()
{
void
debugUpdateRenderObjectOwner
()
{
List
<
String
>
chain
=
<
String
>[];
_renderObject
.
debugOwner
=
debugGetOwnershipChain
(
4
);
Element
node
=
this
;
while
(
chain
.
length
<
4
&&
node
!=
null
)
{
chain
.
add
(
node
.
toStringShort
());
node
=
node
.
_parent
;
}
if
(
node
!=
null
)
chain
.
add
(
'
\
u22EF'
);
_renderObject
.
debugOwner
=
chain
.
join
(
'
\
u2190 '
);
}
}
void
performRebuild
()
{
void
performRebuild
()
{
...
...
packages/unit/test/widget/input_test.dart
View file @
c130dfff
...
@@ -38,10 +38,12 @@ void main() {
...
@@ -38,10 +38,12 @@ void main() {
Widget
builder
()
{
Widget
builder
()
{
return
new
Center
(
return
new
Center
(
child:
new
Input
(
child:
new
Material
(
key:
inputKey
,
child:
new
Input
(
placeholder:
'Placeholder'
,
key:
inputKey
,
onChanged:
(
String
value
)
{
inputValue
=
value
;
}
placeholder:
'Placeholder'
,
onChanged:
(
String
value
)
{
inputValue
=
value
;
}
)
)
)
);
);
}
}
...
@@ -72,9 +74,11 @@ void main() {
...
@@ -72,9 +74,11 @@ void main() {
Widget
builder
()
{
Widget
builder
()
{
return
new
Center
(
return
new
Center
(
child:
new
Input
(
child:
new
Material
(
key:
inputKey
,
child:
new
Input
(
placeholder:
'Placeholder'
key:
inputKey
,
placeholder:
'Placeholder'
)
)
)
);
);
}
}
...
@@ -112,9 +116,11 @@ void main() {
...
@@ -112,9 +116,11 @@ void main() {
Widget
builder
()
{
Widget
builder
()
{
return
new
Center
(
return
new
Center
(
child:
new
Input
(
child:
new
Material
(
key:
inputKey
,
child:
new
Input
(
placeholder:
'Placeholder'
key:
inputKey
,
placeholder:
'Placeholder'
)
)
)
);
);
}
}
...
@@ -145,10 +151,12 @@ void main() {
...
@@ -145,10 +151,12 @@ void main() {
Widget
builder
()
{
Widget
builder
()
{
return
new
Center
(
return
new
Center
(
child:
new
Input
(
child:
new
Material
(
key:
inputKey
,
child:
new
Input
(
hideText:
true
,
key:
inputKey
,
placeholder:
'Placeholder'
hideText:
true
,
placeholder:
'Placeholder'
)
)
)
);
);
}
}
...
...
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