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.
 
 
 
 
 
 

175 Zeilen
6.8 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. ),
  73. const SizedBox(height: 16),
  74. // Password field
  75. CustomTextField(
  76. isPass: true,
  77. label: AppLocalizations.of(context)!.password,
  78. hintText: AppLocalizations.of(context)!.hintpass,
  79. textEditingController: passwordController,
  80. textInputType: TextInputType.visiblePassword,
  81. ),
  82. const SizedBox(height: 40),
  83. // Buttons section
  84. Row(
  85. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  86. children: [
  87. // Login button (filled)
  88. CustomButton(
  89. hieght: 56,
  90. fontSize: 13,
  91. text: AppLocalizations.of(context)!
  92. .submitwithotp,
  93. color: Colors.white,
  94. textColor: Colors.green,
  95. onPressed:
  96. value.statusLogin == Status.loading
  97. ? null
  98. : () {
  99. context.pushNamed('loginotp');
  100. }),
  101. const SizedBox(width: 16),
  102. // Register button (outlined)
  103. Expanded(
  104. child: submitButton(context, value),
  105. ),
  106. ],
  107. ),
  108. ],
  109. ),
  110. ),
  111. const SizedBox(height: 40),
  112. ],
  113. ),
  114. ),
  115. ),
  116. ],
  117. );
  118. },
  119. ),
  120. );
  121. }
  122. CustomButton submitButton(BuildContext context, AuthState state) {
  123. switch (state.statusLogin) {
  124. case Status.loading:
  125. return CustomButton(
  126. hieght: 56,
  127. fontSize: 12,
  128. text: AppLocalizations.of(context)!.loading,
  129. onPressed: null);
  130. default:
  131. return CustomButton(
  132. hieght: 56,
  133. fontSize: 16,
  134. text: AppLocalizations.of(context)!.submit,
  135. onPressed: () async {
  136. if (phoneController.text == '') {
  137. Tools.showCustomSnackBar(
  138. text: AppLocalizations.of(context)!.phoneerror,
  139. isError: true,
  140. context,
  141. );
  142. } else if (passwordController.text == '') {
  143. Tools.showCustomSnackBar(
  144. text: AppLocalizations.of(context)!.passerror,
  145. isError: true,
  146. context,
  147. );
  148. } else {
  149. final status = await state.login(
  150. mobile: phoneController.text,
  151. password: passwordController.text);
  152. if (status == Status.ready) {
  153. context.goNamed('navigate', pathParameters: {'tab': '0'});
  154. } else {
  155. Tools.showCustomSnackBar(
  156. text: state.errorsLogin == null
  157. ? state.messageLogin ??
  158. AppLocalizations.of(context)!.haserror
  159. : Tools.combineErrorMessages(state.errorsLogin ?? {}),
  160. isError: true,
  161. context,
  162. );
  163. }
  164. }
  165. },
  166. );
  167. }
  168. }
  169. }