logIn.dart 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import 'package:flutter/material.dart';
  2. import 'Services/AuthService.dart';
  3. class LogIn extends StatefulWidget {
  4. const LogIn({Key? key, required this.title}) : super(key: key);
  5. final String title;
  6. @override
  7. //_RegisterScreen createState() => _RegisterScreen();
  8. State<LogIn> createState() => _LogIn();
  9. }
  10. class _LogIn extends State<LogIn> {
  11. TextEditingController _email = TextEditingController();
  12. TextEditingController _passwd = TextEditingController();
  13. final AuthenticationServices _auth = AuthenticationServices();
  14. @override
  15. Widget build(BuildContext context) {
  16. return Scaffold(
  17. appBar: AppBar(
  18. title: const Text('Login Screen'),
  19. ),
  20. body: Center(
  21. child: SizedBox(
  22. width: 300,
  23. child: Column(children: <Widget>[
  24. const SizedBox(height: 30),
  25. Text(
  26. 'Welcome back!',
  27. style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
  28. ),
  29. const SizedBox(height: 30),
  30. Image.asset(
  31. 'assets/hello.png',
  32. width: 150,
  33. ),
  34. const SizedBox(height: 30),
  35. TextFormField(
  36. controller: _email,
  37. decoration: InputDecoration(
  38. hintText: 'Mail',
  39. ),
  40. ),
  41. const SizedBox(height: 10),
  42. TextFormField(
  43. controller: _passwd,
  44. obscureText: true,
  45. enableSuggestions: false,
  46. autocorrect: false,
  47. decoration: InputDecoration(
  48. hintText: 'Password',
  49. ),
  50. ),
  51. const SizedBox(height: 10),
  52. ElevatedButton(
  53. onPressed: () {
  54. signInUser();
  55. },
  56. child: const Text('Log In'),
  57. ),
  58. ]),
  59. )),
  60. );
  61. }
  62. void signInUser() async {
  63. dynamic authResult = await AuthenticationServices.loginUser(_email.text, _passwd.text);
  64. if (authResult == null) {
  65. print("log in error");
  66. } else {
  67. _email.clear();
  68. _passwd.clear();
  69. print("Succesful login ");
  70. Navigator.pushNamed(context, '/mainPage',
  71. arguments: {'uid': authResult.uid},
  72. );
  73. }
  74. }
  75. }