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
af1c629d
Unverified
Commit
af1c629d
authored
Dec 22, 2020
by
Shi-Hao Hong
Committed by
GitHub
Dec 22, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[State Restoration] Adds remaining Restorable{Property}N (#72708)
parent
0f5b79a2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
116 additions
and
8 deletions
+116
-8
restoration_properties.dart
packages/flutter/lib/src/widgets/restoration_properties.dart
+87
-7
restorable_property_test.dart
packages/flutter/test/widgets/restorable_property_test.dart
+29
-1
No files found.
packages/flutter/lib/src/widgets/restoration_properties.dart
View file @
af1c629d
...
...
@@ -209,6 +209,10 @@ class _RestorablePrimitiveValue<T extends Object> extends _RestorablePrimitiveVa
/// Instead of using the more generic [RestorableNum] directly, consider using
/// one of the more specific subclasses (e.g. [RestorableDouble] to store a
/// [double] and [RestorableInt] to store an [int]).
///
/// See also:
///
/// * [RestorableNumN] for the nullable version of this class.
class
RestorableNum
<
T
extends
num
>
extends
_RestorablePrimitiveValue
<
T
>
{
/// Creates a [RestorableNum].
///
...
...
@@ -222,6 +226,10 @@ class RestorableNum<T extends num> extends _RestorablePrimitiveValue<T> {
/// A [RestorableProperty] that knows how to store and restore a [double].
///
/// {@macro flutter.widgets.RestorableNum}
///
/// See also:
///
/// * [RestorableDoubleN] for the nullable version of this class.
class
RestorableDouble
extends
RestorableNum
<
double
>
{
/// Creates a [RestorableDouble].
///
...
...
@@ -232,6 +240,10 @@ class RestorableDouble extends RestorableNum<double> {
/// A [RestorableProperty] that knows how to store and restore an [int].
///
/// {@macro flutter.widgets.RestorableNum}
///
/// See also:
///
/// * [RestorableIntN] for the nullable version of this class.
class
RestorableInt
extends
RestorableNum
<
int
>
{
/// Creates a [RestorableInt].
///
...
...
@@ -242,6 +254,10 @@ class RestorableInt extends RestorableNum<int> {
/// A [RestorableProperty] that knows how to store and restore a [String].
///
/// {@macro flutter.widgets.RestorableNum}
///
/// See also:
///
/// * [RestorableStringN] for the nullable version of this class.
class
RestorableString
extends
_RestorablePrimitiveValue
<
String
>
{
/// Creates a [RestorableString].
///
...
...
@@ -252,14 +268,14 @@ class RestorableString extends _RestorablePrimitiveValue<String> {
/// A [RestorableProperty] that knows how to store and restore a [bool].
///
/// {@macro flutter.widgets.RestorableNum}
///
/// See also:
///
/// * [RestorableBoolN] for the nullable version of this class.
class
RestorableBool
extends
_RestorablePrimitiveValue
<
bool
>
{
/// Creates a [RestorableBool].
///
/// {@macro flutter.widgets.RestorableNum.constructor}
///
/// See also:
///
/// * [RestorableBoolN] for the nullable version of this class.
RestorableBool
(
bool
defaultValue
)
:
assert
(
defaultValue
!=
null
),
super
(
defaultValue
);
}
...
...
@@ -267,15 +283,79 @@ class RestorableBool extends _RestorablePrimitiveValue<bool> {
/// nullable.
///
/// {@macro flutter.widgets.RestorableNum}
///
/// See also:
///
/// * [RestorableBool] for the non-nullable version of this class.
class
RestorableBoolN
extends
_RestorablePrimitiveValueN
<
bool
?>
{
/// Creates a [RestorableBoolN].
///
/// {@macro flutter.widgets.RestorableNum.constructor}
RestorableBoolN
(
bool
?
defaultValue
)
:
super
(
defaultValue
);
}
/// A [RestorableProperty] that knows how to store and restore a [num]
/// that is nullable.
///
/// {@macro flutter.widgets.RestorableNum}
///
/// Instead of using the more generic [RestorableNumN] directly, consider using
/// one of the more specific subclasses (e.g. [RestorableDoubleN] to store a
/// [double] and [RestorableIntN] to store an [int]).
///
/// See also:
///
/// * [RestorableNum] for the non-nullable version of this class.
class
RestorableNumN
<
T
extends
num
?>
extends
_RestorablePrimitiveValueN
<
num
?>
{
/// Creates a [RestorableNumN].
///
/// {@macro flutter.widgets.RestorableNum.constructor}
RestorableNumN
(
num
?
defaultValue
)
:
super
(
defaultValue
);
}
/// A [RestorableProperty] that knows how to store and restore a [double]
/// that is nullable.
///
/// {@macro flutter.widgets.RestorableNum}
///
/// See also:
///
/// * [RestorableDouble] for the non-nullable version of this class.
class
RestorableDoubleN
extends
RestorableNumN
<
double
>
{
/// Creates a [RestorableDoubleN].
///
/// See also:
/// {@macro flutter.widgets.RestorableNum.constructor}
RestorableDoubleN
(
double
?
defaultValue
)
:
super
(
defaultValue
);
}
/// A [RestorableProperty] that knows how to store and restore an [int]
/// that is nullable.
///
/// {@macro flutter.widgets.RestorableNum}
///
/// See also:
///
/// * [RestorableInt] for the non-nullable version of this class.
class
RestorableIntN
extends
RestorableNumN
<
int
>
{
/// Creates a [RestorableIntN].
///
/// * [RestorableBool] for the non-nullable version of this class.
RestorableBoolN
(
bool
?
defaultValue
)
:
super
(
defaultValue
);
/// {@macro flutter.widgets.RestorableNum.constructor}
RestorableIntN
(
int
?
defaultValue
)
:
super
(
defaultValue
);
}
/// A [RestorableProperty] that knows how to store and restore a [String]
/// that is nullable.
///
/// {@macro flutter.widgets.RestorableNum}
///
/// See also:
///
/// * [RestorableString] for the non-nullable version of this class.
class
RestorableStringN
extends
_RestorablePrimitiveValueN
<
String
?>
{
/// Creates a [RestorableString].
///
/// {@macro flutter.widgets.RestorableNum.constructor}
RestorableStringN
(
String
?
defaultValue
)
:
super
(
defaultValue
);
}
/// A base class for creating a [RestorableProperty] that stores and restores a
...
...
packages/flutter/test/widgets/restorable_property_test.dart
View file @
af1c629d
...
...
@@ -13,6 +13,10 @@ void main() {
expect
(()
=>
RestorableInt
(
1
).
value
,
throwsAssertionError
);
expect
(()
=>
RestorableString
(
'hello'
).
value
,
throwsAssertionError
);
expect
(()
=>
RestorableBool
(
true
).
value
,
throwsAssertionError
);
expect
(()
=>
RestorableNumN
<
num
>(
0
).
value
,
throwsAssertionError
);
expect
(()
=>
RestorableDoubleN
(
1.0
).
value
,
throwsAssertionError
);
expect
(()
=>
RestorableIntN
(
1
).
value
,
throwsAssertionError
);
expect
(()
=>
RestorableStringN
(
'hello'
).
value
,
throwsAssertionError
);
expect
(()
=>
RestorableBoolN
(
true
).
value
,
throwsAssertionError
);
expect
(()
=>
RestorableTextEditingController
().
value
,
throwsAssertionError
);
expect
(()
=>
_TestRestorableValue
().
value
,
throwsAssertionError
);
...
...
@@ -126,6 +130,10 @@ void main() {
state
.
intValue
.
value
=
10
;
state
.
stringValue
.
value
=
'guten tag'
;
state
.
boolValue
.
value
=
true
;
state
.
nullableNumValue
.
value
=
5.0
;
state
.
nullableDoubleValue
.
value
=
2.0
;
state
.
nullableIntValue
.
value
=
1
;
state
.
nullableStringValue
.
value
=
'hullo'
;
state
.
nullableBoolValue
.
value
=
false
;
state
.
controllerValue
.
value
.
text
=
'blabla'
;
state
.
objectValue
.
value
=
53
;
...
...
@@ -142,6 +150,10 @@ void main() {
state
.
intValue
.
value
=
20
;
state
.
stringValue
.
value
=
'ciao'
;
state
.
boolValue
.
value
=
false
;
state
.
nullableNumValue
.
value
=
20.0
;
state
.
nullableDoubleValue
.
value
=
20.0
;
state
.
nullableIntValue
.
value
=
20
;
state
.
nullableStringValue
.
value
=
'ni hao'
;
state
.
nullableBoolValue
.
value
=
null
;
state
.
controllerValue
.
value
.
text
=
'blub'
;
state
.
objectValue
.
value
=
20
;
...
...
@@ -157,6 +169,10 @@ void main() {
expect
(
state
.
intValue
.
value
,
10
);
expect
(
state
.
stringValue
.
value
,
'guten tag'
);
expect
(
state
.
boolValue
.
value
,
true
);
expect
(
state
.
nullableNumValue
.
value
,
5.0
);
expect
(
state
.
nullableDoubleValue
.
value
,
2.0
);
expect
(
state
.
nullableIntValue
.
value
,
1
);
expect
(
state
.
nullableStringValue
.
value
,
'hullo'
);
expect
(
state
.
nullableBoolValue
.
value
,
false
);
expect
(
state
.
controllerValue
.
value
.
text
,
'blabla'
);
expect
(
state
.
objectValue
.
value
,
53
);
...
...
@@ -170,6 +186,10 @@ void main() {
expect
(
state
.
intValue
.
value
,
42
);
expect
(
state
.
stringValue
.
value
,
'hello world'
);
expect
(
state
.
boolValue
.
value
,
false
);
expect
(
state
.
nullableNumValue
.
value
,
null
);
expect
(
state
.
nullableDoubleValue
.
value
,
null
);
expect
(
state
.
nullableIntValue
.
value
,
null
);
expect
(
state
.
nullableStringValue
.
value
,
null
);
expect
(
state
.
nullableBoolValue
.
value
,
null
);
expect
(
state
.
controllerValue
.
value
.
text
,
'FooBar'
);
expect
(
state
.
objectValue
.
value
,
55
);
...
...
@@ -328,6 +348,10 @@ class _RestorableWidgetState extends State<_RestorableWidget> with RestorationMi
final
RestorableInt
intValue
=
RestorableInt
(
42
);
final
RestorableString
stringValue
=
RestorableString
(
'hello world'
);
final
RestorableBool
boolValue
=
RestorableBool
(
false
);
final
RestorableNumN
<
num
>
nullableNumValue
=
RestorableNumN
<
num
>(
null
);
final
RestorableDoubleN
nullableDoubleValue
=
RestorableDoubleN
(
null
);
final
RestorableIntN
nullableIntValue
=
RestorableIntN
(
null
);
final
RestorableStringN
nullableStringValue
=
RestorableStringN
(
null
);
final
RestorableBoolN
nullableBoolValue
=
RestorableBoolN
(
null
);
final
RestorableTextEditingController
controllerValue
=
RestorableTextEditingController
(
text:
'FooBar'
);
final
_TestRestorableValue
objectValue
=
_TestRestorableValue
();
...
...
@@ -339,6 +363,10 @@ class _RestorableWidgetState extends State<_RestorableWidget> with RestorationMi
registerForRestoration
(
intValue
,
'int'
);
registerForRestoration
(
stringValue
,
'string'
);
registerForRestoration
(
boolValue
,
'bool'
);
registerForRestoration
(
nullableNumValue
,
'nullableNum'
);
registerForRestoration
(
nullableDoubleValue
,
'nullableDouble'
);
registerForRestoration
(
nullableIntValue
,
'nullableInt'
);
registerForRestoration
(
nullableStringValue
,
'nullableString'
);
registerForRestoration
(
nullableBoolValue
,
'nullableBool'
);
registerForRestoration
(
controllerValue
,
'controller'
);
registerForRestoration
(
objectValue
,
'object'
);
...
...
@@ -350,7 +378,7 @@ class _RestorableWidgetState extends State<_RestorableWidget> with RestorationMi
@override
Widget
build
(
BuildContext
context
)
{
return
Text
(
stringValue
.
value
,
textDirection:
TextDirection
.
ltr
,
);
return
Text
(
stringValue
.
value
,
textDirection:
TextDirection
.
ltr
);
}
@override
...
...
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