custom_label_dialog.dart 6.0 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: null,
  75. expands: true,
  76. textAlign: TextAlign.center,
  77. textAlignVertical: TextAlignVertical.center,
  78. decoration: InputDecoration(
  79. counterText: "",
  80. hintText: hintText,
  81. hintStyle: TextStyle(
  82. color: Colors.black.withAlpha(66),
  83. ),
  84. border: OutlineInputBorder(
  85. borderRadius: BorderRadius.circular(10.r),
  86. borderSide: BorderSide.none, // 移除边框线
  87. ),
  88. filled: true,
  89. fillColor: const Color(0xFFF5F4F9),
  90. ),
  91. ),
  92. ),
  93. SizedBox(height: 24.h),
  94. Container(
  95. height: 48.h,
  96. width: double.infinity,
  97. decoration: Styles.getActivateButtonDecoration(
  98. 31.r,
  99. ),
  100. child: TextButton(
  101. onPressed: () {
  102. if (textController.text.isEmpty) {
  103. return ToastUtil.show(hintText);
  104. }
  105. if (textController.text.length > maxLength) {
  106. return ToastUtil.show('最多$maxLength个字哦~');
  107. }
  108. clickCallback(textController.text.trim());
  109. SmartDialog.dismiss();
  110. },
  111. child: Text(
  112. StringName.customLabelSave,
  113. style: TextStyle(
  114. color: Colors.white,
  115. fontSize: 16.sp,
  116. fontWeight: FontWeight.w500,
  117. ),
  118. ),
  119. ),
  120. ),
  121. ],
  122. ),
  123. ),
  124. Positioned(
  125. right: 14,
  126. top: 14,
  127. child: GestureDetector(
  128. onTap: () {
  129. SmartDialog.dismiss();
  130. },
  131. child: Assets.images.iconCustomDialogClose.image(
  132. width: 24.w,
  133. height: 24.h,
  134. ),
  135. ),
  136. ),
  137. ],
  138. ),
  139. ),
  140. ],
  141. ),
  142. );
  143. },
  144. );
  145. }
  146. }