2020-10-03 12:31:29 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
|
2020-10-03 12:31:29 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:matrix/matrix.dart';
|
2021-05-23 13:11:55 +02:00
|
|
|
import 'package:vrouter/vrouter.dart';
|
2020-10-03 12:31:29 +02:00
|
|
|
|
2021-11-09 21:32:16 +01:00
|
|
|
import 'package:fluffychat/pages/settings_multiple_emotes/settings_multiple_emotes.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
|
|
|
|
2021-05-22 09:13:47 +02:00
|
|
|
class MultipleEmotesSettingsView extends StatelessWidget {
|
2021-04-24 08:00:03 +02:00
|
|
|
final MultipleEmotesSettingsController controller;
|
2020-10-03 12:31:29 +02:00
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
const MultipleEmotesSettingsView(this.controller, {Key? key})
|
2021-10-17 14:15:29 +02:00
|
|
|
: super(key: key);
|
2020-10-03 12:31:29 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-01-29 12:35:03 +01:00
|
|
|
final room = Matrix.of(context).client.getRoomById(controller.roomId!)!;
|
2020-10-03 12:31:29 +02:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2021-10-14 18:09:30 +02:00
|
|
|
leading: const BackButton(),
|
2022-01-29 12:35:03 +01:00
|
|
|
title: Text(L10n.of(context)!.emotePacks),
|
2020-10-03 12:31:29 +02:00
|
|
|
),
|
|
|
|
body: StreamBuilder(
|
|
|
|
stream: room.onUpdate.stream,
|
|
|
|
builder: (context, snapshot) {
|
2022-01-29 12:35:03 +01:00
|
|
|
final Map<String, Event?> packs =
|
2021-03-09 19:39:25 +01:00
|
|
|
room.states['im.ponies.room_emotes'] ?? <String, Event>{};
|
2020-10-03 12:31:29 +02:00
|
|
|
if (!packs.containsKey('')) {
|
|
|
|
packs[''] = null;
|
|
|
|
}
|
|
|
|
final keys = packs.keys.toList();
|
|
|
|
keys.sort();
|
|
|
|
return ListView.separated(
|
|
|
|
separatorBuilder: (BuildContext context, int i) => Container(),
|
|
|
|
itemCount: keys.length,
|
|
|
|
itemBuilder: (BuildContext context, int i) {
|
|
|
|
final event = packs[keys[i]];
|
2022-01-29 12:35:03 +01:00
|
|
|
String? packName =
|
|
|
|
keys[i].isNotEmpty ? keys[i] : 'Default Pack';
|
2020-10-03 12:31:29 +02:00
|
|
|
if (event != null && event.content['pack'] is Map) {
|
|
|
|
if (event.content['pack']['displayname'] is String) {
|
|
|
|
packName = event.content['pack']['displayname'];
|
|
|
|
} else if (event.content['pack']['name'] is String) {
|
|
|
|
packName = event.content['pack']['name'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ListTile(
|
2022-01-29 12:35:03 +01:00
|
|
|
title: Text(packName!),
|
2020-10-03 12:31:29 +02:00
|
|
|
onTap: () async {
|
2021-08-15 13:26:16 +02:00
|
|
|
VRouter.of(context).toSegments(
|
|
|
|
['rooms', room.id, 'details', 'emotes', keys[i]]);
|
2020-10-03 12:31:29 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|