Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

166 lignes
6.0 KiB

  1. import 'package:flutter/material.dart';
  2. import 'package:provider/provider.dart';
  3. import 'package:qadirneyriz/config/config.dart';
  4. import 'package:qadirneyriz/screens/home/state.dart';
  5. import 'package:qadirneyriz/setting/setting.dart';
  6. import 'package:qadirneyriz/utils/enums/status.dart';
  7. import 'package:qadirneyriz/utils/tools/tools.dart';
  8. import 'package:qadirneyriz/widgets/custom_appbar.dart';
  9. import 'package:flutter_gen/gen_l10n/app_localizations.dart';
  10. import 'package:qadirneyriz/widgets/custom_button.dart';
  11. import 'package:qadirneyriz/widgets/custom_textfield.dart';
  12. class ChangePassScreen extends StatefulWidget {
  13. const ChangePassScreen({super.key});
  14. @override
  15. State<ChangePassScreen> createState() => _ChangePassScreenState();
  16. }
  17. class _ChangePassScreenState extends State<ChangePassScreen> {
  18. TextEditingController nameController = TextEditingController();
  19. TextEditingController passController = TextEditingController();
  20. @override
  21. Widget build(BuildContext context) {
  22. final phone = setting.userLocalDb.getUser().mobile ?? '';
  23. final name = setting.userLocalDb.getUser().name ?? '';
  24. return Consumer<HomeState>(
  25. builder: (context, value, child) {
  26. return CustomScrollView(
  27. slivers: <Widget>[
  28. CustomAppbar(
  29. title: AppLocalizations.of(context)!.profile,
  30. ),
  31. SliverToBoxAdapter(
  32. child: Container(
  33. decoration: BoxDecoration(
  34. color: config.ui.secendGreen,
  35. boxShadow: [
  36. BoxShadow(
  37. color: config.ui.mainGray.withOpacity(.2),
  38. spreadRadius: 10,
  39. offset: const Offset(0, 5),
  40. blurRadius: 8)
  41. ],
  42. borderRadius: BorderRadius.only(
  43. bottomLeft: Radius.circular(50),
  44. bottomRight: Radius.circular(50))),
  45. child: Padding(
  46. padding: const EdgeInsets.all(30.0),
  47. child: Column(
  48. mainAxisAlignment: MainAxisAlignment.center,
  49. children: [
  50. Container(
  51. decoration: BoxDecoration(
  52. color: Colors.white.withOpacity(.2),
  53. shape: BoxShape.circle),
  54. child: Padding(
  55. padding: const EdgeInsets.all(20.0),
  56. child: Icon(
  57. Icons.person,
  58. size: 50,
  59. color: Colors.white,
  60. ),
  61. ),
  62. ),
  63. SizedBox(
  64. height: 10,
  65. ),
  66. Text(
  67. name,
  68. style: TextStyle(
  69. fontSize: 16,
  70. color: Colors.white,
  71. fontWeight: FontWeight.bold),
  72. ),
  73. SizedBox(
  74. height: 2,
  75. ),
  76. Text(
  77. phone,
  78. style: TextStyle(
  79. fontSize: 16,
  80. color: Colors.white,
  81. fontWeight: FontWeight.bold),
  82. ),
  83. ],
  84. ),
  85. ),
  86. ),
  87. ),
  88. SliverToBoxAdapter(
  89. child: Padding(
  90. padding: const EdgeInsets.symmetric(vertical: 70),
  91. child: Column(
  92. children: [
  93. CustomTextField(
  94. label: AppLocalizations.of(context)!.changename,
  95. hintText: name,
  96. textEditingController: nameController,
  97. textInputType: TextInputType.visiblePassword),
  98. CustomTextField(
  99. label: AppLocalizations.of(context)!.changepass,
  100. hintText: AppLocalizations.of(context)!.newpass,
  101. isPass: true,
  102. textEditingController: passController,
  103. textInputType: TextInputType.visiblePassword),
  104. SizedBox(
  105. height: 60,
  106. ),
  107. chnagePassMethod(value)
  108. ],
  109. ),
  110. ),
  111. )
  112. ],
  113. );
  114. },
  115. );
  116. }
  117. Widget chnagePassMethod(HomeState state) {
  118. switch (state.statusEditProfile) {
  119. case Status.loading:
  120. return CustomButton(
  121. hieght: 50, text: AppLocalizations.of(context)!.loading);
  122. default:
  123. return CustomButton(
  124. hieght: 50,
  125. text: AppLocalizations.of(context)!.submit,
  126. onPressed: () async {
  127. if (nameController.text == '' && passController.text == '') {
  128. Tools.showCustomSnackBar(
  129. text: AppLocalizations.of(context)!.doyouredit,
  130. isError: true,
  131. context,
  132. );
  133. } else {
  134. final status = await state.editProfile(
  135. name: nameController.text, pass: passController.text);
  136. if (status == Status.ready) {
  137. Tools.showCustomSnackBar(
  138. text: AppLocalizations.of(context)!.editdone,
  139. isError: false,
  140. context,
  141. );
  142. setState(() {});
  143. } else {
  144. Tools.showCustomSnackBar(
  145. text: state.errorsEditProfile == null
  146. ? state.messageEditProfile ??
  147. AppLocalizations.of(context)!.haserror
  148. : Tools.combineErrorMessages(
  149. state.errorsEditProfile ?? {}),
  150. isError: true,
  151. context,
  152. );
  153. }
  154. }
  155. },
  156. );
  157. }
  158. }
  159. }