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