fluffychat/lib/pages/views/settings_3pid_view.dart

105 lines
3.6 KiB
Dart
Raw Normal View History

2020-11-24 14:27:07 +01:00
import 'package:famedlysdk/famedlysdk.dart';
2021-05-22 08:57:49 +02:00
import 'package:fluffychat/pages/settings_3pid.dart';
2021-05-22 08:53:52 +02:00
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
import 'package:fluffychat/widgets/matrix.dart';
2020-11-24 14:27:07 +01:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
2021-05-22 09:13:47 +02:00
class Settings3PidView extends StatelessWidget {
2021-04-17 11:27:58 +02:00
final Settings3PidController controller;
2020-11-24 14:27:07 +01:00
2021-05-22 09:13:47 +02:00
const Settings3PidView(this.controller, {Key key}) : super(key: key);
2020-11-24 14:27:07 +01:00
@override
Widget build(BuildContext context) {
2021-05-20 14:36:23 +02:00
controller.request ??= Matrix.of(context).client.getAccount3PIDs();
2020-11-24 14:27:07 +01:00
return Scaffold(
appBar: AppBar(
2021-01-16 14:24:52 +01:00
leading: BackButton(),
2020-11-24 14:27:07 +01:00
title: Text(L10n.of(context).passwordRecovery),
actions: [
IconButton(
2020-12-06 10:31:35 +01:00
icon: Icon(Icons.add_outlined),
2021-04-17 11:27:58 +02:00
onPressed: controller.add3PidAction,
2021-02-20 07:40:42 +01:00
tooltip: L10n.of(context).addEmail,
2020-11-24 14:27:07 +01:00
)
],
),
2021-04-09 18:26:44 +02:00
body: MaxWidthBody(
child: FutureBuilder<List<ThirdPartyIdentifier>>(
2021-04-17 11:27:58 +02:00
future: controller.request,
2021-04-09 18:26:44 +02:00
builder: (BuildContext context,
AsyncSnapshot<List<ThirdPartyIdentifier>> snapshot) {
if (snapshot.hasError) {
return Center(
child: Text(
snapshot.error.toString(),
textAlign: TextAlign.center,
),
);
}
if (!snapshot.hasData) {
return Center(child: CircularProgressIndicator());
}
final identifier = snapshot.data;
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 10:31:35 +01:00
identifier.isEmpty
2021-04-09 18:26:44 +02:00
? L10n.of(context).noPasswordRecoveryDescription
: L10n.of(context)
.withTheseAddressesRecoveryDescription,
2020-11-24 14:27:07 +01:00
),
),
2021-04-09 18:26:44 +02:00
Divider(height: 1),
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)),
title: Text(identifier[i].address),
trailing: IconButton(
tooltip: L10n.of(context).delete,
icon: Icon(Icons.delete_forever_outlined),
color: Colors.red,
2021-04-17 11:27:58 +02:00
onPressed: () => controller.delete3Pid(identifier[i]),
2021-04-09 18:26:44 +02:00
),
2020-11-24 14:27:07 +01:00
),
),
),
2021-04-09 18:26:44 +02:00
],
);
},
),
2020-11-24 14:27:07 +01: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;
}
return Icons.device_unknown_outlined;
}
}