initial commit 2
This commit is contained in:
155
lib/screens/home_screen.dart
Normal file
155
lib/screens/home_screen.dart
Normal file
@@ -0,0 +1,155 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../models/address_entry.dart';
|
||||
import '../models/auth_session.dart';
|
||||
import '../services/auth_repository.dart';
|
||||
import '../services/address_repository.dart';
|
||||
import 'auth_screen.dart';
|
||||
|
||||
class HomeScreen extends StatelessWidget {
|
||||
const HomeScreen({
|
||||
super.key,
|
||||
required this.authRepository,
|
||||
required this.addressRepository,
|
||||
required this.session,
|
||||
this.savedAddress,
|
||||
});
|
||||
|
||||
final AuthRepository authRepository;
|
||||
final AddressRepository addressRepository;
|
||||
final AuthSession session;
|
||||
final AddressEntry? savedAddress;
|
||||
|
||||
Future<void> _logOut(BuildContext context) async {
|
||||
await authRepository.signOut();
|
||||
if (!context.mounted) {
|
||||
return;
|
||||
}
|
||||
Navigator.of(context).pushAndRemoveUntil(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => AuthScreen(
|
||||
authRepository: authRepository,
|
||||
addressRepository: addressRepository,
|
||||
),
|
||||
),
|
||||
(route) => false,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [Color(0xFFF8FAFC), Color(0xFFE2E8F0), Color(0xFFCCFBF1)],
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 520),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Card(
|
||||
elevation: 12,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(28)),
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 34,
|
||||
backgroundColor: const Color(0xFF0F766E).withValues(alpha: 0.12),
|
||||
child: Text(
|
||||
session.displayName.isNotEmpty ? session.displayName[0].toUpperCase() : 'U',
|
||||
style: const TextStyle(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: Color(0xFF0F766E),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Hola, ${session.displayName}',
|
||||
style: const TextStyle(fontSize: 28, fontWeight: FontWeight.w800),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
session.email,
|
||||
style: TextStyle(color: Colors.grey.shade700),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_InfoTile(
|
||||
icon: Icons.dns_outlined,
|
||||
title: 'Dirección guardada',
|
||||
subtitle: savedAddress == null
|
||||
? 'Todavía no hay una dirección registrada para esta sesión.'
|
||||
: 'Casa ${savedAddress!.houseNumber}, Colonia ${savedAddress!.colonia}, Calle ${savedAddress!.street}',
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_InfoTile(
|
||||
icon: Icons.storage_outlined,
|
||||
title: 'Persistencia en PostgreSQL',
|
||||
subtitle: 'La dirección se envió al backend con el token de sesión para almacenarla en la base de datos.',
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
FilledButton.icon(
|
||||
onPressed: () => _logOut(context),
|
||||
icon: const Icon(Icons.logout),
|
||||
label: const Text('Cerrar sesión'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _InfoTile extends StatelessWidget {
|
||||
const _InfoTile({required this.icon, required this.title, required this.subtitle});
|
||||
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String subtitle;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF8FAFC),
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
border: Border.all(color: const Color(0xFFE2E8F0)),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(icon, color: const Color(0xFF0F766E)),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title, style: const TextStyle(fontWeight: FontWeight.w700)),
|
||||
const SizedBox(height: 4),
|
||||
Text(subtitle, style: TextStyle(color: Colors.grey.shade700, height: 1.35)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user