import 'package:flutter/material.dart'; import 'package:pmsna1/firebase/auth.dart'; import 'package:pmsna1/providers/theme_provider.dart'; import 'package:pmsna1/settings/themes.dart'; import 'package:pmsna1/widgets/post_list.dart'; import 'package:provider/provider.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'), ), const SliverFillRemaining( child: PostList(), ), ], ), 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( leading: const Icon(Icons.home), title: const Text('Inicio'), onTap: () {}, ), const Divider(), ListTile( title: const Text('Películas populares'), leading: const Icon(Icons.movie), onTap: () { Navigator.of(context).pushNamed('/popular'); }, ), ListTile( title: const Text('Eventos'), leading: const Icon(Icons.calendar_month), onTap: () { Navigator.of(context).pushNamed('/events'); }, ), ListTile( title: const Text('Música'), leading: const Icon(Icons.music_note), onTap: () { Navigator.of(context).pushNamed('/albums'); }, ), 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')); } }); } }