custom_label_dialog.dart 5.4 KB

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