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
2ff2274c
Commit
2ff2274c
authored
Jun 05, 2017
by
Ian Hickson
Committed by
GitHub
Jun 05, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make ColorSwatch more general, and test it (#10505)
parent
1b29312a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
52 deletions
+80
-52
colors.dart
packages/flutter/lib/src/material/colors.dart
+20
-52
colors.dart
packages/flutter/lib/src/painting/colors.dart
+36
-0
colors_test.dart
packages/flutter/test/painting/colors_test.dart
+24
-0
No files found.
packages/flutter/lib/src/material/colors.dart
View file @
2ff2274c
...
...
@@ -2,41 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:ui'
show
Color
,
hashValues
;
import
'dart:ui'
show
Color
;
/// A color that has a small table of related colors called a "swatch".
///
/// See also:
///
/// * [MaterialColor] and [MaterialAccentColor], which define material design
/// primary and accent color swatches.
/// * [Colors], which defines all of the standard material design colors.
class
ColorSwatch
extends
Color
{
/// Creates a color that has a small table of related colors called a "swatch".
const
ColorSwatch
(
int
primary
,
this
.
_swatch
)
:
super
(
primary
);
final
Map
<
int
,
Color
>
_swatch
;
/// Returns an element of the swatch table.
Color
operator
[](
int
index
)
=>
_swatch
[
index
];
@override
bool
operator
==(
dynamic
other
)
{
if
(
identical
(
this
,
other
))
return
true
;
if
(
other
.
runtimeType
!=
runtimeType
)
return
false
;
final
ColorSwatch
typedOther
=
other
;
return
super
==(
other
)
&&
_swatch
==
typedOther
.
_swatch
;
}
@override
int
get
hashCode
=>
hashValues
(
runtimeType
,
value
,
_swatch
);
@override
String
toString
()
=>
'
$runtimeType
(primary value:
${super.toString()}
)'
;
}
import
'package:flutter/painting.dart'
;
/// Defines a single color as well a color swatch with ten shades of the color.
///
...
...
@@ -47,39 +15,39 @@ class ColorSwatch extends Color {
/// See also:
///
/// * [Colors], which defines all of the standard material colors.
class
MaterialColor
extends
ColorSwatch
{
class
MaterialColor
extends
ColorSwatch
<
int
>
{
/// Creates a color swatch with a variety of shades.
const
MaterialColor
(
int
primary
,
Map
<
int
,
Color
>
swatch
)
:
super
(
primary
,
swatch
);
/// The lightest shade.
Color
get
shade50
=>
_swatch
[
50
];
Color
get
shade50
=>
this
[
50
];
/// The second lightest shade.
Color
get
shade100
=>
_swatch
[
100
];
Color
get
shade100
=>
this
[
100
];
/// The third lightest shade.
Color
get
shade200
=>
_swatch
[
200
];
Color
get
shade200
=>
this
[
200
];
/// The fourth lightest shade.
Color
get
shade300
=>
_swatch
[
300
];
Color
get
shade300
=>
this
[
300
];
/// The fifth lightest shade.
Color
get
shade400
=>
_swatch
[
400
];
Color
get
shade400
=>
this
[
400
];
/// The default shade.
Color
get
shade500
=>
_swatch
[
500
];
Color
get
shade500
=>
this
[
500
];
/// The fourth darkest shade.
Color
get
shade600
=>
_swatch
[
600
];
Color
get
shade600
=>
this
[
600
];
/// The third darkest shade.
Color
get
shade700
=>
_swatch
[
700
];
Color
get
shade700
=>
this
[
700
];
/// The second darkest shade.
Color
get
shade800
=>
_swatch
[
800
];
Color
get
shade800
=>
this
[
800
];
/// The darkest shade.
Color
get
shade900
=>
_swatch
[
900
];
Color
get
shade900
=>
this
[
900
];
}
/// Defines a single accent color as well a swatch of four shades of the
...
...
@@ -94,25 +62,25 @@ class MaterialColor extends ColorSwatch {
///
/// * [Colors], which defines all of the standard material colors.
/// * <https://material.io/guidelines/style/color.html#color-color-schemes>
class
MaterialAccentColor
extends
ColorSwatch
{
class
MaterialAccentColor
extends
ColorSwatch
<
int
>
{
/// Creates a color swatch with a variety of shades appropriate for accent
/// colors.
const
MaterialAccentColor
(
int
primary
,
Map
<
int
,
Color
>
swatch
)
:
super
(
primary
,
swatch
);
/// The lightest shade.
Color
get
shade50
=>
_swatch
[
50
];
Color
get
shade50
=>
this
[
50
];
/// The second lightest shade.
Color
get
shade100
=>
_swatch
[
100
];
Color
get
shade100
=>
this
[
100
];
/// The default shade.
Color
get
shade200
=>
_swatch
[
200
];
Color
get
shade200
=>
this
[
200
];
/// The second darkest shade.
Color
get
shade400
=>
_swatch
[
400
];
Color
get
shade400
=>
this
[
400
];
/// The darkest shade.
Color
get
shade700
=>
_swatch
[
700
];
Color
get
shade700
=>
this
[
700
];
}
/// [Color] and [ColorSwatch] constants which represent Material design's
...
...
@@ -130,7 +98,7 @@ class MaterialAccentColor extends ColorSwatch {
/// Colors.green[400] // Selects a mid-range green.
/// ```
///
/// Each
ColorSwatch
constant is a color and can used directly. For example
/// Each
[ColorSwatch]
constant is a color and can used directly. For example
///
/// ```dart
/// new Container(
...
...
packages/flutter/lib/src/painting/colors.dart
View file @
2ff2274c
...
...
@@ -172,3 +172,39 @@ class HSVColor {
@override
String
toString
()
=>
"HSVColor(
$alpha
,
$hue
,
$saturation
,
$value
)"
;
}
/// A color that has a small table of related colors called a "swatch".
///
/// The table is indexed by values of type `T`.
///
/// See also:
///
/// * [MaterialColor] and [MaterialAccentColor], which define material design
/// primary and accent color swatches.
/// * [Colors], which defines all of the standard material design colors.
class
ColorSwatch
<
T
>
extends
Color
{
/// Creates a color that has a small table of related colors called a "swatch".
const
ColorSwatch
(
int
primary
,
this
.
_swatch
)
:
super
(
primary
);
@protected
final
Map
<
T
,
Color
>
_swatch
;
/// Returns an element of the swatch table.
Color
operator
[](
T
index
)
=>
_swatch
[
index
];
@override
bool
operator
==(
dynamic
other
)
{
if
(
identical
(
this
,
other
))
return
true
;
if
(
other
.
runtimeType
!=
runtimeType
)
return
false
;
final
ColorSwatch
<
T
>
typedOther
=
other
;
return
super
==(
other
)
&&
_swatch
==
typedOther
.
_swatch
;
}
@override
int
get
hashCode
=>
hashValues
(
runtimeType
,
value
,
_swatch
);
@override
String
toString
()
=>
'
$runtimeType
(primary value:
${super.toString()}
)'
;
}
packages/flutter/test/painting/colors_test.dart
View file @
2ff2274c
...
...
@@ -38,4 +38,28 @@ void main() {
expect
(
green
.
toColor
(),
equals
(
const
Color
.
fromARGB
(
0xFF
,
0x00
,
0xFF
,
0x00
)));
expect
(
blue
.
toColor
(),
equals
(
const
Color
.
fromARGB
(
0xFF
,
0x00
,
0x00
,
0xFF
)));
});
test
(
'ColorSwatch test'
,
()
{
final
int
color
=
0xFF027223
;
final
ColorSwatch
<
String
>
greens1
=
new
ColorSwatch
<
String
>(
color
,
const
<
String
,
Color
>{
'2259 C'
:
const
Color
(
0xFF027223
),
'2273 C'
:
const
Color
(
0xFF257226
),
'2426 XGC'
:
const
Color
(
0xFF00932F
),
'7732 XGC'
:
const
Color
(
0xFF007940
),
},
);
final
ColorSwatch
<
String
>
greens2
=
new
ColorSwatch
<
String
>(
color
,
const
<
String
,
Color
>{
'2259 C'
:
const
Color
(
0xFF027223
),
'2273 C'
:
const
Color
(
0xFF257226
),
'2426 XGC'
:
const
Color
(
0xFF00932F
),
'7732 XGC'
:
const
Color
(
0xFF007940
),
},
);
expect
(
greens1
,
greens2
);
expect
(
greens1
.
hashCode
,
greens2
.
hashCode
);
expect
(
greens1
[
'2259 C'
],
const
Color
(
0xFF027223
));
expect
(
greens1
.
value
,
0xFF027223
);
});
}
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