2020-10-03 10:31:29 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-10-26 16:50:34 +00:00
|
|
|
|
2020-10-03 10:31:29 +00:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2023-08-02 10:08:23 +00:00
|
|
|
import 'package:go_router/go_router.dart';
|
2021-10-26 16:50:34 +00:00
|
|
|
import 'package:matrix/matrix.dart';
|
2020-10-03 10:31:29 +00:00
|
|
|
|
2021-11-09 20:32:16 +00:00
|
|
|
import 'package:fluffychat/pages/settings_multiple_emotes/settings_multiple_emotes.dart';
|
2021-10-26 16:50:34 +00:00
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
|
|
|
|
2021-05-22 07:13:47 +00:00
|
|
|
class MultipleEmotesSettingsView extends StatelessWidget {
|
2021-04-24 06:00:03 +00:00
|
|
|
final MultipleEmotesSettingsController controller;
|
2020-10-03 10:31:29 +00:00
|
|
|
|
2023-10-28 11:03:16 +00:00
|
|
|
const MultipleEmotesSettingsView(this.controller, {super.key});
|
2020-10-03 10:31:29 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-01-29 11:35:03 +00:00
|
|
|
final room = Matrix.of(context).client.getRoomById(controller.roomId!)!;
|
2020-10-03 10:31:29 +00:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2023-08-13 16:23:36 +00:00
|
|
|
leading: const Center(child: BackButton()),
|
2022-01-29 11:35:03 +00:00
|
|
|
title: Text(L10n.of(context)!.emotePacks),
|
2020-10-03 10:31:29 +00:00
|
|
|
),
|
|
|
|
body: StreamBuilder(
|
2024-05-19 05:52:18 +00:00
|
|
|
stream: room.client.onRoomState.stream
|
|
|
|
.where((update) => update.roomId == room.id),
|
2020-10-03 10:31:29 +00:00
|
|
|
builder: (context, snapshot) {
|
2023-03-11 13:38:47 +00:00
|
|
|
final packStateEvents = room.states['im.ponies.room_emotes'];
|
|
|
|
// we need to manually convert the map using Map.of, otherwise assigning null will throw a type error.
|
2024-05-08 10:42:40 +00:00
|
|
|
final packs = packStateEvents != null
|
|
|
|
? Map<String, StrippedStateEvent?>.of(packStateEvents)
|
|
|
|
: <String, StrippedStateEvent?>{};
|
2020-10-03 10:31:29 +00:00
|
|
|
if (!packs.containsKey('')) {
|
|
|
|
packs[''] = null;
|
|
|
|
}
|
|
|
|
final keys = packs.keys.toList();
|
|
|
|
keys.sort();
|
|
|
|
return ListView.separated(
|
2023-03-23 14:02:32 +00:00
|
|
|
separatorBuilder: (BuildContext context, int i) =>
|
|
|
|
const SizedBox.shrink(),
|
2023-03-02 09:57:52 +00:00
|
|
|
itemCount: keys.length,
|
|
|
|
itemBuilder: (BuildContext context, int i) {
|
|
|
|
final event = packs[keys[i]];
|
2023-07-13 10:46:10 +00:00
|
|
|
final eventPack =
|
|
|
|
event?.content.tryGetMap<String, Object?>('pack');
|
|
|
|
final packName = eventPack?.tryGet<String>('displayname') ??
|
|
|
|
eventPack?.tryGet<String>('name') ??
|
|
|
|
(keys[i].isNotEmpty ? keys[i] : 'Default Pack');
|
|
|
|
|
2023-03-02 09:57:52 +00:00
|
|
|
return ListTile(
|
2023-07-13 10:46:10 +00:00
|
|
|
title: Text(packName),
|
2023-03-02 09:57:52 +00:00
|
|
|
onTap: () async {
|
2023-08-07 16:40:02 +00:00
|
|
|
context.go(
|
|
|
|
['', 'rooms', room.id, 'details', 'emotes', keys[i]]
|
|
|
|
.join('/'),
|
2023-03-02 09:57:52 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2020-10-03 10:31:29 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|