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
7ba5078f
Unverified
Commit
7ba5078f
authored
May 08, 2020
by
Hans Muller
Committed by
GitHub
May 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added MaterialStateProperty.all() convenience method (#56589)
parent
3cb79079
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
3 deletions
+49
-3
material_state.dart
packages/flutter/lib/src/material/material_state.dart
+16
-3
material_state_property_test.dart
...s/flutter/test/material/material_state_property_test.dart
+33
-0
No files found.
packages/flutter/lib/src/material/material_state.dart
View file @
7ba5078f
...
...
@@ -209,14 +209,27 @@ abstract class MaterialStateProperty<T> {
/// Convenience method for creating a [MaterialStateProperty] from a
/// [MaterialPropertyResolver] function alone.
static
MaterialStateProperty
<
T
>
resolveWith
<
T
>(
MaterialPropertyResolver
<
T
>
callback
)
=>
_MaterialStateProperty
<
T
>(
callback
);
static
MaterialStateProperty
<
T
>
resolveWith
<
T
>(
MaterialPropertyResolver
<
T
>
callback
)
=>
_MaterialStatePropertyWith
<
T
>(
callback
);
/// Convenience method for creating a [MaterialStateProperty] that resolves
/// to a single value for all states.
static
MaterialStateProperty
<
T
>
all
<
T
>(
T
value
)
=>
_MaterialStatePropertyAll
<
T
>(
value
);
}
class
_MaterialStateProperty
<
T
>
implements
MaterialStateProperty
<
T
>
{
_MaterialStateProperty
(
this
.
_resolve
);
class
_MaterialStateProperty
With
<
T
>
implements
MaterialStateProperty
<
T
>
{
_MaterialStateProperty
With
(
this
.
_resolve
);
final
MaterialPropertyResolver
<
T
>
_resolve
;
@override
T
resolve
(
Set
<
MaterialState
>
states
)
=>
_resolve
(
states
);
}
class
_MaterialStatePropertyAll
<
T
>
implements
MaterialStateProperty
<
T
>
{
_MaterialStatePropertyAll
(
this
.
value
);
final
T
value
;
@override
T
resolve
(
Set
<
MaterialState
>
states
)
=>
value
;
}
packages/flutter/test/material/material_state_property_test.dart
0 → 100644
View file @
7ba5078f
// Copyright 2014 The Flutter 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/material.dart'
;
void
main
(
)
{
test
(
'MaterialStateProperty.resolveWith()'
,
()
{
final
MaterialStateProperty
<
MaterialState
>
value
=
MaterialStateProperty
.
resolveWith
<
MaterialState
>(
(
Set
<
MaterialState
>
states
)
=>
states
.
first
,
);
expect
(
value
.
resolve
(<
MaterialState
>{
MaterialState
.
hovered
}),
MaterialState
.
hovered
);
expect
(
value
.
resolve
(<
MaterialState
>{
MaterialState
.
focused
}),
MaterialState
.
focused
);
expect
(
value
.
resolve
(<
MaterialState
>{
MaterialState
.
pressed
}),
MaterialState
.
pressed
);
expect
(
value
.
resolve
(<
MaterialState
>{
MaterialState
.
dragged
}),
MaterialState
.
dragged
);
expect
(
value
.
resolve
(<
MaterialState
>{
MaterialState
.
selected
}),
MaterialState
.
selected
);
expect
(
value
.
resolve
(<
MaterialState
>{
MaterialState
.
disabled
}),
MaterialState
.
disabled
);
expect
(
value
.
resolve
(<
MaterialState
>{
MaterialState
.
error
}),
MaterialState
.
error
);
});
test
(
'MaterialStateProperty.all()'
,
()
{
final
MaterialStateProperty
<
int
>
value
=
MaterialStateProperty
.
all
<
int
>(
123
);
expect
(
value
.
resolve
(<
MaterialState
>{
MaterialState
.
hovered
}),
123
);
expect
(
value
.
resolve
(<
MaterialState
>{
MaterialState
.
focused
}),
123
);
expect
(
value
.
resolve
(<
MaterialState
>{
MaterialState
.
pressed
}),
123
);
expect
(
value
.
resolve
(<
MaterialState
>{
MaterialState
.
dragged
}),
123
);
expect
(
value
.
resolve
(<
MaterialState
>{
MaterialState
.
selected
}),
123
);
expect
(
value
.
resolve
(<
MaterialState
>{
MaterialState
.
disabled
}),
123
);
expect
(
value
.
resolve
(<
MaterialState
>{
MaterialState
.
error
}),
123
);
});
}
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