30a19fcc1e
Added: - changePassword to change the password NOTE: this requires the old password, just to prevent account hijacking. - some basic user limit information - theme selector NOTE: the system theme is meant to function like auto-theme, and is directly translated into a flutter ThemeMode, however, this does not appear to be working on the web. This commit also adds the logout and delete account buttons, but they do not yet delete all rooms, nor do they properly logout the user. BUG: User is not logged out correctly, reloading the page fixes this. Maybe localstore.listen does not detect deletion?
84 lines
1.6 KiB
Dart
84 lines
1.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:localstore/localstore.dart';
|
|
|
|
class AppTheme {
|
|
ThemeMode mode;
|
|
|
|
AppTheme(this.mode);
|
|
|
|
String get name {
|
|
if (mode == ThemeMode.light) {
|
|
return 'Light';
|
|
}
|
|
if (mode == ThemeMode.dark) {
|
|
return 'Dark';
|
|
}
|
|
|
|
return 'System';
|
|
}
|
|
|
|
IconData get icon {
|
|
if (mode == ThemeMode.light) {
|
|
return Icons.light_mode;
|
|
}
|
|
if (mode == ThemeMode.dark) {
|
|
return Icons.dark_mode;
|
|
}
|
|
|
|
return Icons.brightness_auto;
|
|
}
|
|
|
|
static get auto {
|
|
return AppTheme(ThemeMode.system);
|
|
}
|
|
|
|
static get light {
|
|
return AppTheme(ThemeMode.light);
|
|
}
|
|
|
|
static get dark {
|
|
return AppTheme(ThemeMode.dark);
|
|
}
|
|
|
|
static List<AppTheme> list() {
|
|
return [AppTheme.auto, AppTheme.light, AppTheme.dark];
|
|
}
|
|
|
|
static listen(Function(Map<String, dynamic>) cb) {
|
|
final db = Localstore.instance;
|
|
final stream = db.collection('settings').stream;
|
|
stream.listen(cb);
|
|
}
|
|
|
|
Future<void> toDisk() async {
|
|
final db = Localstore.instance;
|
|
await db.collection('settings').doc('ui').set({'theme': mode.index});
|
|
}
|
|
|
|
static Future<AppTheme> fromDisk() async {
|
|
final db = Localstore.instance;
|
|
final doc = await db.collection('settings').doc('ui').get();
|
|
try {
|
|
final index = doc?['theme'];
|
|
final mode = ThemeMode.values[index];
|
|
return AppTheme(mode);
|
|
} catch (_) {
|
|
return AppTheme(ThemeMode.system);
|
|
}
|
|
}
|
|
|
|
@override
|
|
bool operator ==(other) {
|
|
if (other.runtimeType == runtimeType) {
|
|
if (other.hashCode == hashCode) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
@override
|
|
int get hashCode => mode.index;
|
|
|
|
}
|