LoginScreen.dart 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_login/flutter_login.dart';
  3. import '../basic/Method.dart';
  4. import 'AppScreen.dart';
  5. // import 'dashboard_screen.dart';
  6. const users = {
  7. 'dribbble@gmail.com': '12345',
  8. 'hunter@gmail.com': 'hunter',
  9. };
  10. class LoginScreen extends StatelessWidget {
  11. const LoginScreen({Key? key}) : super(key: key);
  12. get loginTime => const Duration(milliseconds: 2250);
  13. _authUser(BuildContext context) {
  14. return (LoginData data) {
  15. debugPrint('Name: ${data.name}, Password: ${data.password}');
  16. method.name = data.name;
  17. method.password = data.password;
  18. method.login().then((value) {
  19. if (!value) return false;
  20. Navigator.pushReplacement(
  21. context,
  22. MaterialPageRoute(builder: (context) => const AppScreen()),
  23. );
  24. return true;
  25. });
  26. // if (!widget.mounted) return; // don't use context after async if you're not sure your widget is mounted.
  27. };
  28. }
  29. Future<String?> _signupUser(SignupData data) {
  30. debugPrint('Signup Name: ${data.name}, Password: ${data.password}');
  31. return Future.delayed(loginTime).then((_) {
  32. return null;
  33. });
  34. }
  35. Future<String?> _recoverPassword(String name) {
  36. debugPrint('Name: $name');
  37. return Future.delayed(loginTime).then((_) {
  38. if (!users.containsKey(name)) {
  39. return 'User not exists';
  40. }
  41. return null;
  42. });
  43. }
  44. @override
  45. Widget build(BuildContext context) {
  46. return FlutterLogin(
  47. title: 'PrimeChat',
  48. logo: const AssetImage('lib/assets/avatar.jpg'),
  49. userType: LoginUserType.name,
  50. userValidator: (_) => null,
  51. onLogin: _authUser(context),
  52. onSignup: _signupUser,
  53. onSubmitAnimationCompleted: () {
  54. // Navigator.of(context).pushReplacement(MaterialPageRoute(
  55. // builder: (context) => DashboardScreen(),
  56. // ));
  57. },
  58. onRecoverPassword: _recoverPassword,
  59. );
  60. }
  61. }