Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

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