fluffychat/lib/pages/settings_3pid/settings_3pid_view.dart

112 lines
3.8 KiB
Dart
Raw Normal View History

2021-10-26 16:50:34 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart';
2021-10-26 16:50:34 +00:00
2021-11-09 20:32:16 +00:00
import 'package:fluffychat/pages/settings_3pid/settings_3pid.dart';
2021-05-22 06:53:52 +00:00
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
import 'package:fluffychat/widgets/matrix.dart';
2020-11-24 13:27:07 +00:00
2021-05-22 07:13:47 +00:00
class Settings3PidView extends StatelessWidget {
2021-04-17 09:27:58 +00:00
final Settings3PidController controller;
2020-11-24 13:27:07 +00:00
const Settings3PidView(this.controller, {super.key});
2020-11-24 13:27:07 +00:00
@override
Widget build(BuildContext context) {
2021-05-20 12:36:23 +00:00
controller.request ??= Matrix.of(context).client.getAccount3PIDs();
2020-11-24 13:27:07 +00:00
return Scaffold(
appBar: AppBar(
leading: const Center(child: BackButton()),
2022-01-29 11:35:03 +00:00
title: Text(L10n.of(context)!.passwordRecovery),
2020-11-24 13:27:07 +00:00
actions: [
IconButton(
2021-10-14 16:09:30 +00:00
icon: const Icon(Icons.add_outlined),
2021-04-17 09:27:58 +00:00
onPressed: controller.add3PidAction,
2022-01-29 11:35:03 +00:00
tooltip: L10n.of(context)!.addEmail,
2023-08-18 05:24:31 +00:00
),
2020-11-24 13:27:07 +00:00
],
),
2021-04-09 16:26:44 +00:00
body: MaxWidthBody(
2023-12-26 15:32:47 +00:00
withScrolling: false,
2022-01-29 11:35:03 +00:00
child: FutureBuilder<List<ThirdPartyIdentifier>?>(
2021-04-17 09:27:58 +00:00
future: controller.request,
builder: (
BuildContext context,
AsyncSnapshot<List<ThirdPartyIdentifier>?> snapshot,
) {
2021-04-09 16:26:44 +00:00
if (snapshot.hasError) {
return Center(
child: Text(
snapshot.error.toString(),
textAlign: TextAlign.center,
),
);
}
if (!snapshot.hasData) {
2021-10-14 16:09:30 +00:00
return const Center(
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
);
2021-04-09 16:26:44 +00:00
}
2022-01-29 11:35:03 +00:00
final identifier = snapshot.data!;
2021-04-09 16:26:44 +00:00
return Column(
children: [
ListTile(
leading: CircleAvatar(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
foregroundColor:
identifier.isEmpty ? Colors.orange : Colors.grey,
child: Icon(
identifier.isEmpty
? Icons.warning_outlined
: Icons.info_outlined,
),
),
title: Text(
2020-12-06 09:31:35 +00:00
identifier.isEmpty
2022-01-29 11:35:03 +00:00
? L10n.of(context)!.noPasswordRecoveryDescription
: L10n.of(context)!
2021-04-09 16:26:44 +00:00
.withTheseAddressesRecoveryDescription,
2020-11-24 13:27:07 +00:00
),
),
2021-10-14 16:09:30 +00:00
const Divider(height: 1),
2021-04-09 16:26:44 +00:00
Expanded(
child: ListView.builder(
itemCount: identifier.length,
itemBuilder: (BuildContext context, int i) => ListTile(
leading: CircleAvatar(
backgroundColor:
Theme.of(context).scaffoldBackgroundColor,
foregroundColor: Colors.grey,
child: Icon(identifier[i].iconData),
),
2021-04-09 16:26:44 +00:00
title: Text(identifier[i].address),
trailing: IconButton(
2022-01-29 11:35:03 +00:00
tooltip: L10n.of(context)!.delete,
2021-10-14 16:09:30 +00:00
icon: const Icon(Icons.delete_forever_outlined),
2021-04-09 16:26:44 +00:00
color: Colors.red,
2021-04-17 09:27:58 +00:00
onPressed: () => controller.delete3Pid(identifier[i]),
2021-04-09 16:26:44 +00:00
),
2020-11-24 13:27:07 +00:00
),
),
),
2021-04-09 16:26:44 +00:00
],
);
},
),
2020-11-24 13:27:07 +00:00
),
);
}
}
extension on ThirdPartyIdentifier {
IconData get iconData {
switch (medium) {
case ThirdPartyIdentifierMedium.email:
return Icons.mail_outline_rounded;
case ThirdPartyIdentifierMedium.msisdn:
return Icons.phone_android_outlined;
}
}
}