Line data Source code
1 : // Copyright 2023 The terCAD team. All rights reserved.
2 : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
3 :
4 : import 'dart:math';
5 :
6 : import 'package:app_finance/_configs/theme_helper.dart';
7 : import 'package:app_finance/_ext/build_context_ext.dart';
8 : import 'package:app_finance/components/_core/component_data.dart';
9 : import 'package:material_ui/material_ui.dart';
10 :
11 : class DraggablePointer extends StatefulWidget {
12 : final Map<String, dynamic> data;
13 : final bool topLeft;
14 : final Function()? onDragStarted;
15 : final Function(DraggableDetails)? onDragEnd;
16 :
17 0 : const DraggablePointer(
18 : this.data, {
19 : super.key,
20 : required this.onDragStarted,
21 : required this.onDragEnd,
22 : this.topLeft = true,
23 : });
24 :
25 0 : @override
26 0 : DraggablePointerState createState() => DraggablePointerState();
27 : }
28 :
29 : class DraggablePointerState extends State<DraggablePointer> {
30 : Color? color;
31 :
32 0 : @override
33 : Widget build(BuildContext context) {
34 0 : final colorScheme = context.colorScheme;
35 0 : final border = BorderSide(width: 4, color: context.colorScheme.primary);
36 0 : final size = [ThemeHelper.getHeight(context) / 3, ThemeHelper.getWidth(context) / 3].reduce(min);
37 0 : return Container(
38 0 : margin: EdgeInsets.all(ThemeHelper.getIndent(0.1)),
39 0 : child: Draggable<ComponentData>(
40 0 : data: widget.data,
41 0 : onDragEnd: widget.onDragEnd,
42 0 : onDragStarted: widget.onDragStarted,
43 0 : feedback: Transform.translate(
44 0 : offset: widget.topLeft ? Offset.zero : Offset(-size, -size),
45 0 : child: Container(
46 0 : decoration: BoxDecoration(
47 0 : border: Border(
48 0 : top: widget.topLeft ? border : BorderSide.none,
49 0 : left: widget.topLeft ? border : BorderSide.none,
50 0 : bottom: widget.topLeft ? BorderSide.none : border,
51 0 : right: widget.topLeft ? BorderSide.none : border,
52 : ),
53 : ),
54 : height: size,
55 : width: size,
56 : ),
57 : ),
58 0 : child: MouseRegion(
59 : cursor: SystemMouseCursors.resizeDownRight,
60 0 : onEnter: (_) => setState(() => color = colorScheme.primary.withValues(alpha: 0.5)),
61 0 : onExit: (_) => setState(() => color = null),
62 0 : child: Container(
63 0 : decoration: BoxDecoration(
64 : shape: BoxShape.circle,
65 0 : color: color ?? context.colorScheme.secondary.withValues(alpha: 0.4),
66 : ),
67 : ),
68 : ),
69 : ),
70 : );
71 : }
72 : }
|