forked from alexvasl/drifter_app
added flush bar for keys gen/delete
This commit is contained in:
parent
651a4e2421
commit
834af8472a
@ -2,9 +2,9 @@ import 'package:dart_nostr/dart_nostr.dart';
|
|||||||
import 'package:drifter/models/keys.dart';
|
import 'package:drifter/models/keys.dart';
|
||||||
import 'package:drifter/pages/profile_screen/widgets/delete_keys_dialog.dart';
|
import 'package:drifter/pages/profile_screen/widgets/delete_keys_dialog.dart';
|
||||||
import 'package:drifter/pages/profile_screen/widgets/key_exist_dialog.dart';
|
import 'package:drifter/pages/profile_screen/widgets/key_exist_dialog.dart';
|
||||||
import 'package:drifter/pages/profile_screen/widgets/keys_option_modal_bottom_sheet.dart';
|
|
||||||
import 'package:drifter/pages/profile_screen/widgets/message_snack_bar.dart';
|
|
||||||
import 'package:drifter/pages/profile_screen/widgets/user_info_widget.dart';
|
import 'package:drifter/pages/profile_screen/widgets/user_info_widget.dart';
|
||||||
|
import 'package:drifter/pages/widgets/flust_bar_type.dart';
|
||||||
|
import 'package:drifter/pages/widgets/show_flush_bar.dart';
|
||||||
import 'package:drifter/theme/app_colors.dart';
|
import 'package:drifter/theme/app_colors.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
@ -126,6 +126,20 @@ class ProfileScreenState extends State<ProfileScreen> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void keysExistDialog(String npubEncode, String nsecEncode) async {
|
||||||
|
await showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: ((context) {
|
||||||
|
return KeysExistDialog(
|
||||||
|
npubEncoded: npubEncode,
|
||||||
|
nsecEncoded: nsecEncode,
|
||||||
|
hexPriv: Keys.privateKey,
|
||||||
|
hexPub: Keys.publicKey,
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
privateKeyInput.text = Keys.nsecKey;
|
privateKeyInput.text = Keys.nsecKey;
|
||||||
@ -133,11 +147,14 @@ class ProfileScreenState extends State<ProfileScreen> {
|
|||||||
|
|
||||||
return ListView(
|
return ListView(
|
||||||
children: [
|
children: [
|
||||||
SizedBox(
|
const SizedBox(
|
||||||
height: 60,
|
height: 60,
|
||||||
),
|
),
|
||||||
UserInfo(),
|
Padding(
|
||||||
SizedBox(
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||||
|
child: UserInfo(),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
height: 40,
|
height: 40,
|
||||||
),
|
),
|
||||||
FormKeys(),
|
FormKeys(),
|
||||||
@ -161,18 +178,32 @@ class ProfileScreenState extends State<ProfileScreen> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
'Keys',
|
"Keys",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: ElevatedButton(
|
: ElevatedButton(
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
backgroundColor: MaterialStateProperty.all(
|
backgroundColor:
|
||||||
AppColors.mainDarkBlue)),
|
MaterialStateProperty.all(AppColors.background)),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
modalBottomSheet();
|
final currentContext = context;
|
||||||
|
generateNewKeys().then(
|
||||||
|
(keysGenerated) async {
|
||||||
|
if (keysGenerated) {
|
||||||
|
await Future<void>.delayed(
|
||||||
|
const Duration(milliseconds: 300));
|
||||||
|
|
||||||
|
showFloatingFlushBar(
|
||||||
|
type: FlushBarType.success,
|
||||||
|
message: "Keys generated!",
|
||||||
|
context: context,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
'Generate Keys',
|
"Generate Keys",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Keys.keysExist
|
Keys.keysExist
|
||||||
@ -180,7 +211,27 @@ class ProfileScreenState extends State<ProfileScreen> {
|
|||||||
children: [
|
children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
deleteKeysDialog();
|
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)),
|
icon: const Icon(Icons.delete)),
|
||||||
],
|
],
|
||||||
@ -234,66 +285,4 @@ class ProfileScreenState extends State<ProfileScreen> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void modalBottomSheet() {
|
|
||||||
showModalBottomSheet(
|
|
||||||
context: context,
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
return KeysOptionModalBottomSheet(
|
|
||||||
generateNewKeyPressed: () {
|
|
||||||
final currentContext = context;
|
|
||||||
generateNewKeys().then(
|
|
||||||
(keysGenerated) {
|
|
||||||
if (keysGenerated) {
|
|
||||||
ScaffoldMessenger.of(currentContext).showSnackBar(
|
|
||||||
MessageSnackBar(label: 'Keys Generated!'));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void keysExistDialog(String npubEncode, String nsecEncode) async {
|
|
||||||
await showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: ((context) {
|
|
||||||
return KeysExistDialog(
|
|
||||||
npubEncoded: npubEncode,
|
|
||||||
nsecEncoded: nsecEncode,
|
|
||||||
hexPriv: Keys.privateKey,
|
|
||||||
hexPub: Keys.publicKey,
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void deleteKeysDialog() async {
|
|
||||||
await showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: ((context) {
|
|
||||||
return DeleteKeysDialog(
|
|
||||||
onNoPressed: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
onYesPressed: () {
|
|
||||||
final currentContext = context;
|
|
||||||
_deleteKeysStorage().then((_) {
|
|
||||||
if (!Keys.keysExist) {
|
|
||||||
ScaffoldMessenger.of(currentContext).showSnackBar(
|
|
||||||
MessageSnackBar(
|
|
||||||
label: 'Keys successfully deleted!',
|
|
||||||
isWarning: true,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import 'package:drifter/pages/animated_widgets/rotate_icon.dart';
|
|
||||||
import 'package:drifter/pages/main_screen/main_screen_widget.dart';
|
import 'package:drifter/pages/main_screen/main_screen_widget.dart';
|
||||||
|
import 'package:drifter/pages/widgets/animated_widgets/rotate_icon.dart';
|
||||||
import 'package:drifter/theme/app_colors.dart';
|
import 'package:drifter/theme/app_colors.dart';
|
||||||
|
import 'package:drifter/utilities/assets.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
import 'package:flutter_svg/svg.dart';
|
||||||
|
|
||||||
import '../../utilities/assets.dart';
|
|
||||||
|
|
||||||
class Splash extends StatefulWidget {
|
class Splash extends StatefulWidget {
|
||||||
const Splash({super.key});
|
const Splash({super.key});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user