mirror of
https://github.com/haorendashu/nowser.git
synced 2025-12-18 18:14:21 +01:00
init nostr and add userinfo provider
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nostr_sdk/nip19/nip19.dart';
|
||||
import 'package:nostr_sdk/utils/string_util.dart';
|
||||
import 'package:nowser/data/metadata.dart';
|
||||
import 'package:nowser/provider/userinfo_provider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class UserNameComponent extends StatefulWidget {
|
||||
String pubkey;
|
||||
@@ -17,15 +21,29 @@ class UserNameComponent extends StatefulWidget {
|
||||
class _UserNameComponent extends State<UserNameComponent> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var npub = Nip19.encodePubKey(widget.pubkey);
|
||||
if (!widget.fullNpubName) {
|
||||
npub = Nip19.encodeSimplePubKey(widget.pubkey);
|
||||
}
|
||||
return Selector<UserinfoProvider, Metadata?>(
|
||||
builder: (context, metadata, child) {
|
||||
var npub = Nip19.encodePubKey(widget.pubkey);
|
||||
if (!widget.fullNpubName) {
|
||||
npub = Nip19.encodeSimplePubKey(widget.pubkey);
|
||||
}
|
||||
var name = npub;
|
||||
|
||||
return Text(
|
||||
npub,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
);
|
||||
if (metadata != null) {
|
||||
if (StringUtil.isNotBlank(metadata.displayName)) {
|
||||
name = metadata.displayName!;
|
||||
} else if (StringUtil.isNotBlank(metadata.name)) {
|
||||
name = metadata.name!;
|
||||
}
|
||||
}
|
||||
|
||||
return Text(
|
||||
name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
);
|
||||
}, selector: (context, _provider) {
|
||||
return _provider.getMetadata(widget.pubkey);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nostr_sdk/utils/string_util.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../data/metadata.dart';
|
||||
import '../../provider/userinfo_provider.dart';
|
||||
import '../image_component.dart';
|
||||
|
||||
class UserPicComponent extends StatefulWidget {
|
||||
String pubkey;
|
||||
|
||||
double width;
|
||||
|
||||
UserPicComponent({required this.width});
|
||||
UserPicComponent({
|
||||
required this.pubkey,
|
||||
required this.width,
|
||||
});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
@@ -14,20 +25,37 @@ class UserPicComponent extends StatefulWidget {
|
||||
class _UserPicComponent extends State<UserPicComponent> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget innerWidget = Icon(
|
||||
Icons.account_circle,
|
||||
size: widget.width,
|
||||
);
|
||||
return Selector<UserinfoProvider, Metadata?>(
|
||||
builder: (context, metadata, child) {
|
||||
Widget innerWidget = Icon(
|
||||
Icons.account_circle,
|
||||
size: widget.width,
|
||||
);
|
||||
|
||||
return Container(
|
||||
width: widget.width,
|
||||
height: widget.width,
|
||||
clipBehavior: Clip.hardEdge,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(widget.width / 2),
|
||||
),
|
||||
child: innerWidget,
|
||||
);
|
||||
if (metadata != null && StringUtil.isNotBlank(metadata.picture)) {
|
||||
innerWidget = ImageComponent(
|
||||
imageUrl: metadata.picture!,
|
||||
width: widget.width,
|
||||
height: widget.width,
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (context, url) => CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
width: widget.width,
|
||||
height: widget.width,
|
||||
clipBehavior: Clip.hardEdge,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(widget.width / 2),
|
||||
),
|
||||
child: innerWidget,
|
||||
);
|
||||
}, selector: (context, _provider) {
|
||||
if (StringUtil.isNotBlank(widget.pubkey)) {
|
||||
return _provider.getMetadata(widget.pubkey);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user