2022-07-31 17:59:25 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
2022-08-14 08:59:47 +00:00
|
|
|
import 'package:flutter_phoenix/flutter_phoenix.dart';
|
2022-07-31 17:59:25 +00:00
|
|
|
import 'package:localization/localization.dart';
|
2022-08-12 17:00:09 +00:00
|
|
|
import '../../global.dart' as global;
|
2022-07-31 17:59:25 +00:00
|
|
|
|
|
|
|
class AccountSettings extends StatelessWidget {
|
|
|
|
const AccountSettings({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-14 08:59:47 +00:00
|
|
|
List<Widget> children = [];
|
|
|
|
for (int i = 0; i < global.settings!.identities.length; i++) {
|
|
|
|
children.add(
|
|
|
|
LogoutButton(identity: global.settings!.identities.keys.toList()[i]));
|
|
|
|
}
|
2022-07-31 17:59:25 +00:00
|
|
|
return Row(
|
2022-08-14 08:59:47 +00:00
|
|
|
children: children,
|
2022-07-31 17:59:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LogoutButton extends StatelessWidget {
|
2022-08-14 08:59:47 +00:00
|
|
|
const LogoutButton({
|
|
|
|
required this.identity,
|
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
|
|
|
final String identity;
|
2022-07-31 17:59:25 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-13 16:14:12 +00:00
|
|
|
String url = global
|
|
|
|
.settings!.identities[global.settings!.activeIdentity]!.instanceUrl;
|
|
|
|
|
2022-07-31 17:59:25 +00:00
|
|
|
return Row(
|
|
|
|
children: [
|
2022-08-14 08:59:47 +00:00
|
|
|
Text(url + ": " + identity),
|
2022-07-31 17:59:25 +00:00
|
|
|
TextButton.icon(
|
|
|
|
onPressed: () {
|
2022-08-14 08:59:47 +00:00
|
|
|
logout(context, identity);
|
2022-07-31 17:59:25 +00:00
|
|
|
},
|
|
|
|
icon: const Icon(Icons.logout),
|
|
|
|
label: Text("logout".i18n()))
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-14 08:59:47 +00:00
|
|
|
void logout(context, String identity) async {
|
|
|
|
global.settings!.removeIdentity(identity);
|
|
|
|
Phoenix.rebirth(context);
|
2022-07-31 17:59:25 +00:00
|
|
|
}
|