WIP: moved functions around, working on pub/priv key display

This commit is contained in:
Rylee Davis 2023-05-19 09:49:35 -06:00
parent 6012526b33
commit 136e7efc3d

View File

@ -126,7 +126,7 @@ class ProfileScreenState extends State<ProfileScreen> {
}); });
} }
void keysExistDialog(String npubEncode, String nsecEncode) async { void _keysExistDialog(String npubEncode, String nsecEncode) async {
await showDialog( await showDialog(
context: context, context: context,
builder: ((context) { builder: ((context) {
@ -145,32 +145,127 @@ class ProfileScreenState extends State<ProfileScreen> {
privateKeyInput.text = Keys.nsecKey; privateKeyInput.text = Keys.nsecKey;
publicKeyInput.text = Keys.npubKey; publicKeyInput.text = Keys.npubKey;
return ListView( return Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
const SizedBox( const SizedBox(
height: 60, height: 60,
), ),
Padding( UserInfo(),
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: UserInfo(),
),
const SizedBox( const SizedBox(
height: 40, height: 40,
), ),
FormKeys(), Row(
SizedBox(height: 20),
Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [ children: [
Text(
"Public Key",
textAlign: TextAlign.start,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.grey[700],
),
),
],
),
const SizedBox(height: 12),
publicKeyInput.text.isNotEmpty
? SelectableText(
publicKeyInput.text,
style: TextStyle(
fontSize: 16,
color: Colors.grey[800],
),
)
: Text(
"Public Key empty",
textAlign: TextAlign.left,
),
const SizedBox(
height: 12,
),
Row(
children: [
Text(
"Private Key",
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.grey[700],
),
),
],
),
const SizedBox(height: 12),
privateKeyInput.text.isNotEmpty
? SelectableText(
privateKeyInput.text,
style: TextStyle(
fontSize: 16,
color: Colors.grey[800],
),
)
: Text(
"Private Key empty",
textAlign: TextAlign.left,
),
const SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Keys.keysExist
? Row(
children: [
ElevatedButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.grey[500]),
),
onPressed: () {
showDialog(
context: context,
builder: (context) => DeleteKeysDialog(
onNoPressed: () {
Navigator.pop(context);
},
onYesPressed: () {
final currentContext = context;
_deleteKeysStorage().then(
(_) {
if (!Keys.keysExist) {
showFloatingFlushBar(
type: FlushBarType.warning,
message: "Keys deleted!",
context: context,
);
}
},
);
Navigator.pop(context);
},
),
);
},
child: Text(
"Delete",
),
),
],
)
: Container(),
Keys.keysExist Keys.keysExist
? ElevatedButton( ? ElevatedButton(
style: ButtonStyle( style: ButtonStyle(
backgroundColor: MaterialStateProperty.all( backgroundColor:
AppColors.mainDarkBlue)), MaterialStateProperty.all(AppColors.background),
),
onPressed: () { onPressed: () {
keysExistDialog( _keysExistDialog(
Nostr.instance.keysService Nostr.instance.keysService
.encodePublicKeyToNpub(Keys.publicKey), .encodePublicKeyToNpub(Keys.publicKey),
Nostr.instance.keysService Nostr.instance.keysService
@ -184,7 +279,8 @@ class ProfileScreenState extends State<ProfileScreen> {
: ElevatedButton( : ElevatedButton(
style: ButtonStyle( style: ButtonStyle(
backgroundColor: backgroundColor:
MaterialStateProperty.all(AppColors.background)), MaterialStateProperty.all(AppColors.background),
),
onPressed: () { onPressed: () {
final currentContext = context; final currentContext = context;
generateNewKeys().then( generateNewKeys().then(
@ -202,86 +298,13 @@ class ProfileScreenState extends State<ProfileScreen> {
}, },
); );
}, },
child: Text( child: const Text(
"Generate Keys", "Generate Keys",
), ),
), ),
Keys.keysExist
? Row(
children: [
IconButton(
onPressed: () {
showDialog(
context: context,
builder: (context) => DeleteKeysDialog(
onNoPressed: () {
Navigator.pop(context);
},
onYesPressed: () {
final currentContext = context;
_deleteKeysStorage().then((_) {
if (!Keys.keysExist) {
showFloatingFlushBar(
type: FlushBarType.warning,
message: "Keys deleted!",
context: context,
);
}
});
Navigator.pop(context);
},
),
);
},
icon: const Icon(Icons.delete)),
],
)
: Container(),
], ],
), ),
)
], ],
);
}
Form FormKeys() {
return Form(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
TextFormField(
controller: privateKeyInput,
// _toHex ? widget.hexPriv : widget.nsecEncoded,
decoration: const InputDecoration(
labelText: 'Private Key',
border: OutlineInputBorder(),
),
maxLength: 64,
),
const SizedBox(
height: 20,
),
TextFormField(
controller: publicKeyInput,
// _toHex ? widget.hexPub : widget.npubEncoded,
decoration: const InputDecoration(
labelText: 'Public Key',
border: OutlineInputBorder(),
),
),
const SizedBox(
height: 40,
),
TextFormField(
decoration: const InputDecoration(
labelText: 'Relay',
border: OutlineInputBorder(),
),
),
],
),
), ),
); );
} }