loris/lib/pages/settings/account.dart

114 lines
2.9 KiB
Dart
Raw Normal View History

2022-07-31 17:59:25 +00:00
import 'package:flutter/material.dart';
import 'package:localization/localization.dart';
import 'package:loris/dialogues/conversations.dart';
2022-09-30 18:06:24 +00:00
import 'package:loris/dialogues/followreqs.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]));
}
children.add(const NewAccountButton());
2022-09-30 18:06:24 +00:00
children.add(const FollowreqButton());
children.add(const ConversationButton());
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
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-09-23 17:08:05 +00:00
return Wrap(
2022-07-31 17:59:25 +00:00
children: [
2022-08-14 11:32:26 +00:00
SelectableText(identity),
2022-07-31 17:59:25 +00:00
TextButton.icon(
2022-08-14 14:34:28 +00:00
onPressed: () async {
await logout(context, identity);
},
icon: const Icon(Icons.logout),
label: Text(
"logout".i18n(),
),
),
2022-07-31 17:59:25 +00:00
],
);
}
}
class NewAccountButton extends StatelessWidget {
const NewAccountButton({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return TextButton.icon(
onPressed: (() => addNewIdentity(context)),
icon: const Icon(Icons.person_add),
label: Text(
"add-account".i18n(),
),
);
}
}
2022-08-14 11:32:26 +00:00
void addNewIdentity(context) {
Navigator.of(context).pushReplacementNamed("/login");
}
2022-08-14 14:34:28 +00:00
Future<void> logout(context, String identity) async {
2022-08-14 11:32:26 +00:00
await global.settings!.removeIdentity(identity);
if (global.settings!.identities.isEmpty) {
Navigator.of(context).pushReplacementNamed("/login");
2022-08-14 14:34:28 +00:00
} else {
(Navigator.of(context).pushReplacementNamed("/"));
2022-08-14 11:32:26 +00:00
}
2022-07-31 17:59:25 +00:00
}
2022-09-30 18:06:24 +00:00
class FollowreqButton extends StatelessWidget {
const FollowreqButton({super.key});
@override
Widget build(BuildContext context) {
return TextButton.icon(
onPressed: (() => showDialog(
barrierColor: Colors.transparent,
context: context,
builder: (context) => const FollowReqScreen(),
)),
icon: const Icon(Icons.check),
label: Text(
"follow-requests".i18n(),
),
);
}
}
class ConversationButton extends StatelessWidget {
const ConversationButton({super.key});
@override
Widget build(BuildContext context) {
return TextButton.icon(
onPressed: () => showDialog(
2022-09-30 18:06:24 +00:00
context: context,
2022-10-01 11:41:18 +00:00
builder: (context) => const Chat(),
),
icon: const Icon(Icons.chat),
label: Text("chat".i18n()));
2022-09-30 18:06:24 +00:00
}
}