2022-11-17 10:39:06 +00:00
|
|
|
import 'dart:math';
|
|
|
|
|
2022-10-23 15:57:59 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2022-11-03 15:43:50 +00:00
|
|
|
import '../canvas/document_types.dart';
|
2022-10-29 20:55:38 +00:00
|
|
|
import '../canvas/drawing_page.dart';
|
2022-11-17 10:39:06 +00:00
|
|
|
import '../helpers/vibrate.dart';
|
2022-10-29 19:39:08 +00:00
|
|
|
|
2022-10-23 15:57:59 +00:00
|
|
|
class NoteTile extends StatelessWidget {
|
2022-11-17 10:39:06 +00:00
|
|
|
const NoteTile(
|
|
|
|
{Key? key,
|
|
|
|
required this.data,
|
|
|
|
required this.selectionMode,
|
|
|
|
required this.selected,
|
|
|
|
required this.onSelectionChange})
|
|
|
|
: super(key: key);
|
2022-10-29 19:39:08 +00:00
|
|
|
|
2022-11-04 22:09:50 +00:00
|
|
|
final NoteMetaData data;
|
2022-11-17 10:39:06 +00:00
|
|
|
final bool selectionMode;
|
|
|
|
final bool selected;
|
|
|
|
final void Function(bool) onSelectionChange;
|
2022-10-23 15:57:59 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-10-29 19:39:08 +00:00
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
2022-11-17 10:39:06 +00:00
|
|
|
if (selectionMode) {
|
|
|
|
onSelectionChange(!selected);
|
|
|
|
} else {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => DrawingPage(meta: data),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-10-29 19:39:08 +00:00
|
|
|
},
|
2022-11-17 10:39:06 +00:00
|
|
|
onLongPress: () async {
|
|
|
|
shortVibrate();
|
|
|
|
onSelectionChange(!selected);
|
|
|
|
},
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(20),
|
2022-10-29 19:39:08 +00:00
|
|
|
child: Column(
|
|
|
|
children: [
|
2022-11-17 10:39:06 +00:00
|
|
|
Expanded(
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: 1 / sqrt2,
|
|
|
|
child: Container(
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (selectionMode)
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 10, top: 10),
|
|
|
|
child: CustomPaint(
|
|
|
|
size: const Size(25, 25),
|
|
|
|
painter: _CirclePainter(selected),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
2022-10-29 19:39:08 +00:00
|
|
|
),
|
|
|
|
),
|
2022-11-17 10:39:06 +00:00
|
|
|
const SizedBox(
|
|
|
|
height: 5,
|
|
|
|
),
|
2022-10-29 19:39:08 +00:00
|
|
|
Text(
|
|
|
|
data.name,
|
|
|
|
style: const TextStyle(color: Colors.white),
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
|
|
|
Text('${data.lastModified.hour}:${data.lastModified.minute}',
|
|
|
|
style: const TextStyle(color: Colors.white))
|
|
|
|
],
|
|
|
|
),
|
2022-10-23 15:57:59 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-11-17 10:39:06 +00:00
|
|
|
|
|
|
|
class _CirclePainter extends CustomPainter {
|
|
|
|
final bool selected;
|
|
|
|
|
|
|
|
final _paint = Paint()..strokeWidth = .7;
|
|
|
|
|
|
|
|
_CirclePainter(this.selected) {
|
|
|
|
if (selected) {
|
|
|
|
_paint.color = Colors.orange;
|
|
|
|
_paint.style = PaintingStyle.fill;
|
|
|
|
} else {
|
|
|
|
_paint.color = Colors.black;
|
|
|
|
_paint.style = PaintingStyle.stroke;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void paint(Canvas canvas, Size size) {
|
|
|
|
canvas.drawOval(
|
|
|
|
Rect.fromLTWH(0, 0, size.width, size.height),
|
|
|
|
_paint,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool shouldRepaint(_CirclePainter oldDelegate) =>
|
|
|
|
oldDelegate.selected != selected;
|
|
|
|
}
|