log_in_view.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. // ignore_for_file: unused_local_variable, must_be_immutable
  2. // import packages
  3. import 'package:toast/toast.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:provider/provider.dart';
  6. import 'package:flutter/cupertino.dart';
  7. import 'package:gozap_package/components/common.dart';
  8. import 'package:gozap_package/components/responsive.dart';
  9. import 'package:gozap_package/components/themes/themes.dart';
  10. import 'package:gozap_package/views/signup/signup_view.dart';
  11. import 'package:flutter_form_builder/flutter_form_builder.dart';
  12. import 'package:form_field_validator/form_field_validator.dart';
  13. // import models
  14. import 'package:gozap_package/models/log_in/log_in_model.dart';
  15. // import controllers
  16. import 'package:gozap_package/controllers/log_in/log_in_controller.dart';
  17. // import translation
  18. import 'package:gozap_package/components/localization/app_translations.dart';
  19. class LogInView extends StatefulWidget {
  20. LogInView({
  21. super.key,
  22. required this.nextScreen,
  23. });
  24. Widget nextScreen;
  25. @override
  26. State<LogInView> createState() => _LogInViewState();
  27. }
  28. class _LogInViewState extends State<LogInView> {
  29. final _globalLogin = GlobalKey<FormBuilderState>();
  30. bool _obscureTextLogin = true;
  31. @override
  32. Widget build(BuildContext context) {
  33. LogInController viewController = LogInController();
  34. return ChangeNotifierProvider<LogInModel>(
  35. create: (context) => LogInModel.instance(context,widget.nextScreen),
  36. child: Consumer<LogInModel>(
  37. builder: (context, viewModel, child) {
  38. if (viewModel.status == LogInModelStatus.Loading) {
  39. return const Center(
  40. child: CircularProgressIndicator(),
  41. );
  42. } else {
  43. var loginFormWidget = Container(
  44. constraints: const BoxConstraints(maxWidth: 400),
  45. padding: const EdgeInsets.all(20),
  46. child: Column(
  47. children: [
  48. //login form
  49. FormBuilder(
  50. key: _globalLogin,
  51. onChanged: () {
  52. _globalLogin.currentState!.save();
  53. },
  54. child: Column(
  55. children: <Widget>[
  56. //rider ID / Phone Number
  57. FormBuilderTextField(
  58. name: "phonenumber",
  59. inputFormatters: const [],
  60. validator: MultiValidator([
  61. RequiredValidator(
  62. errorText: AppTranslations.of(context)!
  63. .text("key_field_requird")),
  64. ]),
  65. keyboardType: TextInputType.number,
  66. textInputAction: TextInputAction.done,
  67. decoration: InputDecoration(
  68. border: OutlineInputBorder(
  69. borderRadius: BorderRadius.circular(20.0),
  70. ),
  71. errorBorder: OutlineInputBorder(
  72. borderRadius: BorderRadius.circular(20.0),
  73. borderSide: const BorderSide(
  74. color: Colors.red, width: 0.0),
  75. ),
  76. fillColor: Colors.white,
  77. filled: true,
  78. prefixIcon: const Icon(
  79. CupertinoIcons.person,
  80. color: Colors.black,
  81. size: 15.0,
  82. ),
  83. hintText: AppTranslations.of(context)!
  84. .text("key_login_field_RiderID_or_PhoneNumber"),
  85. ),
  86. ),
  87. const SizedBox(
  88. height: 20,
  89. ),
  90. //Password
  91. FormBuilderTextField(
  92. name: "password",
  93. validator: MultiValidator([
  94. RequiredValidator(
  95. errorText: AppTranslations.of(context)!
  96. .text("key_field_requird")),
  97. ]),
  98. keyboardType: TextInputType.text,
  99. textInputAction: TextInputAction.done,
  100. obscureText: _obscureTextLogin,
  101. decoration: InputDecoration(
  102. border: OutlineInputBorder(
  103. borderRadius: BorderRadius.circular(20.0),
  104. ),
  105. errorBorder: OutlineInputBorder(
  106. borderRadius: BorderRadius.circular(20.0),
  107. borderSide: const BorderSide(
  108. color: Colors.red, width: 0.0),
  109. ),
  110. fillColor: Colors.white,
  111. filled: true,
  112. prefixIcon: const Icon(
  113. CupertinoIcons.lock_fill,
  114. color: Colors.black,
  115. size: 15.0,
  116. ),
  117. suffixIcon: GestureDetector(
  118. onTap: () {
  119. setState(() {
  120. _obscureTextLogin = !_obscureTextLogin;
  121. });
  122. },
  123. child: Icon(
  124. _obscureTextLogin
  125. ? CupertinoIcons.eye
  126. : CupertinoIcons.eye_slash_fill,
  127. color: Colors.black,
  128. size: 22.0,
  129. ),
  130. ),
  131. hintText: AppTranslations.of(context)!
  132. .text("key_login_field_Password"),
  133. ),
  134. ),
  135. const SizedBox(
  136. height: 20,
  137. ),
  138. //Login Button
  139. SizedBox(
  140. width: double.infinity,
  141. child: ElevatedButton(
  142. style: ButtonStyle(
  143. shape: MaterialStateProperty.all(
  144. RoundedRectangleBorder(
  145. borderRadius: BorderRadius.circular(10),
  146. ),
  147. ),
  148. ),
  149. onPressed: () {
  150. if (_globalLogin.currentState
  151. ?.value["phonenumber"] !=
  152. null &&
  153. _globalLogin
  154. .currentState?.value["password"] !=
  155. null) {
  156. viewModel.setter(context,
  157. data: _globalLogin.currentState?.value,
  158. nextScreen: widget.nextScreen);
  159. } else {
  160. Toast.show(
  161. AppTranslations.of(context)!
  162. .text("key_field_requird"),
  163. duration: Toast.lengthLong,
  164. gravity: Toast.bottom);
  165. }
  166. },
  167. child: Padding(
  168. padding: const EdgeInsets.all(10),
  169. child: Text(
  170. AppTranslations.of(context)!
  171. .text("key_btn_login"),
  172. style: const TextStyle(fontSize: 16),
  173. ),
  174. )),
  175. ),
  176. ],
  177. ),
  178. ),
  179. const SizedBox(
  180. height: 20,
  181. ),
  182. //Forgor Password & Sign Up
  183. Row(
  184. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  185. children: [
  186. //Forgor Password
  187. TextButton(
  188. onPressed: () {},
  189. child: Text(
  190. AppTranslations.of(context)!
  191. .text("key_btn_forgot_password"),
  192. style: const TextStyle(
  193. decoration: TextDecoration.underline,
  194. ),
  195. ),
  196. ),
  197. //Sign Up
  198. TextButton(
  199. onPressed: () {
  200. Navigator.pushReplacement(
  201. context,
  202. MaterialPageRoute(
  203. builder: (context) => SignupView(
  204. nextScreen: widget.nextScreen)));
  205. },
  206. child: Text(
  207. AppTranslations.of(context)!.text("key_btn_sign_up"),
  208. style: const TextStyle(
  209. decoration: TextDecoration.underline,
  210. ),
  211. ),
  212. ),
  213. ],
  214. ),
  215. ],
  216. ),
  217. );
  218. return Scaffold(
  219. body: SafeArea(
  220. child: SizedBox(
  221. width: double.infinity,
  222. child: SingleChildScrollView(
  223. scrollDirection: Axis.vertical,
  224. child: ResponsiveWidget(
  225. mobileBody: Column(
  226. children: [
  227. //GoZAP Small Banner
  228. Common.brandSmallBannerWidget(context),
  229. //GoZAP Logo
  230. Common.brandSmallColorLogoWidget(context),
  231. //GoZAP Welcome Text
  232. Common.welcomeTextWidget(context),
  233. //GoZAP login Form
  234. loginFormWidget,
  235. ],
  236. ),
  237. desktopBody: Row(
  238. mainAxisAlignment: MainAxisAlignment.center,
  239. children: [
  240. Container(
  241. width: MediaQuery.of(context).size.width * .65,
  242. height: MediaQuery.of(context).size.height,
  243. color: AppTheme.secondaryColor,
  244. child: Column(
  245. mainAxisAlignment: MainAxisAlignment.center,
  246. children: [
  247. //GoZAP Large Banner
  248. Common.brandLargeBannerWidget(context),
  249. ],
  250. ),
  251. ),
  252. Expanded(
  253. child: Column(
  254. children: [
  255. //GoZAP Small Color Logo
  256. Common.brandSmallColorLogoWidget(context),
  257. //GoZAP Welcome Text
  258. Common.welcomeTextWidget(context),
  259. //GoZAP Welcome login Phara
  260. Common.loginPharaWidget(context),
  261. //GoZAP login Form
  262. loginFormWidget,
  263. ],
  264. ),
  265. )
  266. ],
  267. ),
  268. ),
  269. ),
  270. ),
  271. ),
  272. );
  273. }
  274. },
  275. ),
  276. );
  277. }
  278. }