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
f8a7abb6
Unverified
Commit
f8a7abb6
authored
Dec 11, 2018
by
Hans Muller
Committed by
GitHub
Dec 11, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a check for build methods that return context.widget (#25046)
parent
3f1c308e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
+24
-0
debug.dart
packages/flutter/lib/src/widgets/debug.dart
+8
-0
build_fail_test.dart
packages/flutter/test/widgets/build_fail_test.dart
+16
-0
No files found.
packages/flutter/lib/src/widgets/debug.dart
View file @
f8a7abb6
...
@@ -275,6 +275,14 @@ void debugWidgetBuilderValue(Widget widget, Widget built) {
...
@@ -275,6 +275,14 @@ void debugWidgetBuilderValue(Widget widget, Widget built) {
'To return an empty space that takes as little room as possible, return "new Container(width: 0.0, height: 0.0)".'
'To return an empty space that takes as little room as possible, return "new Container(width: 0.0, height: 0.0)".'
);
);
}
}
if
(
widget
==
built
)
{
throw
FlutterError
(
'A build function returned context.widget.
\n
'
'The offending widget is:
$widget
\n
'
'Build functions must never return their BuildContext parameter
\'
s widget or a child that contains "context.widget". '
'Doing so introduces a loop in the widget tree that can cause the app to crash.'
);
}
return
true
;
return
true
;
}());
}());
}
}
...
...
packages/flutter/test/widgets/build_fail_test.dart
0 → 100644
View file @
f8a7abb6
// Copyright 2018 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_test/flutter_test.dart'
;
import
'package:flutter/widgets.dart'
;
Future
<
void
>
main
()
async
{
testWidgets
(
'Build method that returns context.widget throws FlutterError'
,
(
WidgetTester
tester
)
async
{
// Regression test for: https://github.com/flutter/flutter/issues/25041
await
tester
.
pumpWidget
(
Builder
(
builder:
(
BuildContext
context
)
=>
context
.
widget
)
);
expect
(
tester
.
takeException
(),
isFlutterError
);
});
}
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