mirror of
https://github.com/nostrlabs-io/zap-stream-flutter.git
synced 2025-06-16 03:58:09 +00:00
refactor: performance
This commit is contained in:
@ -32,7 +32,7 @@ var ndk = Ndk(
|
||||
eventVerifier: eventVerifier,
|
||||
cache: ndkCache,
|
||||
bootstrapRelays: defaultRelays,
|
||||
engine: NdkEngine.JIT,
|
||||
//engine: NdkEngine.JIT,
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -16,6 +16,7 @@ class HomePage extends StatelessWidget {
|
||||
children: [
|
||||
HeaderWidget(),
|
||||
RxFilter<Nip01Event>(
|
||||
Key("home-page"),
|
||||
filters: [
|
||||
Filter(kinds: [30_311], limit: 50),
|
||||
],
|
||||
|
@ -81,7 +81,7 @@ class ProfilePage extends StatelessWidget {
|
||||
),
|
||||
|
||||
RxFilter<Nip01Event>(
|
||||
key: Key("profile-streams:$hexPubkey"),
|
||||
Key("profile-streams:$hexPubkey"),
|
||||
relays: defaultRelays,
|
||||
filters: [
|
||||
Filter(kinds: [30_311], limit: 200, pTags: [hexPubkey]),
|
||||
|
@ -75,6 +75,7 @@ class _StreamPage extends State<StreamPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RxFilter<Nip01Event>(
|
||||
Key("stream:event:${widget.stream.aTag}"),
|
||||
relays: widget.stream.info.relays,
|
||||
filters: [
|
||||
Filter(
|
||||
|
@ -14,14 +14,14 @@ class RxFilter<T> extends StatefulWidget {
|
||||
final T Function(Nip01Event)? mapper;
|
||||
final List<String>? relays;
|
||||
|
||||
const RxFilter({
|
||||
super.key,
|
||||
const RxFilter(
|
||||
Key key, {
|
||||
required this.filters,
|
||||
required this.builder,
|
||||
this.mapper,
|
||||
this.leaveOpen = true,
|
||||
this.relays,
|
||||
});
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _RxFilter<T>();
|
||||
@ -105,14 +105,14 @@ class RxFutureFilter<T> extends StatelessWidget {
|
||||
final Widget? loadingWidget;
|
||||
final T Function(Nip01Event)? mapper;
|
||||
|
||||
const RxFutureFilter({
|
||||
super.key,
|
||||
const RxFutureFilter(
|
||||
Key key, {
|
||||
required this.filterBuilder,
|
||||
required this.builder,
|
||||
this.mapper,
|
||||
this.leaveOpen = true,
|
||||
this.loadingWidget,
|
||||
});
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -121,6 +121,7 @@ class RxFutureFilter<T> extends StatelessWidget {
|
||||
builder: (ctx, data) {
|
||||
if (data.hasData) {
|
||||
return RxFilter<T>(
|
||||
super.key!,
|
||||
filters: data.data!,
|
||||
mapper: mapper,
|
||||
builder: builder,
|
||||
|
@ -6,15 +6,14 @@ import 'package:zap_stream_flutter/rx_filter.dart';
|
||||
import 'package:zap_stream_flutter/theme.dart';
|
||||
import 'package:zap_stream_flutter/utils.dart';
|
||||
import 'package:zap_stream_flutter/widgets/avatar.dart';
|
||||
import 'package:zap_stream_flutter/widgets/nostr_text.dart';
|
||||
import 'package:zap_stream_flutter/widgets/chat_message.dart';
|
||||
import 'package:zap_stream_flutter/widgets/chat_write.dart';
|
||||
import 'package:zap_stream_flutter/widgets/profile.dart';
|
||||
import 'package:zap_stream_flutter/widgets/chat_modal.dart';
|
||||
|
||||
class ChatWidget extends StatelessWidget {
|
||||
final StreamEvent stream;
|
||||
|
||||
const ChatWidget({super.key, required this.stream});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var muteLists = [stream.info.host];
|
||||
@ -24,9 +23,10 @@ class ChatWidget extends StatelessWidget {
|
||||
|
||||
var filters = [
|
||||
Filter(kinds: [1311, 9735], limit: 200, aTags: [stream.aTag]),
|
||||
//Filter(kinds: [Nip51List.kMute], authors: muteLists), // bugged
|
||||
Filter(kinds: [Nip51List.kMute], authors: muteLists),
|
||||
];
|
||||
return RxFilter<Nip01Event>(
|
||||
Key("stream:chat:${stream.aTag}"),
|
||||
relays: stream.info.relays,
|
||||
filters: filters,
|
||||
builder: (ctx, state) {
|
||||
@ -69,37 +69,26 @@ class ChatWidget extends StatelessWidget {
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
reverse: true,
|
||||
shrinkWrap: true,
|
||||
primary: true,
|
||||
itemCount: filteredChat.length,
|
||||
itemBuilder:
|
||||
(ctx, idx) => switch (filteredChat[idx].kind) {
|
||||
1311 => Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 2,
|
||||
vertical: 2,
|
||||
),
|
||||
child: _ChatMessageWidget(
|
||||
1311 => ChatMessageWidget(
|
||||
key: Key("chat:${filteredChat[idx].id}"),
|
||||
stream: stream,
|
||||
msg: filteredChat[idx],
|
||||
),
|
||||
),
|
||||
9735 => Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 2,
|
||||
vertical: 2,
|
||||
),
|
||||
child: _ChatZapWidget(
|
||||
9735 => _ChatZapWidget(
|
||||
key: Key("chat:${filteredChat[idx].id}"),
|
||||
stream: stream,
|
||||
zap: filteredChat[idx],
|
||||
),
|
||||
),
|
||||
_ => SizedBox.shrink(),
|
||||
},
|
||||
),
|
||||
),
|
||||
if (stream.info.status == StreamStatus.live)
|
||||
_WriteMessageWidget(stream: stream),
|
||||
WriteMessageWidget(stream: stream),
|
||||
if (stream.info.status == StreamStatus.ended)
|
||||
Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
@ -126,6 +115,8 @@ class _StreamGoalWidget extends StatelessWidget {
|
||||
|
||||
static Widget id(String id) {
|
||||
return RxFilter<Nip01Event>(
|
||||
Key("stream:goal:$id"),
|
||||
leaveOpen: false,
|
||||
filters: [
|
||||
Filter(kinds: [9041], ids: [id]),
|
||||
],
|
||||
@ -142,6 +133,7 @@ class _StreamGoalWidget extends StatelessWidget {
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 4, vertical: 4),
|
||||
child: RxFilter<Nip01Event>(
|
||||
Key("stream:goal:$id:zaps"),
|
||||
filters: [
|
||||
Filter(kinds: [9735], eTags: [goal.id]),
|
||||
],
|
||||
@ -163,7 +155,7 @@ class _StreamGoalWidget extends StatelessWidget {
|
||||
if (remaining > 0)
|
||||
Text(
|
||||
"Remaining: ${formatSats(remaining)}",
|
||||
style: TextStyle(fontSize: 12, color: LAYER_5),
|
||||
style: TextStyle(fontSize: 10, color: LAYER_5),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -273,12 +265,13 @@ class _ChatZapWidget extends StatelessWidget {
|
||||
final StreamEvent stream;
|
||||
final Nip01Event zap;
|
||||
|
||||
const _ChatZapWidget({required this.stream, required this.zap});
|
||||
const _ChatZapWidget({required this.stream, required this.zap, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final parsed = ZapReceipt.fromEvent(zap);
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(vertical: 4),
|
||||
padding: EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: ZAP_1),
|
||||
@ -338,203 +331,3 @@ class _ChatZapWidget extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ChatMessageWidget extends StatelessWidget {
|
||||
final StreamEvent stream;
|
||||
final Nip01Event msg;
|
||||
|
||||
const _ChatMessageWidget({required this.stream, required this.msg});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ProfileLoaderWidget(msg.pubKey, (ctx, state) {
|
||||
final profile = state.data ?? Metadata(pubKey: msg.pubKey);
|
||||
return GestureDetector(
|
||||
onLongPress: () {
|
||||
if (ndk.accounts.canSign) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
constraints: BoxConstraints.expand(),
|
||||
builder: (ctx) => ChatModalWidget(profile: profile, event: msg),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Column(
|
||||
spacing: 2,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_chatText(profile),
|
||||
RxFilter<Nip01Event>(
|
||||
key: Key("chat:reactions:${msg.id}"),
|
||||
filters: [
|
||||
Filter(kinds: [9735, 7], eTags: [msg.id]),
|
||||
],
|
||||
builder: (ctx, data) => _chatReactions(data),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _chatText(Metadata profile) {
|
||||
return RichText(
|
||||
text: TextSpan(
|
||||
children: [
|
||||
WidgetSpan(
|
||||
child: AvatarWidget(profile: profile, size: 24),
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
),
|
||||
TextSpan(text: " "),
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: ProfileNameWidget(
|
||||
profile: profile,
|
||||
style: TextStyle(
|
||||
color: msg.pubKey == stream.info.host ? PRIMARY_1 : SECONDARY_1,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextSpan(text: " "),
|
||||
...textToSpans(msg.content, msg.tags, msg.pubKey),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _chatReactions(List<Nip01Event>? events) {
|
||||
if ((events?.length ?? 0) == 0) return SizedBox.shrink();
|
||||
|
||||
// reactions must have e tag pointing to msg
|
||||
final filteredEvents = events!.where((e) => e.getEId() == msg.id);
|
||||
final zaps = filteredEvents
|
||||
.where((e) => e.kind == 9735)
|
||||
.map((e) => ZapReceipt.fromEvent(e));
|
||||
final reactions = filteredEvents.where((e) => e.kind == 7);
|
||||
|
||||
return Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
if (zaps.isNotEmpty)
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 4, vertical: 2),
|
||||
decoration: BoxDecoration(color: LAYER_2, borderRadius: DEFAULT_BR),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.bolt, color: ZAP_1, size: 16),
|
||||
Text(
|
||||
formatSats(
|
||||
zaps.fold(0, (acc, v) => acc + (v.amountSats ?? 0)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (reactions.isNotEmpty)
|
||||
...reactions
|
||||
.fold(<String, Set<String>>{}, (acc, v) {
|
||||
// ignore: prefer_collection_literals
|
||||
acc[v.content] ??= Set();
|
||||
acc[v.content]!.add(v.pubKey);
|
||||
return acc;
|
||||
})
|
||||
.entries
|
||||
.map(
|
||||
(v) => Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 4, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: LAYER_2,
|
||||
borderRadius: DEFAULT_BR,
|
||||
),
|
||||
child: Center(child: Text(v.key)),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _WriteMessageWidget extends StatefulWidget {
|
||||
final StreamEvent stream;
|
||||
|
||||
const _WriteMessageWidget({required this.stream});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => __WriteMessageWidget();
|
||||
}
|
||||
|
||||
class __WriteMessageWidget extends State<_WriteMessageWidget> {
|
||||
late final TextEditingController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = TextEditingController();
|
||||
}
|
||||
|
||||
Future<void> _sendMessage() async {
|
||||
final login = ndk.accounts.getLoggedAccount();
|
||||
if (login == null) return;
|
||||
|
||||
final chatMsg = Nip01Event(
|
||||
pubKey: login.pubkey,
|
||||
kind: 1311,
|
||||
content: _controller.text,
|
||||
tags: [
|
||||
["a", widget.stream.aTag],
|
||||
],
|
||||
);
|
||||
_controller.text = "";
|
||||
final res = ndk.broadcast.broadcast(nostrEvent: chatMsg);
|
||||
await res.broadcastDoneFuture;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final canSign = ndk.accounts.canSign;
|
||||
final isLogin = ndk.accounts.isLoggedIn;
|
||||
|
||||
return Container(
|
||||
margin: EdgeInsets.fromLTRB(4, 8, 4, 0),
|
||||
padding: EdgeInsets.symmetric(horizontal: 8),
|
||||
decoration: BoxDecoration(color: LAYER_2, borderRadius: DEFAULT_BR),
|
||||
child:
|
||||
canSign
|
||||
? Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _controller,
|
||||
onSubmitted: (_) => _sendMessage(),
|
||||
decoration: InputDecoration(
|
||||
labelText: "Write message",
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 4),
|
||||
labelStyle: TextStyle(color: LAYER_4, fontSize: 14),
|
||||
border: InputBorder.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
//IconButton(onPressed: () {}, icon: Icon(Icons.mood)),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
_sendMessage();
|
||||
},
|
||||
icon: Icon(Icons.send),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
isLogin
|
||||
? "Can't write messages with npub login"
|
||||
: "Please login to send messages",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
136
lib/widgets/chat_message.dart
Normal file
136
lib/widgets/chat_message.dart
Normal file
@ -0,0 +1,136 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ndk/ndk.dart';
|
||||
import 'package:zap_stream_flutter/main.dart';
|
||||
import 'package:zap_stream_flutter/rx_filter.dart';
|
||||
import 'package:zap_stream_flutter/theme.dart';
|
||||
import 'package:zap_stream_flutter/utils.dart';
|
||||
import 'package:zap_stream_flutter/widgets/avatar.dart';
|
||||
import 'package:zap_stream_flutter/widgets/chat_modal.dart';
|
||||
import 'package:zap_stream_flutter/widgets/nostr_text.dart';
|
||||
import 'package:zap_stream_flutter/widgets/profile.dart';
|
||||
|
||||
class ChatMessageWidget extends StatelessWidget {
|
||||
final StreamEvent stream;
|
||||
final Nip01Event msg;
|
||||
|
||||
const ChatMessageWidget({super.key, required this.stream, required this.msg});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ProfileLoaderWidget(msg.pubKey, (ctx, state) {
|
||||
final profile = state.data ?? Metadata(pubKey: msg.pubKey);
|
||||
return GestureDetector(
|
||||
onLongPress: () {
|
||||
if (ndk.accounts.canSign) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
constraints: BoxConstraints.expand(),
|
||||
builder: (ctx) => ChatModalWidget(profile: profile, event: msg),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 2, vertical: 4),
|
||||
child: Column(
|
||||
spacing: 2,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [_chatText(profile), ChatReactions(msg: msg)],
|
||||
),
|
||||
),
|
||||
);
|
||||
}, key: Key("chat:${msg.id}:profile"));
|
||||
}
|
||||
|
||||
Widget _chatText(Metadata profile) {
|
||||
return RichText(
|
||||
text: TextSpan(
|
||||
children: [
|
||||
WidgetSpan(
|
||||
child: AvatarWidget(profile: profile, size: 24),
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
),
|
||||
TextSpan(text: " "),
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: ProfileNameWidget(
|
||||
profile: profile,
|
||||
style: TextStyle(
|
||||
color: msg.pubKey == stream.info.host ? PRIMARY_1 : SECONDARY_1,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextSpan(text: " "),
|
||||
...textToSpans(msg.content, msg.tags, msg.pubKey),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ChatReactions extends StatelessWidget {
|
||||
final Nip01Event msg;
|
||||
|
||||
const ChatReactions({super.key, required this.msg});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RxFilter<Nip01Event>(
|
||||
Key("chat:${msg.id}:reactions"),
|
||||
filters: [
|
||||
Filter(kinds: [9735, 7], eTags: [msg.id]),
|
||||
],
|
||||
builder: (ctx, data) => _chatReactions(data),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _chatReactions(List<Nip01Event>? events) {
|
||||
if ((events?.length ?? 0) == 0) return SizedBox.shrink();
|
||||
|
||||
// reactions must have e tag pointing to msg
|
||||
final filteredEvents = events!.where((e) => e.getEId() == msg.id);
|
||||
final zaps = filteredEvents
|
||||
.where((e) => e.kind == 9735)
|
||||
.map((e) => ZapReceipt.fromEvent(e));
|
||||
final reactions = filteredEvents.where((e) => e.kind == 7);
|
||||
|
||||
return Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
if (zaps.isNotEmpty)
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 4, vertical: 2),
|
||||
decoration: BoxDecoration(color: LAYER_2, borderRadius: DEFAULT_BR),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.bolt, color: ZAP_1, size: 16),
|
||||
Text(
|
||||
formatSats(
|
||||
zaps.fold(0, (acc, v) => acc + (v.amountSats ?? 0)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (reactions.isNotEmpty)
|
||||
...reactions
|
||||
.fold(<String, Set<String>>{}, (acc, v) {
|
||||
// ignore: prefer_collection_literals
|
||||
acc[v.content] ??= Set();
|
||||
acc[v.content]!.add(v.pubKey);
|
||||
return acc;
|
||||
})
|
||||
.entries
|
||||
.map(
|
||||
(v) => Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 4, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: LAYER_2,
|
||||
borderRadius: DEFAULT_BR,
|
||||
),
|
||||
child: Center(child: Text(v.key)),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -75,7 +75,12 @@ class _ChatModalWidget extends State<ChatModalWidget> {
|
||||
],
|
||||
),
|
||||
if (_showEmojiPicker) ReactionWidget(event: widget.event),
|
||||
MuteButton(pubkey: widget.event.pubKey),
|
||||
MuteButton(
|
||||
pubkey: widget.event.pubKey,
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
90
lib/widgets/chat_write.dart
Normal file
90
lib/widgets/chat_write.dart
Normal file
@ -0,0 +1,90 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ndk/ndk.dart';
|
||||
import 'package:zap_stream_flutter/main.dart';
|
||||
import 'package:zap_stream_flutter/theme.dart';
|
||||
import 'package:zap_stream_flutter/utils.dart';
|
||||
|
||||
class WriteMessageWidget extends StatefulWidget {
|
||||
final StreamEvent stream;
|
||||
|
||||
const WriteMessageWidget({super.key, required this.stream});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => __WriteMessageWidget();
|
||||
}
|
||||
|
||||
class __WriteMessageWidget extends State<WriteMessageWidget> {
|
||||
late final TextEditingController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = TextEditingController();
|
||||
}
|
||||
|
||||
Future<void> _sendMessage() async {
|
||||
final login = ndk.accounts.getLoggedAccount();
|
||||
if (login == null) return;
|
||||
|
||||
final chatMsg = Nip01Event(
|
||||
pubKey: login.pubkey,
|
||||
kind: 1311,
|
||||
content: _controller.text,
|
||||
tags: [
|
||||
["a", widget.stream.aTag],
|
||||
],
|
||||
);
|
||||
_controller.text = "";
|
||||
final res = ndk.broadcast.broadcast(nostrEvent: chatMsg);
|
||||
await res.broadcastDoneFuture;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final canSign = ndk.accounts.canSign;
|
||||
final isLogin = ndk.accounts.isLoggedIn;
|
||||
|
||||
return Container(
|
||||
margin: EdgeInsets.fromLTRB(4, 8, 4, 0),
|
||||
padding: EdgeInsets.symmetric(horizontal: 8),
|
||||
decoration: BoxDecoration(color: LAYER_2, borderRadius: DEFAULT_BR),
|
||||
child:
|
||||
canSign
|
||||
? Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _controller,
|
||||
onSubmitted: (_) => _sendMessage(),
|
||||
decoration: InputDecoration(
|
||||
labelText: "Write message",
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 4),
|
||||
labelStyle: TextStyle(color: LAYER_4, fontSize: 14),
|
||||
border: InputBorder.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
//IconButton(onPressed: () {}, icon: Icon(Icons.mood)),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
_sendMessage();
|
||||
},
|
||||
icon: Icon(Icons.send),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
isLogin
|
||||
? "Can't write messages with npub login"
|
||||
: "Please login to send messages",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -6,8 +6,17 @@ import 'package:zap_stream_flutter/widgets/button.dart';
|
||||
|
||||
class MuteButton extends StatelessWidget {
|
||||
final String pubkey;
|
||||
final void Function()? onTap;
|
||||
final void Function()? onMute;
|
||||
final void Function()? onUnmute;
|
||||
|
||||
const MuteButton({super.key, required this.pubkey});
|
||||
const MuteButton({
|
||||
super.key,
|
||||
required this.pubkey,
|
||||
this.onTap,
|
||||
this.onMute,
|
||||
this.onUnmute,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -32,6 +41,9 @@ class MuteButton extends StatelessWidget {
|
||||
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 12),
|
||||
decoration: BoxDecoration(color: WARNING, borderRadius: DEFAULT_BR),
|
||||
onTap: () async {
|
||||
if (onTap != null) {
|
||||
onTap!();
|
||||
}
|
||||
if (isMuted) {
|
||||
await ndk.lists.broadcastRemoveNip51ListElement(
|
||||
Nip51List.kMute,
|
||||
@ -39,6 +51,9 @@ class MuteButton extends StatelessWidget {
|
||||
pubkey,
|
||||
null,
|
||||
);
|
||||
if (onUnmute != null) {
|
||||
onUnmute!();
|
||||
}
|
||||
} else {
|
||||
await ndk.lists.broadcastAddNip51ListElement(
|
||||
Nip51List.kMute,
|
||||
@ -46,9 +61,10 @@ class MuteButton extends StatelessWidget {
|
||||
pubkey,
|
||||
null,
|
||||
);
|
||||
|
||||
if (onMute != null) {
|
||||
onMute!();
|
||||
}
|
||||
if (ctx.mounted) {
|
||||
Navigator.pop(ctx);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
@ -14,6 +14,7 @@ class ProfileLoaderWidget extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder(
|
||||
key: super.key ?? Key("profile-loader:$pubkey"),
|
||||
future: ndk.metadata.loadMetadata(pubkey),
|
||||
builder: builder,
|
||||
);
|
||||
@ -26,14 +27,14 @@ class ProfileNameWidget extends StatelessWidget {
|
||||
|
||||
const ProfileNameWidget({super.key, required this.profile, this.style});
|
||||
|
||||
static Widget pubkey(String pubkey, {TextStyle? style}) {
|
||||
return FutureBuilder(
|
||||
future: ndk.metadata.loadMetadata(pubkey),
|
||||
builder:
|
||||
static Widget pubkey(String pubkey, {Key? key, TextStyle? style}) {
|
||||
return ProfileLoaderWidget(
|
||||
pubkey,
|
||||
(ctx, data) => ProfileNameWidget(
|
||||
profile: data.data ?? Metadata(pubKey: pubkey),
|
||||
style: style,
|
||||
),
|
||||
key: key,
|
||||
);
|
||||
}
|
||||
|
||||
@ -84,6 +85,7 @@ class ProfileWidget extends StatelessWidget {
|
||||
List<Widget>? children,
|
||||
bool? showName,
|
||||
double? spacing,
|
||||
Key? key,
|
||||
}) {
|
||||
return ProfileLoaderWidget(pubkey, (ctx, state) {
|
||||
return ProfileWidget(
|
||||
@ -91,6 +93,7 @@ class ProfileWidget extends StatelessWidget {
|
||||
size: size,
|
||||
showName: showName,
|
||||
spacing: spacing,
|
||||
key: key,
|
||||
children: children,
|
||||
);
|
||||
});
|
||||
@ -102,7 +105,7 @@ class ProfileWidget extends StatelessWidget {
|
||||
spacing: spacing ?? 8,
|
||||
children: [
|
||||
AvatarWidget(profile: profile, size: size),
|
||||
if (showName ?? true) ProfileNameWidget(profile: profile),
|
||||
if (showName ?? true) ProfileNameWidget(profile: profile, key: key),
|
||||
...(children ?? []),
|
||||
],
|
||||
);
|
||||
|
30
pubspec.lock
30
pubspec.lock
@ -580,26 +580,28 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "packages/ndk"
|
||||
ref: bbf2aa9c2468b2301de65734199649d56bb0fd74
|
||||
resolved-ref: bbf2aa9c2468b2301de65734199649d56bb0fd74
|
||||
ref: "919f35866f4b9d84565f7f08ebbbcd5fd0ef0b6a"
|
||||
resolved-ref: "919f35866f4b9d84565f7f08ebbbcd5fd0ef0b6a"
|
||||
url: "https://github.com/relaystr/ndk"
|
||||
source: git
|
||||
version: "0.3.2"
|
||||
ndk_amber:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: ndk_amber
|
||||
sha256: "6f525e2bcdea08ecdd1815e2fdfc6e53c4bb86335927d8c333c1f4513dc1c099"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
path: "packages/amber"
|
||||
ref: "919f35866f4b9d84565f7f08ebbbcd5fd0ef0b6a"
|
||||
resolved-ref: "919f35866f4b9d84565f7f08ebbbcd5fd0ef0b6a"
|
||||
url: "https://github.com/relaystr/ndk"
|
||||
source: git
|
||||
version: "0.3.0"
|
||||
ndk_objectbox:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: ndk_objectbox
|
||||
sha256: f2bd04299ed34b99a01957c46eb6ff495c0bdcde068d382cbb8b8a222f67e132
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
path: "packages/objectbox"
|
||||
ref: "919f35866f4b9d84565f7f08ebbbcd5fd0ef0b6a"
|
||||
resolved-ref: "919f35866f4b9d84565f7f08ebbbcd5fd0ef0b6a"
|
||||
url: "https://github.com/relaystr/ndk"
|
||||
source: git
|
||||
version: "0.2.3"
|
||||
ndk_rust_verifier:
|
||||
dependency: "direct main"
|
||||
@ -1198,6 +1200,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.5.0"
|
||||
xxh3:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: xxh3
|
||||
sha256: "399a0438f5d426785723c99da6b16e136f4953fb1e9db0bf270bd41dd4619916"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
sdks:
|
||||
dart: ">=3.7.2 <4.0.0"
|
||||
flutter: ">=3.27.0"
|
||||
|
12
pubspec.yaml
12
pubspec.yaml
@ -38,7 +38,17 @@ dependency_overrides:
|
||||
git:
|
||||
url: https://github.com/relaystr/ndk
|
||||
path: packages/ndk
|
||||
ref: bbf2aa9c2468b2301de65734199649d56bb0fd74
|
||||
ref: 919f35866f4b9d84565f7f08ebbbcd5fd0ef0b6a
|
||||
ndk_objectbox:
|
||||
git:
|
||||
url: https://github.com/relaystr/ndk
|
||||
path: packages/objectbox
|
||||
ref: 919f35866f4b9d84565f7f08ebbbcd5fd0ef0b6a
|
||||
ndk_amber:
|
||||
git:
|
||||
url: https://github.com/relaystr/ndk
|
||||
path: packages/amber
|
||||
ref: 919f35866f4b9d84565f7f08ebbbcd5fd0ef0b6a
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
Reference in New Issue
Block a user