Initial commit: family safety frontend project setup
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../providers/auth_provider.dart';
|
||||
|
||||
class LoginScreen extends StatelessWidget {
|
||||
const LoginScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final authProvider = context.watch<AuthProvider>();
|
||||
final TextEditingController loginController = TextEditingController();
|
||||
final TextEditingController passwordController = TextEditingController();
|
||||
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: Card(
|
||||
margin: const EdgeInsets.all(24),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text(
|
||||
'Family Safety',
|
||||
style: TextStyle(
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
TextField(
|
||||
controller: loginController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Login',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: passwordController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Password',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
obscureText: true,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (authProvider.error.isNotEmpty)
|
||||
Text(
|
||||
authProvider.error,
|
||||
style: const TextStyle(color: Colors.red),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: authProvider.isLoading
|
||||
? null
|
||||
: () async {
|
||||
try {
|
||||
await authProvider.login(
|
||||
loginController.text,
|
||||
passwordController.text,
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
Navigator.of(context).pushReplacementNamed('/map');
|
||||
} catch (e) {
|
||||
// Error is handled by provider
|
||||
}
|
||||
},
|
||||
child: const Text('Login'),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: authProvider.isLoading
|
||||
? null
|
||||
: () async {
|
||||
try {
|
||||
await authProvider.register(
|
||||
loginController.text,
|
||||
passwordController.text,
|
||||
);
|
||||
} catch (e) {
|
||||
// Error is handled by provider
|
||||
}
|
||||
},
|
||||
child: const Text('Register'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user