Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

176 wiersze
6.9 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/auth/state/state.dart';
  5. import 'package:qadirneyriz/utils/enums/status.dart';
  6. import 'package:qadirneyriz/utils/tools/tools.dart';
  7. import 'package:qadirneyriz/widgets/custom_button.dart';
  8. import 'package:qadirneyriz/widgets/custom_textfield.dart';
  9. import 'package:go_router/go_router.dart';
  10. import 'package:flutter_gen/gen_l10n/app_localizations.dart';
  11. class LoginScreen extends StatefulWidget {
  12. const LoginScreen({super.key});
  13. @override
  14. State<LoginScreen> createState() => _LoginScreenState();
  15. }
  16. class _LoginScreenState extends State<LoginScreen> {
  17. TextEditingController phoneController = TextEditingController();
  18. TextEditingController passwordController = TextEditingController();
  19. @override
  20. Widget build(BuildContext context) {
  21. return Scaffold(
  22. body: Consumer<AuthState>(
  23. builder: (context, value, child) {
  24. return CustomScrollView(
  25. slivers: <Widget>[
  26. SliverToBoxAdapter(
  27. child: Container(
  28. height: 30,
  29. color: config.ui.mainGreen,
  30. ),
  31. ),
  32. // Header Image with cut-out shape at the bottom
  33. SliverToBoxAdapter(
  34. child: ClipPath(
  35. child: Image.asset(
  36. 'assets/images/template.png',
  37. width: double.infinity,
  38. fit: BoxFit.cover,
  39. ),
  40. ),
  41. ),
  42. // Form section with inputs and buttons
  43. SliverPadding(
  44. padding: const EdgeInsets.symmetric(horizontal: 20),
  45. sliver: SliverToBoxAdapter(
  46. child: Column(
  47. children: [
  48. Container(
  49. padding: const EdgeInsets.all(16),
  50. decoration: BoxDecoration(
  51. color: Colors.white,
  52. borderRadius: BorderRadius.circular(16),
  53. boxShadow: [
  54. BoxShadow(
  55. color:
  56. Colors.black.withOpacity(0.1), // light shadow
  57. blurRadius: 10,
  58. spreadRadius: 5,
  59. ),
  60. ],
  61. ),
  62. child: Column(
  63. crossAxisAlignment: CrossAxisAlignment.stretch,
  64. children: [
  65. // Username field
  66. CustomTextField(
  67. label: AppLocalizations.of(context)!.phonenumber,
  68. hintText:
  69. AppLocalizations.of(context)!.hintphonenumber,
  70. textEditingController: phoneController,
  71. textInputType: TextInputType.phone,
  72. textInputAction: TextInputAction.next,
  73. ),
  74. const SizedBox(height: 16),
  75. // Password field
  76. CustomTextField(
  77. isPass: true,
  78. label: AppLocalizations.of(context)!.password,
  79. hintText: AppLocalizations.of(context)!.hintpass,
  80. textEditingController: passwordController,
  81. textInputType: TextInputType.visiblePassword,
  82. ),
  83. const SizedBox(height: 40),
  84. // Buttons section
  85. Row(
  86. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  87. children: [
  88. // Login button (filled)
  89. CustomButton(
  90. hieght: 56,
  91. fontSize: 13,
  92. text: AppLocalizations.of(context)!
  93. .submitwithotp,
  94. color: Colors.white,
  95. textColor: Colors.green,
  96. onPressed:
  97. value.statusLogin == Status.loading
  98. ? null
  99. : () {
  100. context.pushNamed('loginotp');
  101. }),
  102. const SizedBox(width: 16),
  103. // Register button (outlined)
  104. Expanded(
  105. child: submitButton(context, value),
  106. ),
  107. ],
  108. ),
  109. ],
  110. ),
  111. ),
  112. const SizedBox(height: 40),
  113. ],
  114. ),
  115. ),
  116. ),
  117. ],
  118. );
  119. },
  120. ),
  121. );
  122. }
  123. CustomButton submitButton(BuildContext context, AuthState state) {
  124. switch (state.statusLogin) {
  125. case Status.loading:
  126. return CustomButton(
  127. hieght: 56,
  128. fontSize: 12,
  129. text: AppLocalizations.of(context)!.loading,
  130. onPressed: null);
  131. default:
  132. return CustomButton(
  133. hieght: 56,
  134. fontSize: 16,
  135. text: AppLocalizations.of(context)!.submit,
  136. onPressed: () async {
  137. if (phoneController.text == '') {
  138. Tools.showCustomSnackBar(
  139. text: AppLocalizations.of(context)!.phoneerror,
  140. isError: true,
  141. context,
  142. );
  143. } else if (passwordController.text == '') {
  144. Tools.showCustomSnackBar(
  145. text: AppLocalizations.of(context)!.passerror,
  146. isError: true,
  147. context,
  148. );
  149. } else {
  150. final status = await state.login(
  151. mobile: phoneController.text,
  152. password: passwordController.text);
  153. if (status == Status.ready) {
  154. context.goNamed('navigate', pathParameters: {'tab': '0'});
  155. } else {
  156. Tools.showCustomSnackBar(
  157. text: state.errorsLogin == null
  158. ? state.messageLogin ??
  159. AppLocalizations.of(context)!.haserror
  160. : Tools.combineErrorMessages(state.errorsLogin ?? {}),
  161. isError: true,
  162. context,
  163. );
  164. }
  165. }
  166. },
  167. );
  168. }
  169. }
  170. }