You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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