fluffychat/lib/views/ui/settings_multiple_emotes_ui.dart

63 lines
2.3 KiB
Dart
Raw Normal View History

2021-01-16 12:46:38 +01:00
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
2021-04-24 08:00:03 +02:00
import 'package:fluffychat/views/settings_multiple_emotes.dart';
2021-04-09 16:15:03 +02:00
import 'package:fluffychat/views/widgets/matrix.dart';
2020-10-03 12:31:29 +02:00
import 'package:flutter/material.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
2021-04-24 08:00:03 +02:00
class MultipleEmotesSettingsUI extends StatelessWidget {
final MultipleEmotesSettingsController controller;
2020-10-03 12:31:29 +02:00
2021-04-24 08:00:03 +02:00
MultipleEmotesSettingsUI(this.controller, {Key key}) : super(key: key);
2020-10-03 12:31:29 +02:00
@override
Widget build(BuildContext context) {
2021-04-24 08:00:03 +02:00
final room =
Matrix.of(context).client.getRoomById(controller.widget.roomId);
2020-10-03 12:31:29 +02:00
return Scaffold(
appBar: AppBar(
2021-01-16 14:24:52 +01:00
leading: BackButton(),
2020-10-03 12:31:29 +02:00
title: Text(L10n.of(context).emotePacks),
),
body: StreamBuilder(
stream: room.onUpdate.stream,
builder: (context, snapshot) {
final packs =
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]];
var 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'];
}
}
return ListTile(
title: Text(packName),
onTap: () async {
2021-01-16 12:46:38 +01:00
await AdaptivePageLayout.of(context).pushNamed(
'/settings/emotes',
2021-02-01 16:25:28 +01:00
arguments: {
'room': room,
'stateKey': keys[i],
},
2020-10-03 12:31:29 +02:00
);
},
);
});
},
),
);
}
}