OpenMediacenterMobileFlutter/lib/navigation/settings_screen.dart

65 lines
1.7 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import '../utils/file_formatter.dart';
import '../api/token.dart';
import '../db/database.dart';
import '../drawer/my_drawer.dart';
2022-09-02 16:42:38 +00:00
import '../login/login_context.dart';
class SettingsScreen extends StatefulWidget {
const SettingsScreen({Key? key}) : super(key: key);
@override
State<SettingsScreen> createState() => _SettingsScreenState();
}
class _SettingsScreenState extends State<SettingsScreen> {
int dbsize = 0;
String serverUrl = "";
@override
void initState() {
super.initState();
Db().getDbSize().then((v) => setState(() {
dbsize = v;
}));
Token.getInstance().getToken().then((value) => setState(() {
serverUrl = value?.domain ?? "unknown";
}));
}
@override
Widget build(BuildContext context) {
final loginCtx = LoginContext.of(context);
return Scaffold(
appBar: AppBar(
2022-08-30 09:57:50 +00:00
title: Text("Settings"),
),
body: Column(
children: [
Text("Current server: $serverUrl"),
ElevatedButton(
onPressed: () async {
await Db().clear();
Db().getDbSize().then((v) => setState(() {
2022-08-29 15:20:35 +00:00
dbsize = v;
}));
},
child: const Text("Delete cache!")),
2022-08-30 21:25:21 +00:00
Text(
"DB size: ${dbsize.readableFileSize()} / ${dbsize.readableFileSize(base1024: false)}"),
2022-08-29 15:20:35 +00:00
ElevatedButton(
onPressed: () {
loginCtx.onLoggin(false);
2022-09-02 16:42:38 +00:00
Token.getInstance().setToken("", "", "");
2022-08-29 15:20:35 +00:00
Db().clear();
},
child: Text("Logout"))
],
),
drawer: MyDrawer());
}
}