fluffychat/lib/pages/settings_multiple_emotes/settings_multiple_emotes_view.dart

66 lines
2.4 KiB
Dart
Raw Normal View History

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';
2021-10-26 16:50:34 +00:00
import 'package:matrix/matrix.dart';
2021-05-23 11:11:55 +00:00
import 'package:vrouter/vrouter.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
2022-01-29 11:35:03 +00:00
const MultipleEmotesSettingsView(this.controller, {Key? key})
2021-10-17 12:15:29 +00:00
: super(key: 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(
2021-10-14 16:09:30 +00:00
leading: const 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(
stream: room.onUpdate.stream,
builder: (context, snapshot) {
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.
final Map<String, Event?> packs = packStateEvents != null
? Map<String, Event?>.of(packStateEvents)
: <String, Event?>{};
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(),
itemCount: keys.length,
itemBuilder: (BuildContext context, int i) {
final event = packs[keys[i]];
String? packName = keys[i].isNotEmpty ? keys[i] : 'Default Pack';
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'];
2020-10-03 10:31:29 +00:00
}
}
return ListTile(
title: Text(packName!),
onTap: () async {
VRouter.of(context).toSegments(
['rooms', room.id, 'details', 'emotes', keys[i]],
);
},
);
},
);
2020-10-03 10:31:29 +00:00
},
),
);
}
}