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
f98b4863
Unverified
Commit
f98b4863
authored
Jan 17, 2018
by
Ian Hickson
Committed by
GitHub
Jan 17, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make debugCheckHasMaterial more useful (#14101)
Fixes
https://github.com/flutter/flutter/issues/2877
parent
b1248de5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
14 deletions
+41
-14
debug.dart
packages/flutter/lib/src/material/debug.dart
+38
-13
debug_test.dart
packages/flutter/test/material/debug_test.dart
+3
-1
No files found.
packages/flutter/lib/src/material/debug.dart
View file @
f98b4863
...
...
@@ -22,20 +22,45 @@ import 'material.dart';
bool
debugCheckHasMaterial
(
BuildContext
context
)
{
assert
(()
{
if
(
context
.
widget
is
!
Material
&&
context
.
ancestorWidgetOfExactType
(
Material
)
==
null
)
{
final
Element
element
=
context
;
throw
new
FlutterError
(
'No Material widget found.
\n
'
'
${context.widget.runtimeType}
widgets require a Material widget ancestor.
\n
'
'In material design, most widgets are conceptually "printed" on a sheet of material. In Flutter
\'
s material library, '
'that material is represented by the Material widget. It is the Material widget that renders ink splashes, for instance. '
'Because of this, many material library widgets require that there be a Material widget in the tree above them.
\n
'
'To introduce a Material widget, you can either directly include one, or use a widget that contains Material itself, '
'such as a Card, Dialog, Drawer, or Scaffold.
\n
'
'The specific widget that could not find a Material ancestor was:
\n
'
'
${context.widget}
\n
'
'The ownership chain for the affected widget is:
\n
'
'
${element.debugGetCreatorChain(10)}
'
final
StringBuffer
message
=
new
StringBuffer
();
message
.
writeln
(
'No Material widget found.'
);
message
.
writeln
(
'
${context.widget.runtimeType}
widgets require a Material '
'widget ancestor.'
);
message
.
writeln
(
'In material design, most widgets are conceptually "printed" on '
'a sheet of material. In Flutter
\'
s material library, that '
'material is represented by the Material widget. It is the '
'Material widget that renders ink splashes, for instance. '
'Because of this, many material library widgets require that '
'there be a Material widget in the tree above them.'
);
message
.
writeln
(
'To introduce a Material widget, you can either directly '
'include one, or use a widget that contains Material itself, '
'such as a Card, Dialog, Drawer, or Scaffold.'
);
message
.
writeln
(
'The specific widget that could not find a Material ancestor was:'
);
message
.
writeln
(
'
${context.widget}
'
);
final
List
<
Widget
>
ancestors
=
<
Widget
>[];
context
.
visitAncestorElements
((
Element
element
)
{
ancestors
.
add
(
element
.
widget
);
return
true
;
});
if
(
ancestors
.
isNotEmpty
)
{
message
.
write
(
'The ancestors of this widget were:'
);
for
(
Widget
ancestor
in
ancestors
)
message
.
write
(
'
\n
$ancestor
'
);
}
else
{
message
.
writeln
(
'This widget is the root of the tree, so it has no '
'ancestors, let alone a "Material" ancestor.'
);
}
throw
new
FlutterError
(
message
.
toString
());
}
return
true
;
}());
...
...
packages/flutter/test/material/debug_test.dart
View file @
f98b4863
...
...
@@ -11,6 +11,8 @@ void main() {
onPressed:
null
,
child:
const
Text
(
'Go'
),
));
expect
(
tester
.
takeException
(),
isFlutterError
);
final
dynamic
exception
=
tester
.
takeException
();
expect
(
exception
,
isFlutterError
);
expect
(
exception
.
toString
(),
endsWith
(
':
\n
FlatButton(disabled)
\n
[root]'
));
});
}
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