-
Notifications
You must be signed in to change notification settings - Fork 223
/
color_picker.dart
115 lines (103 loc) · 4.16 KB
/
color_picker.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import 'package:flutter_ume_kit_ui/third_party/cyclop/lib/cyclop.dart';
import 'package:flutter/material.dart';
import 'package:flutter_ume/flutter_ume.dart';
import 'icon.dart' as icon;
class ColorPicker extends StatefulWidget implements PluggableWithNestedWidget {
const ColorPicker({Key? key}) : super(key: key);
@override
_ColorPickerState createState() => _ColorPickerState();
@override
Widget buildWidget(BuildContext? context) => this;
@override
String get name => 'ColorPicker';
@override
String get displayName => 'TouchIndicator';
@override
void onTrigger() {}
@override
ImageProvider<Object> get iconImageProvider => MemoryImage(icon.iconBytes);
@override
Widget buildNestedWidget(Widget child) {
return EyeDrop(child: child);
}
}
class _ColorPickerState extends State<ColorPicker> {
final colorTextStyle = TextStyle(
fontFamily: "Monospace", fontWeight: FontWeight.bold, fontSize: 20);
Color? _color;
bool _panelDown = true;
@override
Widget build(BuildContext context) {
return Listener(
onPointerDown: (downEvent) {},
onPointerMove: (moveEvent) {
setState(() => _panelDown =
moveEvent.position.dy < MediaQuery.of(context).size.height * 0.5);
},
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
color: Colors.transparent,
child: Align(
alignment:
_panelDown ? Alignment.bottomCenter : Alignment.topCenter,
child: Padding(
padding: const EdgeInsets.only(top: 28, bottom: 28),
child: Container(
decoration: ShapeDecoration(
shape: StadiumBorder(),
color: Colors.white,
shadows: [
BoxShadow(color: Colors.black54, blurRadius: 12),
],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
CircleAvatar(
radius: 40,
backgroundColor: _color,
child: EyedropperButton(
onColor: (color) => setState(() => _color = color),
onColorChanged: (color) =>
setState(() => _color = color),
)),
GestureDetector(
onTap: () {
debugPrint(_color?.hexARGB.toString());
},
child: Padding(
padding: const EdgeInsets.only(left: 8, right: 18.0),
child: RichText(
text: TextSpan(children: [
TextSpan(
text:
'${_color?.hexARGB.toString().substring(0, 2) ?? '👈🏻Tap to pick'}',
style: colorTextStyle.copyWith(
color: Colors.grey)),
TextSpan(
text:
'${_color?.hexARGB.toString().substring(2, 4) ?? ''}',
style:
colorTextStyle.copyWith(color: Colors.red)),
TextSpan(
text:
'${_color?.hexARGB.toString().substring(4, 6) ?? ''}',
style: colorTextStyle.copyWith(
color: Colors.green)),
TextSpan(
text:
'${_color?.hexARGB.toString().substring(6, 8) ?? ''}',
style: colorTextStyle.copyWith(
color: Colors.blue)),
])),
),
)
],
)),
)),
),
);
}
}