refactor: Pages folder structure
This commit is contained in:
parent
5fe495db94
commit
1abb7310f3
88 changed files with 188 additions and 250 deletions
93
lib/pages/settings_3pid/settings_3pid.dart
Normal file
93
lib/pages/settings_3pid/settings_3pid.dart
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'settings_3pid_view.dart';
|
||||
|
||||
class Settings3Pid extends StatefulWidget {
|
||||
static int sendAttempt = 0;
|
||||
|
||||
const Settings3Pid({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Settings3PidController createState() => Settings3PidController();
|
||||
}
|
||||
|
||||
class Settings3PidController extends State<Settings3Pid> {
|
||||
void add3PidAction() async {
|
||||
final input = await showTextInputDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context).enterAnEmailAddress,
|
||||
okLabel: L10n.of(context).ok,
|
||||
cancelLabel: L10n.of(context).cancel,
|
||||
textFields: [
|
||||
DialogTextField(
|
||||
hintText: L10n.of(context).enterAnEmailAddress,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
),
|
||||
],
|
||||
);
|
||||
if (input == null) return;
|
||||
final clientSecret = DateTime.now().millisecondsSinceEpoch.toString();
|
||||
final response = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => Matrix.of(context).client.requestTokenToRegisterEmail(
|
||||
clientSecret,
|
||||
input.single,
|
||||
Settings3Pid.sendAttempt++,
|
||||
),
|
||||
);
|
||||
if (response.error != null) return;
|
||||
final ok = await showOkAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context).weSentYouAnEmail,
|
||||
message: L10n.of(context).pleaseClickOnLink,
|
||||
okLabel: L10n.of(context).iHaveClickedOnLink,
|
||||
);
|
||||
if (ok == null) return;
|
||||
final success = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => Matrix.of(context).client.uiaRequestBackground(
|
||||
(auth) => Matrix.of(context).client.add3PID(
|
||||
clientSecret,
|
||||
response.result.sid,
|
||||
auth: auth,
|
||||
),
|
||||
),
|
||||
);
|
||||
if (success.error != null) return;
|
||||
setState(() => request = null);
|
||||
}
|
||||
|
||||
Future<List<ThirdPartyIdentifier>> request;
|
||||
|
||||
void delete3Pid(ThirdPartyIdentifier identifier) async {
|
||||
if (await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context).areYouSure,
|
||||
okLabel: L10n.of(context).yes,
|
||||
cancelLabel: L10n.of(context).cancel,
|
||||
) !=
|
||||
OkCancelResult.ok) {
|
||||
return;
|
||||
}
|
||||
final success = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => Matrix.of(context).client.delete3pidFromAccount(
|
||||
identifier.address,
|
||||
identifier.medium,
|
||||
));
|
||||
if (success.error != null) return;
|
||||
setState(() => request = null);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Settings3PidView(this);
|
||||
}
|
||||
107
lib/pages/settings_3pid/settings_3pid_view.dart
Normal file
107
lib/pages/settings_3pid/settings_3pid_view.dart
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/pages/settings_3pid/settings_3pid.dart';
|
||||
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
class Settings3PidView extends StatelessWidget {
|
||||
final Settings3PidController controller;
|
||||
|
||||
const Settings3PidView(this.controller, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
controller.request ??= Matrix.of(context).client.getAccount3PIDs();
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: const BackButton(),
|
||||
title: Text(L10n.of(context).passwordRecovery),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add_outlined),
|
||||
onPressed: controller.add3PidAction,
|
||||
tooltip: L10n.of(context).addEmail,
|
||||
)
|
||||
],
|
||||
),
|
||||
body: MaxWidthBody(
|
||||
child: FutureBuilder<List<ThirdPartyIdentifier>>(
|
||||
future: controller.request,
|
||||
builder: (BuildContext context,
|
||||
AsyncSnapshot<List<ThirdPartyIdentifier>> snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return Center(
|
||||
child: Text(
|
||||
snapshot.error.toString(),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
if (!snapshot.hasData) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator.adaptive(strokeWidth: 2));
|
||||
}
|
||||
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(
|
||||
identifier.isEmpty
|
||||
? L10n.of(context).noPasswordRecoveryDescription
|
||||
: L10n.of(context)
|
||||
.withTheseAddressesRecoveryDescription,
|
||||
),
|
||||
),
|
||||
const 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: const Icon(Icons.delete_forever_outlined),
|
||||
color: Colors.red,
|
||||
onPressed: () => controller.delete3Pid(identifier[i]),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue