OpenMediacenterMobileFlutter/lib/navigation/settings_screen.dart

67 lines
1.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:openmediacentermobile/db/settings_db.dart';
import '../api/token.dart';
import '../db/database.dart';
import '../drawer/my_drawer.dart';
import '../login/login_context.dart';
import '../utils/file_formatter.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;
}));
getToken().then((value) => setState(() {
serverUrl = value?.domain ?? "unknown";
}));
}
@override
Widget build(BuildContext context) {
final loginCtx = LoginContext.of(context);
return Scaffold(
appBar: AppBar(
title: Text("Settings"),
),
body: Column(
children: [
Text("Current server: $serverUrl"),
ElevatedButton(
onPressed: () async {
await Db().clear();
Db().getDbSize().then((v) => setState(() {
dbsize = v;
}));
},
child: const Text("Delete cache!")),
Text(
"DB size: ${dbsize.readableFileSize()} / ${dbsize.readableFileSize(base1024: false)}"),
ElevatedButton(
onPressed: () {
loginCtx.onLoggin(false);
SettingsDB.getInstance()
.setSettings(SettingsT("", "", "", 0));
Db().clear();
},
child: Text("Logout"))
],
),
drawer: MyDrawer());
}
}