drag_delete_area.dart 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import 'package:fis_i18n/i18n.dart';
  2. import 'package:fis_measure/interfaces/process/workspace/application.dart';
  3. import 'package:fis_measure/process/workspace/measure_data_controller.dart';
  4. import 'package:fis_measure/utils/prompt_box.dart';
  5. import 'package:fis_ui/index.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:get/get.dart';
  8. class DragDeleteArea extends FStatefulWidget {
  9. const DragDeleteArea({Key? key}) : super(key: key);
  10. @override
  11. FState<DragDeleteArea> createState() => DragDeleteAreaState();
  12. }
  13. class DragDeleteAreaState extends FState<DragDeleteArea> {
  14. final measureData = Get.find<MeasureDataController>();
  15. bool _isDragOn = false;
  16. @override
  17. void initState() {
  18. super.initState();
  19. }
  20. @override
  21. void dispose() {
  22. super.dispose();
  23. }
  24. @override
  25. FWidget build(BuildContext context) {
  26. return FDragTarget<String>(
  27. onAccept: (data) async {
  28. measureData.annotationList.remove(data);
  29. final application = Get.find<IApplication>();
  30. final result = await measureData.deleteAnnotation(application, data);
  31. if (result ?? false) {
  32. PromptBox.toast(i18nBook.measure.annotationDeleted.translate([data]));
  33. }
  34. setState(() {
  35. _isDragOn = false;
  36. });
  37. },
  38. onWillAccept: (data) {
  39. setState(() {
  40. _isDragOn = true;
  41. });
  42. return true;
  43. },
  44. onLeave: (data) {
  45. setState(() {
  46. _isDragOn = false;
  47. });
  48. },
  49. builder: (context, candidateData, rejectedData) {
  50. return FContainer(
  51. width: 300,
  52. height: 50,
  53. padding: const EdgeInsets.only(left: 10, top: 5, bottom: 5),
  54. child: FContainer(
  55. decoration: BoxDecoration(
  56. color: const Color.fromARGB(255, 243, 108, 99),
  57. borderRadius: BorderRadius.circular(5),
  58. ),
  59. child: FCenter(
  60. child:
  61. FRow(mainAxisAlignment: MainAxisAlignment.center, children: [
  62. const FIcon(
  63. Icons.delete,
  64. color: Colors.white,
  65. ),
  66. FText(
  67. _isDragOn
  68. ? i18nBook.measure.releaseToDelete.t
  69. : i18nBook.measure.dragHereToDelete.t,
  70. textAlign: TextAlign.center,
  71. style: const TextStyle(color: Colors.white),
  72. ),
  73. ]),
  74. ),
  75. ),
  76. );
  77. },
  78. );
  79. }
  80. }