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.
 
 
 
 
 
 

158 lines
5.9 KiB

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