Skip to content

Commit 42831b1

Browse files
committed
feat(auth): Implement sign-in UI and logic
- Added email/password sign-in - Implemented Google sign-in - Added anonymous sign-in - Displayed loading indicator - Showed error messages
1 parent 025b993 commit 42831b1

File tree

1 file changed

+87
-4
lines changed

1 file changed

+87
-4
lines changed

lib/authentication/view/authentication_page.dart

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,101 @@ class AuthenticationPage extends StatelessWidget {
1212
create: (context) => AuthenticationBloc(
1313
authenticationRepository: context.read<HtAuthenticationRepository>(),
1414
),
15-
child: const _AuthenticationView(),
15+
child: _AuthenticationView(),
1616
);
1717
}
1818
}
1919

2020
class _AuthenticationView extends StatelessWidget {
21-
const _AuthenticationView();
21+
_AuthenticationView();
22+
23+
final _emailController = TextEditingController();
24+
final _passwordController = TextEditingController();
2225

2326
@override
2427
Widget build(BuildContext context) {
25-
return const Placeholder(
26-
child: Text('AUTHENTICATION PAGE'),
28+
29+
return Scaffold(
30+
body: SafeArea(
31+
child: BlocBuilder<AuthenticationBloc, AuthenticationState>(
32+
builder: (context, state) {
33+
if (state is AuthenticationLoading) {
34+
return const Center(child: CircularProgressIndicator());
35+
}
36+
if (state is AuthenticationFailure) {
37+
WidgetsBinding.instance.addPostFrameCallback((_) {
38+
ScaffoldMessenger.of(context).showSnackBar(
39+
SnackBar(content: Text(state.errorMessage)),
40+
);
41+
});
42+
}
43+
return Padding(
44+
padding: const EdgeInsets.all(16),
45+
child: Column(
46+
mainAxisAlignment: MainAxisAlignment.center,
47+
children: [
48+
const Text(
49+
'Sign In',
50+
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
51+
),
52+
const SizedBox(height: 32),
53+
TextFormField(
54+
controller: _emailController,
55+
decoration: const InputDecoration(
56+
labelText: 'Email',
57+
border: OutlineInputBorder(),
58+
),
59+
keyboardType: TextInputType.emailAddress,
60+
),
61+
const SizedBox(height: 16),
62+
TextFormField(
63+
controller: _passwordController,
64+
decoration: const InputDecoration(
65+
labelText: 'Password',
66+
border: OutlineInputBorder(),
67+
),
68+
obscureText: true,
69+
),
70+
const SizedBox(height: 32),
71+
ElevatedButton(
72+
onPressed: () {
73+
context.read<AuthenticationBloc>().add(
74+
AuthenticationEmailSignInRequested(
75+
email: _emailController.text,
76+
password: _passwordController.text,
77+
),
78+
);
79+
},
80+
child: const Text('Sign In with Email'),
81+
),
82+
const SizedBox(height: 16),
83+
ElevatedButton(
84+
onPressed: () {
85+
context
86+
.read<AuthenticationBloc>()
87+
.add(const AuthenticationGoogleSignInRequested());
88+
},
89+
style: ElevatedButton.styleFrom(
90+
backgroundColor: Colors.white,
91+
foregroundColor: Colors.black,
92+
),
93+
child: const Text('Sign In with Google'),
94+
),
95+
const SizedBox(height: 16),
96+
ElevatedButton(
97+
onPressed: () {
98+
context
99+
.read<AuthenticationBloc>()
100+
.add(const AuthenticationAnonymousSignInRequested());
101+
},
102+
child: const Text('Sign In Anonymously'),
103+
),
104+
],
105+
),
106+
);
107+
},
108+
),
109+
),
27110
);
28111
}
29112
}

0 commit comments

Comments
 (0)