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
b803d187
Commit
b803d187
authored
May 17, 2016
by
Ian Hickson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Catch async functions passed to setState(). (#3992)
parent
fc610604
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
1 deletion
+46
-1
framework.dart
packages/flutter/lib/src/widgets/framework.dart
+16
-1
set_state_1_test.dart
packages/flutter/test/widget/set_state_1_test.dart
+0
-0
set_state_4_test.dart
packages/flutter/test/widget/set_state_4_test.dart
+30
-0
No files found.
packages/flutter/lib/src/widgets/framework.dart
View file @
b803d187
...
...
@@ -416,7 +416,22 @@ abstract class State<T extends StatefulWidget> {
}
return
true
;
});
fn
();
dynamic
result
=
fn
()
as
dynamic
;
assert
(()
{
if
(
result
is
Future
)
{
throw
new
FlutterError
(
'setState() callback argument returned a Future.
\n
'
'The setState() method on
$this
was invoked with a closure or method that '
'returned a Future. Maybe it is marked as "async".
\n
'
'Instead of performing asynchronous work inside a call to setState(), first '
'execute the work (without updating the widget state), and then synchronously '
'update the state inside a call to setState().'
);
}
// We ignore other types of return values so that you can do things like:
// setState(() => x = 3);
return
true
;
});
_element
.
markNeedsBuild
();
}
...
...
packages/flutter/test/widget/set_state_test.dart
→
packages/flutter/test/widget/set_state_
1_
test.dart
View file @
b803d187
File moved
packages/flutter/test/widget/set_state_4_test.dart
0 → 100644
View file @
b803d187
// 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_test/flutter_test.dart'
;
import
'package:flutter/widgets.dart'
;
class
Changer
extends
StatefulWidget
{
@override
ChangerState
createState
()
=>
new
ChangerState
();
}
class
ChangerState
extends
State
<
Changer
>
{
void
test0
()
{
setState
(()
{
});
}
void
test1
()
{
setState
(()
=>
1
);
}
void
test2
()
{
setState
(()
async
{
});
}
@override
Widget
build
(
BuildContext
context
)
=>
new
Text
(
'test'
);
}
void
main
(
)
{
testWidgets
(
'setState() catches being used with an async callback'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
Changer
());
ChangerState
s
=
tester
.
state
(
find
.
byType
(
Changer
));
expect
(
s
.
test0
,
isNot
(
throws
));
expect
(
s
.
test1
,
isNot
(
throws
));
expect
(
s
.
test2
,
throws
);
});
}
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