「Flutter/キャスト」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→色と文字列) |
(→色と文字列) |
||
| 行7: | 行7: | ||
int value = int.parse(valueString, radix: 16); | int value = int.parse(valueString, radix: 16); | ||
Color otherColor = new Color(value); | Color otherColor = new Color(value); | ||
| + | </pre> | ||
| + | |||
| + | <pre> | ||
| + | static String toStrByColor(Color color) { | ||
| + | return color.toString().split('(0x')[1].split(')')[0]; | ||
| + | } | ||
| + | static Color toColorByStr(String str) { | ||
| + | int value = int.parse(str, radix: 16); | ||
| + | return new Color(value); | ||
| + | } | ||
</pre> | </pre> | ||
2019年11月14日 (木) 01:21時点における版
色と文字列
Color color = new Color(0xff443a49);
String colorString = color.toString(); // Color(0xff443a49)
String valueString = colorString.split('(0x')[1].split(')')[0]; // ff443a49
int value = int.parse(valueString, radix: 16);
Color otherColor = new Color(value);
static String toStrByColor(Color color) {
return color.toString().split('(0x')[1].split(')')[0];
}
static Color toColorByStr(String str) {
int value = int.parse(str, radix: 16);
return new Color(value);
}
