mirror of
https://github.com/nostrlabs-io/zap-stream-flutter.git
synced 2025-06-16 20:08:50 +00:00
refactor: minor profile loader improvement
This commit is contained in:
@ -6,6 +6,7 @@ import 'package:zap_stream_flutter/const.dart';
|
||||
import 'package:zap_stream_flutter/theme.dart';
|
||||
import 'package:zap_stream_flutter/widgets/avatar_upload.dart';
|
||||
import 'package:zap_stream_flutter/widgets/button.dart';
|
||||
import 'package:zap_stream_flutter/widgets/profile.dart';
|
||||
|
||||
class SettingsProfilePage extends StatelessWidget {
|
||||
final TextEditingController _picture = TextEditingController();
|
||||
@ -22,97 +23,94 @@ class SettingsProfilePage extends StatelessWidget {
|
||||
final pubkey = ndk.accounts.getPublicKey();
|
||||
if (pubkey == null) return Text(t.settings.profile.error.logged_out);
|
||||
|
||||
return FutureBuilder(
|
||||
future: ndk.metadata.loadMetadata(pubkey),
|
||||
builder: (context, state) {
|
||||
if (state.hasData) {
|
||||
_name.text = state.data!.name ?? "";
|
||||
_about.text = state.data!.about ?? "";
|
||||
_nip5.text = state.data!.nip05 ?? "";
|
||||
_lud16.text = state.data!.lud16 ?? "";
|
||||
_picture.text = state.data!.picture ?? "";
|
||||
}
|
||||
return ValueListenableBuilder(
|
||||
valueListenable: _loading,
|
||||
builder: (context, v, _) {
|
||||
return Column(
|
||||
spacing: 16,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Center(
|
||||
child: AvatarUpload(
|
||||
key: Key("avatar:${_picture.text}"),
|
||||
avatar: _picture.text.isEmpty ? null : _picture.text,
|
||||
onUpload: (i) {
|
||||
_picture.text = i;
|
||||
},
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
controller: _name,
|
||||
readOnly: v,
|
||||
decoration: InputDecoration(
|
||||
labelText: t.settings.profile.display_name,
|
||||
fillColor: LAYER_1,
|
||||
filled: true,
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
controller: _about,
|
||||
readOnly: v,
|
||||
decoration: InputDecoration(
|
||||
labelText: t.settings.profile.about,
|
||||
fillColor: LAYER_1,
|
||||
filled: true,
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
controller: _nip5,
|
||||
readOnly: v,
|
||||
decoration: InputDecoration(
|
||||
labelText: t.settings.profile.nip05,
|
||||
fillColor: LAYER_1,
|
||||
filled: true,
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
controller: _lud16,
|
||||
readOnly: v,
|
||||
decoration: InputDecoration(
|
||||
labelText: t.settings.profile.lud16,
|
||||
fillColor: LAYER_1,
|
||||
filled: true,
|
||||
),
|
||||
),
|
||||
BasicButton.text(
|
||||
t.button.save,
|
||||
disabled: v,
|
||||
onTap: (context) async {
|
||||
_loading.value = true;
|
||||
try {
|
||||
final newMeta = Metadata(
|
||||
pubKey: pubkey,
|
||||
name: _name.text.isEmpty ? null : _name.text,
|
||||
about: _about.text.isEmpty ? null : _about.text,
|
||||
picture: _picture.text.isEmpty ? null : _picture.text,
|
||||
nip05: _nip5.text.isEmpty ? null : _nip5.text,
|
||||
lud16: _lud16.text.isEmpty ? null : _lud16.text,
|
||||
);
|
||||
await ndk.metadata.broadcastMetadata(newMeta);
|
||||
if (context.mounted) {
|
||||
context.pop();
|
||||
}
|
||||
} finally {
|
||||
_loading.value = false;
|
||||
}
|
||||
return ProfileLoaderWidget(pubkey, (context, state) {
|
||||
if (state.hasData) {
|
||||
_name.text = state.data!.name ?? "";
|
||||
_about.text = state.data!.about ?? "";
|
||||
_nip5.text = state.data!.nip05 ?? "";
|
||||
_lud16.text = state.data!.lud16 ?? "";
|
||||
_picture.text = state.data!.picture ?? "";
|
||||
}
|
||||
return ValueListenableBuilder(
|
||||
valueListenable: _loading,
|
||||
builder: (context, v, _) {
|
||||
return Column(
|
||||
spacing: 16,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Center(
|
||||
child: AvatarUpload(
|
||||
key: Key("avatar:${_picture.text}"),
|
||||
avatar: _picture.text.isEmpty ? null : _picture.text,
|
||||
onUpload: (i) {
|
||||
_picture.text = i;
|
||||
},
|
||||
),
|
||||
if (v) Center(child: CircularProgressIndicator()),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
),
|
||||
TextField(
|
||||
controller: _name,
|
||||
readOnly: v,
|
||||
decoration: InputDecoration(
|
||||
labelText: t.settings.profile.display_name,
|
||||
fillColor: LAYER_1,
|
||||
filled: true,
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
controller: _about,
|
||||
readOnly: v,
|
||||
decoration: InputDecoration(
|
||||
labelText: t.settings.profile.about,
|
||||
fillColor: LAYER_1,
|
||||
filled: true,
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
controller: _nip5,
|
||||
readOnly: v,
|
||||
decoration: InputDecoration(
|
||||
labelText: t.settings.profile.nip05,
|
||||
fillColor: LAYER_1,
|
||||
filled: true,
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
controller: _lud16,
|
||||
readOnly: v,
|
||||
decoration: InputDecoration(
|
||||
labelText: t.settings.profile.lud16,
|
||||
fillColor: LAYER_1,
|
||||
filled: true,
|
||||
),
|
||||
),
|
||||
BasicButton.text(
|
||||
t.button.save,
|
||||
disabled: v,
|
||||
onTap: (context) async {
|
||||
_loading.value = true;
|
||||
try {
|
||||
final newMeta = Metadata(
|
||||
pubKey: pubkey,
|
||||
name: _name.text.isEmpty ? null : _name.text,
|
||||
about: _about.text.isEmpty ? null : _about.text,
|
||||
picture: _picture.text.isEmpty ? null : _picture.text,
|
||||
nip05: _nip5.text.isEmpty ? null : _nip5.text,
|
||||
lud16: _lud16.text.isEmpty ? null : _lud16.text,
|
||||
);
|
||||
await ndk.metadata.broadcastMetadata(newMeta);
|
||||
if (context.mounted) {
|
||||
context.pop();
|
||||
}
|
||||
} finally {
|
||||
_loading.value = false;
|
||||
}
|
||||
},
|
||||
),
|
||||
if (v) Center(child: CircularProgressIndicator()),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user