Skip to content

Commit 1f70986

Browse files
`Part 13 - Color Picker
1 parent 716a701 commit 1f70986

2 files changed

Lines changed: 75 additions & 1 deletion

File tree

lib/screen/note_detail_page.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:drift/drift.dart' as dr;
22
import 'package:flutter/material.dart';
33
import 'package:note_keeper/database/database.dart';
4+
import 'package:note_keeper/util/color_picker.dart';
45
import 'package:note_keeper/util/priority_picker.dart';
56
import 'package:provider/provider.dart';
67

@@ -36,6 +37,7 @@ class _NoteDetailPageState extends State<NoteDetailPage> {
3637
Widget build(BuildContext context) {
3738
appDatabase = Provider.of<AppDatabase>(context);
3839
return Scaffold(
40+
backgroundColor: colors[colorLevel],
3941
appBar: _getDetailAppBar(),
4042
body: Container(
4143
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
@@ -50,6 +52,16 @@ class _NoteDetailPageState extends State<NoteDetailPage> {
5052
const SizedBox(
5153
height: 10,
5254
),
55+
ColorPicker(
56+
index: colorLevel,
57+
onTap: (selectedColor) {
58+
colorLevel = selectedColor;
59+
setState(() {});
60+
},
61+
),
62+
const SizedBox(
63+
height: 10,
64+
),
5365
TextFormField(
5466
controller: titleEditingController,
5567
decoration: InputDecoration(
@@ -80,7 +92,7 @@ class _NoteDetailPageState extends State<NoteDetailPage> {
8092

8193
_getDetailAppBar() {
8294
return AppBar(
83-
backgroundColor: Colors.white,
95+
backgroundColor: colors[colorLevel],
8496
elevation: 0,
8597
leading: IconButton(
8698
onPressed: () {

lib/util/color_picker.dart

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import 'package:flutter/cupertino.dart';
2+
import 'package:flutter/material.dart';
3+
4+
List<Color> colors = const [
5+
Color(0xFFFFFFFF),
6+
Color(0xffF28B83),
7+
Color(0xFFFCBC05),
8+
Color(0xFFFFF476),
9+
Color(0xFFCBFF90),
10+
Color(0xFFA7FEEA),
11+
Color(0xFFE6C9A9),
12+
Color(0xFFE8EAEE),
13+
Color(0xFFA7FEEA),
14+
Color(0xFFCAF0F8)
15+
];
16+
17+
class ColorPicker extends StatefulWidget {
18+
int index;
19+
final Function(int) onTap;
20+
ColorPicker({Key? key, required this.index, required this.onTap})
21+
: super(key: key);
22+
23+
@override
24+
_ColorPickerState createState() => _ColorPickerState();
25+
}
26+
27+
class _ColorPickerState extends State<ColorPicker> {
28+
@override
29+
Widget build(BuildContext context) {
30+
return SizedBox(
31+
height: 30,
32+
child: ListView.builder(
33+
scrollDirection: Axis.horizontal,
34+
itemCount: colors.length,
35+
itemBuilder: (context, index) {
36+
return InkWell(
37+
onTap: () {
38+
widget.index = index;
39+
widget.onTap(index);
40+
setState(() {});
41+
},
42+
child: Stack(
43+
alignment: Alignment.center,
44+
children: [
45+
Container(
46+
margin: const EdgeInsets.symmetric(horizontal: 5),
47+
width: 30,
48+
height: 30,
49+
decoration: BoxDecoration(
50+
borderRadius: BorderRadius.circular(15),
51+
border: Border.all(color: Colors.black, width: 2),
52+
color: colors[index]),
53+
),
54+
widget.index == index ? const Icon(Icons.check) : Container()
55+
],
56+
),
57+
);
58+
},
59+
),
60+
);
61+
}
62+
}

0 commit comments

Comments
 (0)