2021-04-24 05:43:47 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2024-04-14 11:06:30 +00:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-10-26 16:50:34 +00:00
|
|
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
2024-04-14 11:06:30 +00:00
|
|
|
import 'package:matrix/matrix.dart';
|
2021-10-26 16:50:34 +00:00
|
|
|
|
2021-11-09 20:32:16 +00:00
|
|
|
import '../../widgets/matrix.dart';
|
|
|
|
import 'settings_ignore_list_view.dart';
|
2021-04-24 05:43:47 +00:00
|
|
|
|
|
|
|
class SettingsIgnoreList extends StatefulWidget {
|
2022-01-29 11:35:03 +00:00
|
|
|
final String? initialUserId;
|
2021-04-24 05:43:47 +00:00
|
|
|
|
2023-10-28 11:03:16 +00:00
|
|
|
const SettingsIgnoreList({super.key, this.initialUserId});
|
2021-04-24 05:43:47 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
SettingsIgnoreListController createState() => SettingsIgnoreListController();
|
|
|
|
}
|
|
|
|
|
|
|
|
class SettingsIgnoreListController extends State<SettingsIgnoreList> {
|
|
|
|
final TextEditingController controller = TextEditingController();
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
if (widget.initialUserId != null) {
|
2022-01-29 11:35:03 +00:00
|
|
|
controller.text = widget.initialUserId!.replaceAll('@', '');
|
2021-04-24 05:43:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-14 11:06:30 +00:00
|
|
|
String? errorText;
|
|
|
|
|
2021-04-24 05:43:47 +00:00
|
|
|
void ignoreUser(BuildContext context) {
|
2024-04-14 11:06:30 +00:00
|
|
|
final userId = controller.text.trim();
|
|
|
|
if (userId.isEmpty) return;
|
|
|
|
if (!userId.isValidMatrixId || userId.sigil != '@') {
|
|
|
|
setState(() {
|
|
|
|
errorText = L10n.of(context)!.invalidInput;
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setState(() {
|
|
|
|
errorText = null;
|
|
|
|
});
|
2021-04-24 05:43:47 +00:00
|
|
|
|
|
|
|
showFutureLoadingDialog(
|
|
|
|
context: context,
|
|
|
|
future: () => Matrix.of(context).client.ignoreUser(userId),
|
|
|
|
);
|
|
|
|
controller.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2021-05-22 07:13:47 +00:00
|
|
|
Widget build(BuildContext context) => SettingsIgnoreListView(this);
|
2021-04-24 05:43:47 +00:00
|
|
|
}
|