mirror of
https://github.com/nostrlabs-io/zap-stream-flutter.git
synced 2025-06-15 19:48:23 +00:00
56
lib/pages/login_input.dart
Normal file
56
lib/pages/login_input.dart
Normal file
@ -0,0 +1,56 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:ndk/shared/nips/nip19/nip19.dart';
|
||||
import 'package:zap_stream_flutter/login.dart';
|
||||
import 'package:zap_stream_flutter/main.dart';
|
||||
import 'package:zap_stream_flutter/theme.dart';
|
||||
import 'package:zap_stream_flutter/widgets/button.dart';
|
||||
|
||||
class LoginInputPage extends StatefulWidget {
|
||||
const LoginInputPage({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _LoginInputPage();
|
||||
}
|
||||
|
||||
class _LoginInputPage extends State<LoginInputPage> {
|
||||
final TextEditingController _controller = TextEditingController();
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
spacing: 20,
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: _controller,
|
||||
decoration: InputDecoration(labelText: "npub/nsec"),
|
||||
),
|
||||
BasicButton.text(
|
||||
"Login",
|
||||
onTap: () async {
|
||||
try {
|
||||
final keyData = Nip19.decode(_controller.text);
|
||||
if (keyData.isNotEmpty) {
|
||||
loginData.value = LoginAccount.nip19(_controller.text);
|
||||
context.go("/");
|
||||
} else {
|
||||
throw "Invalid key";
|
||||
}
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_error = e.toString();
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
if (_error != null)
|
||||
Text(
|
||||
_error!,
|
||||
style: TextStyle(color: WARNING, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user