import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../firebase/auth.dart'; import '../providers/theme_provider.dart'; import '../settings/themes.dart'; import '../widgets/recent_chats.dart'; class DashboardScreen extends StatefulWidget { const DashboardScreen({super.key}); @override State createState() => _DashboardScreenState(); } class _DashboardScreenState extends State { late Auth _auth; @override void initState() { super.initState(); _auth = Auth(); } @override Widget build(BuildContext context) { final ThemeProvider themeProvider = context.watch(); return Scaffold( body: CustomScrollView( slivers: [ SliverAppBar.large( title: const Text('Inicio'), ), SliverFillRemaining( hasScrollBody: true, child: RecentChats(), ), ], ), drawer: Drawer( child: ListView( children: [ UserAccountsDrawerHeader( currentAccountPicture: CircleAvatar( backgroundImage: _auth.currentUser?.photoURL != null ? NetworkImage(_auth.currentUser!.photoURL!) : null, ), accountName: Text(_auth.currentUser?.displayName ?? "Lincite"), accountEmail: _auth.currentUser?.email != null ? Text(_auth.currentUser!.email!) : null, ), ListTile( title: const Text('Tema'), trailing: SegmentedButton( segments: [ const ButtonSegment( value: null, icon: Icon(Icons.brightness_auto), ), ButtonSegment( value: ThemeSettings.lightTheme, icon: const Icon(Icons.light_mode), ), ButtonSegment( value: ThemeSettings.darkTheme, icon: const Icon(Icons.dark_mode)), ], selected: {themeProvider.theme}, onSelectionChanged: ((Set newSelection) { themeProvider.theme = newSelection.first; }), ), ), const Divider(), ListTile( title: const Text('Cerrar sesiĆ³n'), leading: const Icon(Icons.logout), onTap: () => signOut(context), ) ], ), ), floatingActionButton: FloatingActionButton.extended( label: const Text('Nuevo'), icon: const Icon(Icons.create), onPressed: () { Navigator.of(context).pushNamed('/new'); }, ), ); } void signOut(BuildContext context) { _auth.signOut().then((success) { if (success) { Navigator.of(context).popUntil(ModalRoute.withName('/login')); } }); } }