aboutsummaryrefslogtreecommitdiff
path: root/lib/screens/dashboard_screen.dart
blob: 88bd8e72a1684fa2505eacd379fb81a14d8951bf (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
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<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'),
          ),
          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<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'));
      }
    });*/
    _auth.signOut().then((success) {
      if (success) {
        Navigator.of(context).pushReplacementNamed('/login');
      }
    });
  }
}