forked from alexvasl/drifter_app
Authorization for entering a private key has been set up.
This commit is contained in:
parent
d25e5074f6
commit
a5fc25ddec
@ -1,5 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:drifter/pages/login_screen/login_screen.dart';
|
||||
import 'package:drifter/pages/main_screen/main_screen_widget.dart';
|
||||
import 'package:drifter/pages/splash_screen/splash_screen.dart';
|
||||
import 'package:drifter/theme/app_colors.dart';
|
||||
@ -25,7 +26,10 @@ class MyApp extends StatelessWidget {
|
||||
unselectedItemColor: Colors.grey,
|
||||
),
|
||||
),
|
||||
home: const Splash(),
|
||||
routes: {
|
||||
'/': (context) => const Splash(),
|
||||
'/login': (context) => const LoginScreen(),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,10 @@ import 'package:drifter/pages/profile_screen/widgets/message_snack_bar.dart';
|
||||
import 'package:drifter/pages/profile_screen/widgets/ok_button_widget.dart';
|
||||
|
||||
import 'package:drifter/theme/app_colors.dart';
|
||||
import 'package:drifter/utilities/assets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:nostr_tools/nostr_tools.dart';
|
||||
|
||||
class LoginScreen extends StatefulWidget {
|
||||
@ -25,9 +27,34 @@ class LoginScreenState extends State<LoginScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView(
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
SvgPicture.asset(
|
||||
Assets.svg.drifterIcon,
|
||||
height: 30,
|
||||
width: 30,
|
||||
alignment: Alignment.centerLeft,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 125,
|
||||
),
|
||||
const Text(
|
||||
"Login",
|
||||
style: TextStyle(
|
||||
color: AppColors.mainAccent,
|
||||
),
|
||||
// textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: ListView(
|
||||
children: [
|
||||
const SizedBox(
|
||||
height: 200,
|
||||
),
|
||||
Padding(
|
||||
@ -54,8 +81,8 @@ class LoginScreenState extends State<LoginScreen> {
|
||||
return 'Please enter your private key';
|
||||
}
|
||||
try {
|
||||
bool isValidHexKey =
|
||||
Nostr.instance.keysService.isValidPrivateKey(value);
|
||||
bool isValidHexKey = Nostr.instance.keysService
|
||||
.isValidPrivateKey(value);
|
||||
bool isValidNSec = value.trim().startsWith('nsec') &&
|
||||
Nostr.instance.keysService.isValidPrivateKey(Nostr
|
||||
.instance.keysService
|
||||
@ -119,25 +146,17 @@ class LoginScreenState extends State<LoginScreen> {
|
||||
nsecKey = nip19.nsecEncode(privateKeyHex);
|
||||
npubKey = nip19.npubEncode(publicKeyHex);
|
||||
}
|
||||
try {
|
||||
ProfileScreenState().addKeyToStorage(
|
||||
privateKeyHex, publicKeyHex, nsecKey, npubKey);
|
||||
|
||||
ProfileScreenState()
|
||||
.addKeyToStorage(
|
||||
privateKeyHex, publicKeyHex, nsecKey, npubKey)
|
||||
.then((keysAdded) {
|
||||
if (keysAdded) {
|
||||
keyController.clear();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
MessageSnackBar(label: 'Congratulations! Keys Stored!'),
|
||||
);
|
||||
// setState() {
|
||||
// Keys.privateKey = privateKeyHex;
|
||||
// Keys.publicKey = publicKeyHex;
|
||||
// Keys.nsecKey = nsecKey;
|
||||
// Keys.npubKey = npubKey;
|
||||
// Keys.keysExist = true;
|
||||
// }
|
||||
}
|
||||
});
|
||||
|
||||
Navigator.of(context).pop(true);
|
||||
} catch (e) {}
|
||||
} else {
|
||||
formKey.currentState?.setState(() {});
|
||||
}
|
||||
@ -145,6 +164,6 @@ class LoginScreenState extends State<LoginScreen> {
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import 'package:drifter/pages/login_screen/login_screen.dart';
|
||||
import 'package:drifter/pages/message_screen/message_screen_widget.dart';
|
||||
import 'package:drifter/pages/profile_screen/profile_screen.dart';
|
||||
import 'package:drifter/theme/app_colors.dart';
|
||||
import 'package:drifter/main.dart';
|
||||
import 'package:drifter/utilities/assets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
@ -59,7 +60,7 @@ class _MainScreenWidgetState extends State<MainScreenWidget> {
|
||||
HomeScreen(),
|
||||
MessageScreen(),
|
||||
ProfileScreen(),
|
||||
LoginScreen(),
|
||||
// LoginScreen(),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
@ -77,10 +78,10 @@ class _MainScreenWidgetState extends State<MainScreenWidget> {
|
||||
icon: Icon(Icons.person),
|
||||
label: 'Profile',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.login),
|
||||
label: 'Login',
|
||||
),
|
||||
// BottomNavigationBarItem(
|
||||
// icon: Icon(Icons.login),
|
||||
// label: 'Login',
|
||||
// ),
|
||||
],
|
||||
onTap: onSelectedtap,
|
||||
),
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'package:dart_nostr/dart_nostr.dart';
|
||||
import 'package:drifter/models/keys.dart';
|
||||
import 'package:drifter/pages/profile_screen/widgets/delete_keys_dialog.dart';
|
||||
import 'package:drifter/main.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';
|
||||
@ -174,10 +175,12 @@ class ProfileScreenState extends State<ProfileScreen> {
|
||||
// 'Keys',
|
||||
// ),
|
||||
// )
|
||||
: ElevatedButton(
|
||||
: Row(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
style: ButtonStyle(
|
||||
backgroundColor:
|
||||
MaterialStateProperty.all(AppColors.background)),
|
||||
backgroundColor: MaterialStateProperty.all(
|
||||
AppColors.background)),
|
||||
onPressed: () {
|
||||
modalBottomSheet();
|
||||
},
|
||||
@ -185,6 +188,22 @@ class ProfileScreenState extends State<ProfileScreen> {
|
||||
'Generate Keys',
|
||||
),
|
||||
),
|
||||
SizedBox(width: 100),
|
||||
ElevatedButton(
|
||||
style: ButtonStyle(
|
||||
backgroundColor: MaterialStateProperty.all(
|
||||
AppColors.background)),
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, '/login').then((_) {
|
||||
initState();
|
||||
});
|
||||
},
|
||||
child: const Text(
|
||||
'Login',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Keys.keysExist
|
||||
? Row(
|
||||
children: [
|
||||
|
Loading…
Reference in New Issue
Block a user