talk_popup.dart 3.0 KB

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