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
76a9f683
Unverified
Commit
76a9f683
authored
May 15, 2023
by
Kate Lovett
Committed by
GitHub
May 15, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more to error message of RestorationScope.of (#126444)
Fixes
https://github.com/flutter/flutter/issues/126443
parent
41abe998
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
9 deletions
+66
-9
restoration.dart
packages/flutter/lib/src/widgets/restoration.dart
+20
-9
restoration_scope_test.dart
packages/flutter/test/widgets/restoration_scope_test.dart
+46
-0
No files found.
packages/flutter/lib/src/widgets/restoration.dart
View file @
76a9f683
...
...
@@ -106,15 +106,26 @@ class RestorationScope extends StatefulWidget {
final
RestorationBucket
?
bucket
=
maybeOf
(
context
);
assert
(()
{
if
(
bucket
==
null
)
{
throw
FlutterError
(
'RestorationScope.of() was called with a context that does not contain a '
'RestorationScope widget.
\n
'
'No RestorationScope widget ancestor could be found starting from the '
'context that was passed to RestorationScope.of(). This can happen '
'because you are using a widget that looks for a RestorationScope '
'ancestor, but no such ancestor exists.
\n
'
'The context used was:
\n
'
'
$context
'
,
throw
FlutterError
.
fromParts
(<
DiagnosticsNode
>[
ErrorSummary
(
'RestorationScope.of() was called with a context that does not '
'contain a RestorationScope widget. '
),
ErrorDescription
(
'No RestorationScope widget ancestor could be found starting from '
'the context that was passed to RestorationScope.of(). This can '
'happen because you are using a widget that looks for a '
'RestorationScope ancestor, but no such ancestor exists.
\n
'
'The context used was:
\n
'
'
$context
'
),
ErrorHint
(
'State restoration must be enabled for a RestorationScope to exist. '
'This can be done by passing a restorationScopeId to MaterialApp, '
'CupertinoApp, or WidgetsApp at the root of the widget tree or by '
'wrapping the widget tree in a RootRestorationScope.'
),
],
);
}
return
true
;
...
...
packages/flutter/test/widgets/restoration_scope_test.dart
View file @
76a9f683
...
...
@@ -51,6 +51,52 @@ void main() {
});
group
(
'RestorationScope'
,
()
{
testWidgets
(
'asserts when none is found'
,
(
WidgetTester
tester
)
async
{
late
BuildContext
capturedContext
;
await
tester
.
pumpWidget
(
WidgetsApp
(
color:
const
Color
(
0xD0FF0000
),
builder:
(
_
,
__
)
{
return
RestorationScope
(
restorationId:
'test'
,
child:
Builder
(
builder:
(
BuildContext
context
)
{
capturedContext
=
context
;
return
Container
();
}
)
);
},
));
expect
(
()
{
RestorationScope
.
of
(
capturedContext
);
},
throwsA
(
isA
<
FlutterError
>().
having
(
(
FlutterError
error
)
=>
error
.
message
,
'message'
,
contains
(
'State restoration must be enabled for a RestorationScope'
),
)),
);
await
tester
.
pumpWidget
(
WidgetsApp
(
restorationScopeId:
'test scope'
,
color:
const
Color
(
0xD0FF0000
),
builder:
(
_
,
__
)
{
return
RestorationScope
(
restorationId:
'test'
,
child:
Builder
(
builder:
(
BuildContext
context
)
{
capturedContext
=
context
;
return
Container
();
}
)
);
},
));
final
UnmanagedRestorationScope
scope
=
tester
.
widget
(
find
.
byType
(
UnmanagedRestorationScope
).
last
);
expect
(
RestorationScope
.
of
(
capturedContext
),
scope
.
bucket
);
});
testWidgets
(
'makes bucket available to descendants'
,
(
WidgetTester
tester
)
async
{
const
String
id
=
'hello world 1234'
;
final
MockRestorationManager
manager
=
MockRestorationManager
();
...
...
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