summaryrefslogtreecommitdiff
path: root/lib/screens/login_screen.dart
blob: d4dc3a227afd05ca86e7fcd665f26710a3aa8348 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import 'package:flutter/material.dart';
import 'package:pmsna1/widgets/loading_modal_widget.dart';
import 'package:social_login_buttons/social_login_buttons.dart';

class LoginScreen extends StatefulWidget {
  const LoginScreen({super.key});

  @override
  State<LoginScreen> createState() => _LoginScreenState();
}

class _LoginScreenState extends State<LoginScreen>
    with SingleTickerProviderStateMixin {
  late AnimationController _controller;

  bool isLoading = false;

  final padding = 16.0;
  final spacer = const SizedBox(height: 16.0);

  // TextField controllers
  late TextEditingController _emailController;
  late TextEditingController _passwordController;

  @override
  void initState() {
    super.initState();
    _emailController = TextEditingController();
    _passwordController = TextEditingController();
    _controller = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          SingleChildScrollView(
            child: Column(
              children: [
                Padding(
                  padding: EdgeInsets.all(padding * 2),
                  child: Image.asset('assets/logo_itc.png', height: 120.0),
                ),
                Container(
                  width: double.infinity,
                  alignment: Alignment.centerLeft,
                  padding: EdgeInsets.symmetric(horizontal: padding),
                  child: Text(
                    'Iniciar sesión',
                    style: Theme.of(context).textTheme.displaySmall,
                    textAlign: TextAlign.left,
                  ),
                ),
                Card(
                  margin: EdgeInsets.all(padding),
                  child: Padding(
                    padding: EdgeInsets.all(padding),
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        TextField(
                          controller: _emailController,
                          decoration: const InputDecoration(
                            border: OutlineInputBorder(),
                            labelText: 'Correo electrónico',
                            hintText: 'test@example.com',
                          ),
                          keyboardType: TextInputType.emailAddress,
                        ),
                        spacer,
                        TextField(
                          controller: _passwordController,
                          obscureText: true,
                          decoration: const InputDecoration(
                            border: OutlineInputBorder(),
                            labelText: 'Contraseña',
                          ),
                        ),
                        spacer,
                        SocialLoginButton(
                          buttonType: SocialLoginButtonType.generalLogin,
                          text: 'Iniciar sesión',
                          backgroundColor:
                              Theme.of(context).colorScheme.primary,
                          onPressed: () {
                            setState(() {
                              isLoading = true;
                            });
                            Future.delayed(const Duration(seconds: 4))
                                .whenComplete(() {
                              setState(() {
                                isLoading = false;
                                Navigator.of(context).pushNamed('/dash');
                              });
                            });
                          },
                        ),
                        spacer,
                        const Divider(),
                        spacer,
                        SocialLoginButton(
                          buttonType: SocialLoginButtonType.google,
                          text: 'Iniciar sesión con Google',
                          onPressed: () {},
                        ),
                        spacer,
                        SocialLoginButton(
                          buttonType: SocialLoginButtonType.facebook,
                          text: 'Iniciar sesión con Facebook',
                          onPressed: () {},
                        ),
                        spacer,
                        SocialLoginButton(
                          buttonType: SocialLoginButtonType.github,
                          text: 'Iniciar sesión con GitHub',
                          onPressed: () {},
                        ),
                        spacer,
                        TextButton(
                          onPressed: () {
                            Navigator.of(context).pushNamed('/register');
                          },
                          child: const Text('Crear cuenta'),
                        )
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
          isLoading ? const LoadingModal() : const SizedBox.shrink(),
        ],
      ),
    );
  }
}