mirror of
https://github.com/nostrlabs-io/zap-stream-flutter.git
synced 2025-06-16 11:58:50 +00:00
feat: badge awards
This commit is contained in:
74
lib/widgets/chat_badge.dart
Normal file
74
lib/widgets/chat_badge.dart
Normal file
@ -0,0 +1,74 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:ndk/entities.dart';
|
||||
import 'package:zap_stream_flutter/imgproxy.dart';
|
||||
import 'package:zap_stream_flutter/main.dart';
|
||||
import 'package:zap_stream_flutter/theme.dart';
|
||||
import 'package:zap_stream_flutter/utils.dart';
|
||||
import 'package:zap_stream_flutter/widgets/profile.dart';
|
||||
|
||||
class ChatBadgeAwardWidget extends StatelessWidget {
|
||||
final Nip01Event event;
|
||||
final StreamEvent stream;
|
||||
|
||||
const ChatBadgeAwardWidget({
|
||||
super.key,
|
||||
required this.event,
|
||||
required this.stream,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final aTag = event.getFirstTag("a");
|
||||
if (aTag == null) return SizedBox();
|
||||
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 2, vertical: 4),
|
||||
padding: EdgeInsets.all(5),
|
||||
decoration: BoxDecoration(color: LAYER_1, borderRadius: DEFAULT_BR),
|
||||
child: FutureBuilder(
|
||||
future: ndk.requests.query(filters: [aTagToFilter(aTag)]).future,
|
||||
builder: (context, state) {
|
||||
final badge = state.data?.firstOrNull;
|
||||
final image = badge?.getFirstTag("image");
|
||||
final name = badge?.getFirstTag("name");
|
||||
final title = badge?.getFirstTag("description");
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: 8,
|
||||
children: [
|
||||
Column(
|
||||
spacing: 8,
|
||||
children: [
|
||||
if (image?.isNotEmpty ?? false)
|
||||
ProxyImg(url: image, width: 64),
|
||||
if (name?.isNotEmpty ?? false)
|
||||
Text(
|
||||
name!,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
if (title?.isNotEmpty ?? false)
|
||||
Text(
|
||||
title!,
|
||||
style: TextStyle(color: LAYER_5),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
"Awarded to: ",
|
||||
style: TextStyle(fontWeight: FontWeight.w500),
|
||||
),
|
||||
...event
|
||||
.getTags("p")
|
||||
.map((e) => ProfileWidget.pubkey(e, size: 20)),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user