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
43ed3b6b
Unverified
Commit
43ed3b6b
authored
Jul 13, 2021
by
Viren Khatri
Committed by
GitHub
Jul 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added rethrowError to FutureBuilder (#84308)
parent
d2057d50
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
0 deletions
+33
-0
async.dart
packages/flutter/lib/src/widgets/async.dart
+15
-0
async_test.dart
packages/flutter/test/widgets/async_test.dart
+18
-0
No files found.
packages/flutter/lib/src/widgets/async.dart
View file @
43ed3b6b
...
...
@@ -737,6 +737,14 @@ class FutureBuilder<T> extends StatefulWidget {
/// [AsyncSnapshot.hasError] will be true.)
final
T
?
initialData
;
/// Whether the latest error received by the asynchronous computation should
/// be rethrown or swallowed. This property is useful for debugging purposes.
///
/// When set to true, will rethrow the latest error only in debug mode.
///
/// Defaults to `false`, resulting in swallowing of errors.
static
bool
debugRethrowError
=
false
;
@override
State
<
FutureBuilder
<
T
>>
createState
()
=>
_FutureBuilderState
<
T
>();
}
...
...
@@ -795,6 +803,13 @@ class _FutureBuilderState<T> extends State<FutureBuilder<T>> {
_snapshot
=
AsyncSnapshot
<
T
>.
withError
(
ConnectionState
.
done
,
error
,
stackTrace
);
});
}
assert
(()
{
if
(
FutureBuilder
.
debugRethrowError
)
{
Future
<
Object
>.
error
(
error
,
stackTrace
);
}
return
true
;
}());
});
_snapshot
=
_snapshot
.
inState
(
ConnectionState
.
waiting
);
}
...
...
packages/flutter/test/widgets/async_test.dart
View file @
43ed3b6b
...
...
@@ -165,6 +165,24 @@ void main() {
));
expect
(
find
.
text
(
'AsyncSnapshot<String>(ConnectionState.waiting, I, null, null)'
),
findsOneWidget
);
});
testWidgets
(
'debugRethrowError rethrows caught error'
,
(
WidgetTester
tester
)
async
{
FutureBuilder
.
debugRethrowError
=
true
;
final
Completer
<
void
>
caughtError
=
Completer
<
void
>();
await
runZonedGuarded
(()
async
{
final
Completer
<
String
>
completer
=
Completer
<
String
>();
await
tester
.
pumpWidget
(
FutureBuilder
<
String
>(
future:
completer
.
future
,
builder:
snapshotText
,
),
const
Duration
(
seconds:
1
));
completer
.
completeError
(
'bad'
);
},
(
Object
error
,
StackTrace
stack
)
{
expectSync
(
error
,
equals
(
'bad'
));
caughtError
.
complete
();
});
await
tester
.
pumpAndSettle
();
expectSync
(
caughtError
.
isCompleted
,
isTrue
);
FutureBuilder
.
debugRethrowError
=
false
;
});
});
group
(
'StreamBuilder'
,
()
{
testWidgets
(
'gracefully handles transition from null stream'
,
(
WidgetTester
tester
)
async
{
...
...
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