custom_label_dialog.dart 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import 'dart:ui';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutter_screenutil/flutter_screenutil.dart';
  5. import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
  6. import 'package:keyboard/resource/string.gen.dart';
  7. import 'package:keyboard/utils/toast_util.dart';
  8. import '../resource/assets.gen.dart';
  9. import '../resource/colors.gen.dart';
  10. import '../utils/styles.dart';
  11. class CustomLabelDialog {
  12. static const String tag = 'CustomLabelDialog';
  13. static void show({
  14. String? title,
  15. required Function(String) clickCallback,
  16. required String hintText,
  17. required int maxLength,
  18. }) {
  19. TextEditingController textController = TextEditingController();
  20. SmartDialog.show(
  21. tag: tag,
  22. backType: SmartBackType.block,
  23. clickMaskDismiss: true,
  24. maskColor: ColorName.black70,
  25. builder: (_) {
  26. return Scaffold(
  27. backgroundColor: Colors.transparent,
  28. body: Column(
  29. crossAxisAlignment: CrossAxisAlignment.center,
  30. mainAxisAlignment: MainAxisAlignment.center,
  31. children: [
  32. Container(
  33. width: double.infinity,
  34. margin: EdgeInsets.symmetric(horizontal: 31.w),
  35. decoration: ShapeDecoration(
  36. color: Colors.white,
  37. shape: RoundedRectangleBorder(
  38. borderRadius: BorderRadius.circular(20.r),
  39. ),
  40. ),
  41. child: Stack(
  42. children: [
  43. Container(
  44. padding: EdgeInsets.symmetric(
  45. horizontal: 16.w,
  46. vertical: 24.h,
  47. ),
  48. child: Column(
  49. mainAxisSize: MainAxisSize.min,
  50. crossAxisAlignment: CrossAxisAlignment.center,
  51. mainAxisAlignment: MainAxisAlignment.center,
  52. children: [
  53. Text(
  54. title ?? StringName.customLabel,
  55. style: TextStyle(
  56. color: Colors.black.withAlpha(204),
  57. fontSize: 16.sp,
  58. fontWeight: FontWeight.w500,
  59. ),
  60. ),
  61. SizedBox(height: 16.h),
  62. Container(
  63. height: 48.h,
  64. alignment: Alignment.center,
  65. decoration: ShapeDecoration(
  66. color: const Color(0xFFF5F4F9),
  67. shape: RoundedRectangleBorder(
  68. borderRadius: BorderRadius.circular(31.r),
  69. ),
  70. ),
  71. child: TextField(
  72. controller: textController,
  73. // maxLength: maxLength,
  74. maxLines: 1,
  75. textAlign: TextAlign.center,
  76. textAlignVertical: TextAlignVertical.center,
  77. decoration: InputDecoration(
  78. counterText: "",
  79. hintText: hintText,
  80. hintStyle: TextStyle(
  81. color: Colors.black.withAlpha(66),
  82. ),
  83. border: OutlineInputBorder(
  84. borderRadius: BorderRadius.circular(10.r),
  85. borderSide: BorderSide.none, // 移除边框线
  86. ),
  87. filled: true,
  88. fillColor: const Color(0xFFF5F4F9),
  89. ),
  90. ),
  91. ),
  92. SizedBox(height: 24.h),
  93. Container(
  94. height: 48.h,
  95. width: double.infinity,
  96. decoration: Styles.getActivateButtonDecoration(
  97. 31.r,
  98. ),
  99. child: TextButton(
  100. onPressed: () {
  101. if (textController.text.isEmpty) {
  102. return ToastUtil.show(hintText);
  103. }
  104. if (textController.text.length > maxLength) {
  105. return ToastUtil.show('最多$maxLength个字哦~');
  106. }
  107. clickCallback(textController.text.trim());
  108. SmartDialog.dismiss();
  109. },
  110. child: Text(
  111. StringName.customLabelSave,
  112. style: TextStyle(
  113. color: Colors.white,
  114. fontSize: 16.sp,
  115. fontWeight: FontWeight.w500,
  116. ),
  117. ),
  118. ),
  119. ),
  120. ],
  121. ),
  122. ),
  123. Positioned(
  124. right: 14,
  125. top: 14,
  126. child: GestureDetector(
  127. onTap: () {
  128. SmartDialog.dismiss();
  129. },
  130. child: Assets.images.iconCustomDialogClose.image(
  131. width: 24.w,
  132. height: 24.h,
  133. ),
  134. ),
  135. ),
  136. ],
  137. ),
  138. ),
  139. ],
  140. ),
  141. );
  142. },
  143. );
  144. }
  145. }