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
|
import 'package:flutter/material.dart';
import 'package:linkchat/widgets/cached_avatar.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'),
actions: [
IconButton(
icon: const Icon(Icons.favorite_outline),
onPressed: () {
Navigator.of(context).pushNamed('/favorites');
},
)
],
),
SliverFillRemaining(
hasScrollBody: true,
child: RecentChats(),
),
],
),
drawer: Drawer(
child: ListView(
children: [
UserAccountsDrawerHeader(
currentAccountPicture: CachedAvatar(_auth.currentUser?.photoURL),
accountName: Text(
_auth.currentUser?.displayName ?? "Lincite",
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimary,
),
),
accountEmail: _auth.currentUser?.email != null
? Text(
_auth.currentUser!.email!,
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimary,
),
)
: null,
),
ListTile(
title: const Text('Tema'),
trailing: SegmentedButton<ThemeEnum>(
segments: const [
ButtonSegment<ThemeEnum>(
value: ThemeEnum.auto,
icon: Icon(Icons.brightness_auto),
),
ButtonSegment<ThemeEnum>(
value: ThemeEnum.light,
icon: Icon(Icons.light_mode),
),
ButtonSegment<ThemeEnum>(
value: ThemeEnum.dark,
icon: Icon(Icons.dark_mode),
),
],
selected: <ThemeEnum>{themeProvider.theme},
onSelectionChanged: ((Set<ThemeEnum> 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).pushReplacementNamed('/login');
}
});
}
}
|