No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

203 líneas
6.9 KiB

  1. // ignore_for_file: public_member_api_docs, sort_constructors_first
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_gen/gen_l10n/app_localizations.dart';
  4. import 'package:go_router/go_router.dart';
  5. import 'package:provider/provider.dart';
  6. import 'package:qadirneyriz/global_state/global_state.dart';
  7. import 'package:qadirneyriz/screens/meeting_edit/screen.dart';
  8. import 'package:qadirneyriz/utils/enums/status.dart';
  9. import 'package:qadirneyriz/utils/tools/tools.dart';
  10. import 'package:qadirneyriz/widgets/ExpansionTileCustom.dart';
  11. import 'package:qadirneyriz/widgets/custom_button.dart';
  12. import 'package:qadirneyriz/widgets/custom_textfield.dart';
  13. class AddUserDiolog extends StatefulWidget {
  14. AddUserDiolog({
  15. super.key,
  16. });
  17. @override
  18. State<AddUserDiolog> createState() => _AddUserDiologState();
  19. }
  20. class _AddUserDiologState extends State<AddUserDiolog> {
  21. final TextEditingController nameController = TextEditingController();
  22. final TextEditingController mobileController = TextEditingController();
  23. final TextEditingController passwordController = TextEditingController();
  24. int? selectedRole;
  25. final List<MemberRole> roles = [
  26. MemberRole(roleId: 1, roleName: 'کاربر معمولی'),
  27. MemberRole(roleId: 2, roleName: 'اپراتور'),
  28. ];
  29. @override
  30. Widget build(BuildContext context) {
  31. return Consumer<GlobalState>(
  32. builder: (context, value, child) {
  33. return Dialog(
  34. child: Padding(
  35. padding: const EdgeInsets.all(20.0),
  36. child: SingleChildScrollView(
  37. child: Column(
  38. mainAxisSize: MainAxisSize.min, // برای اندازه‌گیری درست دیالوگ
  39. children: [
  40. Text('عضو جدید'),
  41. CustomTextField(
  42. label: '',
  43. hintText: 'نام و نام خانوادگی',
  44. paddingVertical: 0,
  45. textEditingController: nameController,
  46. textInputType: TextInputType.text),
  47. CustomTextField(
  48. label: '',
  49. paddingVertical: 0,
  50. hintText: 'شماره موبایل',
  51. textEditingController: mobileController,
  52. textInputType: TextInputType.phone),
  53. CustomTextField(
  54. label: '',
  55. paddingVertical: 0,
  56. hintText: 'رمز عبور',
  57. isPass: true,
  58. textEditingController: passwordController,
  59. textInputType: TextInputType.visiblePassword),
  60. Padding(
  61. padding: const EdgeInsets.symmetric(horizontal: 20),
  62. child: ExpansionTileCustom(
  63. isForm: true,
  64. subTitile: '',
  65. title: 'نقش کاربر',
  66. widgets: <Widget>[
  67. Column(
  68. children: roles.map((role) {
  69. bool isSelected = selectedRole == role.roleId;
  70. return ItemInTile(
  71. backColor:
  72. isSelected ? Color(0xff06CF64) : Colors.white,
  73. textColor:
  74. isSelected ? Colors.white : Colors.black,
  75. text: role.roleName,
  76. hasIcon: false,
  77. onTap: () {
  78. setState(() {
  79. selectedRole = role.roleId;
  80. });
  81. },
  82. );
  83. }).toList(),
  84. ),
  85. ],
  86. ),
  87. ),
  88. SizedBox(
  89. height: 60,
  90. ),
  91. submit(value, context),
  92. ],
  93. ),
  94. ),
  95. ),
  96. );
  97. },
  98. );
  99. }
  100. CustomButton submit(GlobalState state, BuildContext context) {
  101. switch (state.statusAddNewUser) {
  102. case Status.loading:
  103. return CustomButton(
  104. hieght: 40,
  105. width: double.infinity,
  106. text: AppLocalizations.of(context)!.loading,
  107. fontSize: 13,
  108. onPressed: null,
  109. topRightRadius: 10,
  110. topLeftRadius: 10,
  111. bottomLeftRadius: 10,
  112. bottomRightRadius: 10,
  113. );
  114. default:
  115. return CustomButton(
  116. hieght: 40,
  117. width: double.infinity,
  118. text: 'اظافه کردن',
  119. fontSize: 13,
  120. onPressed: () async {
  121. if (nameController.text == '') {
  122. // call add new subject
  123. Tools.showCustomSnackBar(
  124. text: 'اسم وارد کنید!',
  125. isError: true,
  126. context,
  127. );
  128. } else if (mobileController.text == '') {
  129. Tools.showCustomSnackBar(
  130. text: 'موبایل وارد کنید!',
  131. isError: true,
  132. context,
  133. );
  134. } else if (passwordController.text == '') {
  135. Tools.showCustomSnackBar(
  136. text: 'پسورد وارد کنید!',
  137. isError: true,
  138. context,
  139. );
  140. } else if (selectedRole == null) {
  141. Tools.showCustomSnackBar(
  142. text: 'نقش کاربر وارد کنید!',
  143. isError: true,
  144. context,
  145. );
  146. } else {
  147. final status = await state.addNewUser(
  148. name: nameController.text,
  149. mobile: mobileController.text,
  150. role: selectedRole!,
  151. password: passwordController.text);
  152. if (status == Status.ready) {
  153. // call refrresh users
  154. await state.getUsers(refresh: true);
  155. Tools.showCustomSnackBar(
  156. text: 'کاربر اظافه شد!',
  157. isError: false,
  158. context,
  159. );
  160. context.pop();
  161. } else {
  162. Tools.showCustomSnackBar(
  163. text: state.errorsAddNewUser == null
  164. ? state.messageAddNewUser ??
  165. AppLocalizations.of(context)!.haserror
  166. : Tools.combineErrorMessages(
  167. state.errorsAddNewUser ?? {}),
  168. isError: true,
  169. context,
  170. );
  171. }
  172. }
  173. },
  174. topRightRadius: 10,
  175. topLeftRadius: 10,
  176. bottomLeftRadius: 10,
  177. bottomRightRadius: 10,
  178. );
  179. }
  180. }
  181. }
  182. class MemberRole {
  183. final int roleId;
  184. final String roleName;
  185. MemberRole({
  186. required this.roleId,
  187. required this.roleName,
  188. });
  189. }