fluffychat/lib/views/settings_ignore_list.dart

98 lines
3.4 KiB
Dart
Raw Normal View History

2020-09-19 15:29:12 +02:00
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/avatar.dart';
2020-12-25 09:58:34 +01:00
import 'package:future_loading_dialog/future_loading_dialog.dart';
2020-09-19 15:29:12 +02:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
2020-09-19 15:29:12 +02:00
import '../components/matrix.dart';
class SettingsIgnoreList extends StatelessWidget {
2021-01-16 18:09:41 +01:00
final TextEditingController _controller = TextEditingController();
2020-09-19 15:29:12 +02:00
void _ignoreUser(BuildContext context) {
2021-01-16 18:09:41 +01:00
if (_controller.text.isEmpty) return;
final userId = '@${_controller.text}';
2020-12-25 09:58:34 +01:00
showFutureLoadingDialog(
context: context,
2021-01-16 18:09:41 +01:00
future: () => Matrix.of(context).client.ignoreUser(userId),
2020-09-19 15:29:12 +02:00
);
2021-01-16 18:09:41 +01:00
_controller.clear();
2020-09-19 15:29:12 +02:00
}
@override
Widget build(BuildContext context) {
final client = Matrix.of(context).client;
return Scaffold(
2021-01-16 14:24:52 +01:00
appBar: AppBar(
leading: BackButton(),
title: Text(L10n.of(context).ignoredUsers),
),
2020-09-19 15:29:12 +02:00
body: Column(
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
2021-01-16 18:09:41 +01:00
controller: _controller,
2020-09-19 15:29:12 +02:00
autocorrect: false,
textInputAction: TextInputAction.done,
onSubmitted: (_) => _ignoreUser(context),
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'bad_guy:domain.abc',
prefixText: '@',
labelText: L10n.of(context).ignoreUsername,
suffixIcon: IconButton(
2020-12-06 10:31:35 +01:00
icon: Icon(Icons.done_outlined),
2020-09-19 15:29:12 +02:00
onPressed: () => _ignoreUser(context),
),
),
),
SizedBox(height: 16),
Text(
L10n.of(context).ignoreListDescription,
style: TextStyle(color: Colors.orange),
),
],
),
),
Divider(height: 1),
Expanded(
child: StreamBuilder<Object>(
stream: client.onAccountData.stream
.where((a) => a.type == 'm.ignored_user_list'),
builder: (context, snapshot) {
return ListView.builder(
itemCount: client.ignoredUsers.length,
itemBuilder: (c, i) => FutureBuilder<Profile>(
future:
client.getProfileFromUserId(client.ignoredUsers[i]),
builder: (c, s) => ListTile(
leading: Avatar(
s.data?.avatarUrl ?? Uri.parse(''),
s.data?.displayname ?? client.ignoredUsers[i],
),
title:
Text(s.data?.displayname ?? client.ignoredUsers[i]),
trailing: IconButton(
2020-12-06 10:31:35 +01:00
icon: Icon(Icons.delete_forever_outlined),
2020-12-25 09:58:34 +01:00
onPressed: () => showFutureLoadingDialog(
context: context,
future: () =>
client.unignoreUser(client.ignoredUsers[i]),
2020-09-19 15:29:12 +02:00
),
),
),
),
);
}),
),
],
),
);
}
}