loris/lib/pages/settings/account.dart

54 lines
1.3 KiB
Dart
Raw Normal View History

2022-07-31 17:59:25 +00:00
import 'dart:io';
import 'package:flutter/material.dart';
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) {
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(
children: children,
2022-07-31 17:59:25 +00:00
);
}
}
class LogoutButton extends StatelessWidget {
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: [
Text(url + ": " + identity),
2022-07-31 17:59:25 +00:00
TextButton.icon(
onPressed: () {
logout(context, identity);
2022-07-31 17:59:25 +00:00
},
icon: const Icon(Icons.logout),
label: Text("logout".i18n()))
],
);
}
}
void logout(context, String identity) async {
global.settings!.removeIdentity(identity);
Phoenix.rebirth(context);
2022-07-31 17:59:25 +00:00
}