summaryrefslogtreecommitdiff
path: root/lib/screens/dashboard_screen.dart
blob: 2e27aa2d217e9432fb5102e8af53d470126df167 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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<DashboardScreen> createState() => _DashboardScreenState();
}

class _DashboardScreenState extends State<DashboardScreen> {
  late Auth _auth;

  @override
  void initState() {
    super.initState();
    _auth = Auth();
  }

  @override
  Widget build(BuildContext context) {
    final ThemeProvider themeProvider = context.watch<ThemeProvider>();
    return Scaffold(
      body: CustomScrollView(
        slivers: [
          SliverAppBar.large(
            title: const Text('Inicio'),
          ),
          const SliverFillRemaining(
            child: PostList(),
          ),
        ],
      ),
      drawer: Drawer(
        child: ListView(
          children: [
            UserAccountsDrawerHeader(
              currentAccountPicture: const CircleAvatar(
                backgroundImage:
                    NetworkImage('https://avalos.me/images/pro.jpg'),
              ),
              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<ThemeData?>(
                segments: [
                  const ButtonSegment<ThemeData?>(
                    value: null,
                    icon: Icon(Icons.brightness_auto),
                  ),
                  ButtonSegment<ThemeData?>(
                    value: ThemeSettings.lightTheme,
                    icon: const Icon(Icons.light_mode),
                  ),
                  ButtonSegment<ThemeData?>(
                      value: ThemeSettings.darkTheme,
                      icon: const Icon(Icons.dark_mode)),
                ],
                selected: <ThemeData?>{themeProvider.theme},
                onSelectionChanged: ((Set<ThemeData?> 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'));
      }
    });
  }
}