talk_popup.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import 'dart:ui';
  2. import 'package:electronic_assistant/resource/colors.gen.dart';
  3. import 'package:electronic_assistant/resource/string.gen.dart';
  4. import 'package:electronic_assistant/utils/expand.dart';
  5. import 'package:flutter/cupertino.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter_screenutil/flutter_screenutil.dart';
  8. import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
  9. import 'package:get/get.dart';
  10. import '../resource/assets.gen.dart';
  11. void showTalkPopup(Offset offset, Alignment alignment,
  12. {VoidCallback? onRename, VoidCallback? onDelete}) {
  13. SmartDialog.showAttach(
  14. targetContext: null,
  15. targetBuilder: (targetOffset, targetSize) {
  16. return offset;
  17. },
  18. animationType: SmartAnimationType.fade,
  19. usePenetrate: true,
  20. clickMaskDismiss: true,
  21. alignment: alignment,
  22. maskColor: Colors.transparent,
  23. builder: (_) {
  24. return Container(
  25. width: 128.w,
  26. decoration: BoxDecoration(
  27. color: Colors.white,
  28. border: Border.all(color: '#D8D8D8'.toColor(), width: 1), // 边框
  29. borderRadius: BorderRadius.circular(8), // 圆角
  30. boxShadow: [
  31. BoxShadow(
  32. color: Colors.black.withOpacity(0.1), // 阴影颜色
  33. spreadRadius: 2, // 阴影扩散半径
  34. blurRadius: 6, // 阴影模糊半径
  35. offset: const Offset(0, 3), // 阴影偏移量
  36. ),
  37. ],
  38. ),
  39. child: Column(
  40. children: [
  41. _createNormalItem(StringName.talkRename.tr, onItemClick: () {
  42. SmartDialog.dismiss();
  43. onRename?.call();
  44. }),
  45. Divider(color: "#F6F6F6".toColor(), height: 1),
  46. _buildDeleteItem(onDelete),
  47. ],
  48. ),
  49. );
  50. },
  51. );
  52. }
  53. GestureDetector _buildDeleteItem(VoidCallback? onDelete) {
  54. return GestureDetector(
  55. onTap: () {
  56. SmartDialog.dismiss();
  57. onDelete?.call();
  58. },
  59. child: Container(
  60. color: Colors.transparent,
  61. padding: EdgeInsets.symmetric(horizontal: _itemPadding),
  62. height: _itemHeight,
  63. child: Row(
  64. crossAxisAlignment: CrossAxisAlignment.center,
  65. children: [
  66. Text(
  67. StringName.talkDelete.tr,
  68. style: TextStyle(color: '#F5574E'.toColor(), fontSize: 14.sp),
  69. ),
  70. const Spacer(),
  71. SizedBox(
  72. width: 20.w,
  73. height: 20.w,
  74. child: Assets.images.iconTalkDelete.image())
  75. ],
  76. ),
  77. ),
  78. );
  79. }
  80. Widget _createNormalItem(String title, {VoidCallback? onItemClick}) {
  81. return GestureDetector(
  82. onTap: onItemClick,
  83. child: Container(
  84. color: Colors.transparent,
  85. padding: EdgeInsets.symmetric(horizontal: _itemPadding),
  86. height: _itemHeight,
  87. child: Align(
  88. alignment: Alignment.centerLeft,
  89. child: Text(
  90. StringName.talkRename.tr,
  91. style: TextStyle(
  92. fontSize: 14.sp,
  93. color: ColorName.primaryTextColor,
  94. ),
  95. ),
  96. ),
  97. ),
  98. );
  99. }
  100. final _itemHeight = 52.h;
  101. final _itemPadding = 14.w;