mirror of
https://github.com/nostrlabs-io/zap-stream-flutter.git
synced 2025-06-16 03:58:09 +00:00
@ -4,56 +4,53 @@ 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 LoginPage extends StatefulWidget {
|
||||
class LoginPage extends StatelessWidget {
|
||||
const LoginPage({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _LoginPage();
|
||||
}
|
||||
|
||||
class _LoginPage extends State<LoginPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(top: 50),
|
||||
child: Column(
|
||||
spacing: 10,
|
||||
children: [
|
||||
Image.asset("assets/logo.png", height: 150),
|
||||
FutureBuilder(
|
||||
future: Amberflutter().isAppInstalled(),
|
||||
builder: (ctx, state) {
|
||||
if (state.data ?? false) {
|
||||
return BasicButton.text(
|
||||
"Login with Amber",
|
||||
onTap: () async {
|
||||
final amber = Amberflutter();
|
||||
final result = await amber.getPublicKey();
|
||||
if (result['signature'] != null) {
|
||||
final key = Nip19.decode(result['signature']);
|
||||
loginData.value = Account.externalPublicKeyHex(key);
|
||||
ctx.go("/");
|
||||
}
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return SizedBox.shrink();
|
||||
}
|
||||
},
|
||||
return Column(
|
||||
spacing: 20,
|
||||
children: [
|
||||
FutureBuilder(
|
||||
future: Amberflutter().isAppInstalled(),
|
||||
builder: (ctx, state) {
|
||||
if (state.data ?? false) {
|
||||
return BasicButton.text(
|
||||
"Login with Amber",
|
||||
onTap: () async {
|
||||
final amber = Amberflutter();
|
||||
final result = await amber.getPublicKey();
|
||||
if (result['signature'] != null) {
|
||||
final key = Nip19.decode(result['signature']);
|
||||
loginData.value = LoginAccount.externalPublicKeyHex(key);
|
||||
ctx.go("/");
|
||||
}
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return SizedBox.shrink();
|
||||
}
|
||||
},
|
||||
),
|
||||
BasicButton.text(
|
||||
"Login with Key",
|
||||
onTap: () => context.push("/login/key"),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.symmetric(vertical: 20),
|
||||
height: 1,
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: LAYER_2)),
|
||||
),
|
||||
/*BasicButton.text("Login with Key"),
|
||||
Container(
|
||||
margin: EdgeInsets.symmetric(vertical: 20),
|
||||
height: 1,
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: LAYER_1)),
|
||||
),
|
||||
),
|
||||
Text("Create Account"),*/
|
||||
],
|
||||
),
|
||||
),
|
||||
BasicButton.text(
|
||||
"Create Account",
|
||||
onTap: () => context.push("/login/new"),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
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),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
121
lib/pages/new_account.dart
Normal file
121
lib/pages/new_account.dart
Normal file
@ -0,0 +1,121 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:ndk/ndk.dart';
|
||||
import 'package:ndk/shared/nips/nip01/bip340.dart';
|
||||
import 'package:ndk/shared/nips/nip01/key_pair.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 NewAccountPage extends StatefulWidget {
|
||||
const NewAccountPage({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _NewAccountPage();
|
||||
}
|
||||
|
||||
class _NewAccountPage extends State<NewAccountPage> {
|
||||
final TextEditingController _name = TextEditingController();
|
||||
String? _avatar;
|
||||
String? _error;
|
||||
final KeyPair _privateKey = Bip340.generatePrivateKey();
|
||||
|
||||
Future<void> _uploadAvatar() async {
|
||||
ndk.accounts.loginPrivateKey(
|
||||
pubkey: _privateKey.publicKey,
|
||||
privkey: _privateKey.privateKey!,
|
||||
);
|
||||
|
||||
final file = await ImagePicker().pickImage(source: ImageSource.gallery);
|
||||
if (file != null) {
|
||||
final upload = await ndk.blossom.uploadBlob(
|
||||
serverUrls: ["https://nostr.download"],
|
||||
data: await file.readAsBytes(),
|
||||
);
|
||||
setState(() {
|
||||
_avatar = upload.first.descriptor!.url;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _login() async {
|
||||
if (ndk.accounts.isNotLoggedIn) {
|
||||
ndk.accounts.loginPrivateKey(
|
||||
pubkey: _privateKey.publicKey,
|
||||
privkey: _privateKey.privateKey!,
|
||||
);
|
||||
}
|
||||
|
||||
await ndk.metadata.broadcastMetadata(
|
||||
Metadata(
|
||||
pubKey: _privateKey.publicKey,
|
||||
name: _name.text,
|
||||
picture: _avatar,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
spacing: 20,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
_uploadAvatar().catchError((e) {
|
||||
setState(() {
|
||||
if (e is String) {
|
||||
_error = e;
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
width: 200,
|
||||
height: 200,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.all(Radius.circular(200)),
|
||||
color: Color.fromARGB(100, 50, 50, 50),
|
||||
),
|
||||
child:
|
||||
_avatar == null
|
||||
? Center(child: Text("Upload Avatar"))
|
||||
: CachedNetworkImage(imageUrl: _avatar!),
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
controller: _name,
|
||||
decoration: InputDecoration(labelText: "Username"),
|
||||
),
|
||||
BasicButton.text(
|
||||
"Login",
|
||||
onTap: () {
|
||||
_login()
|
||||
.then((_) {
|
||||
loginData.value = LoginAccount.privateKeyHex(
|
||||
_privateKey.privateKey!,
|
||||
);
|
||||
context.go("/");
|
||||
})
|
||||
.catchError((e) {
|
||||
setState(() {
|
||||
if (e is String) {
|
||||
_error = e;
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
),
|
||||
if (_error != null)
|
||||
Text(
|
||||
_error!,
|
||||
style: TextStyle(color: WARNING, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:chewie/chewie.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||
import 'package:zap_stream_flutter/imgproxy.dart';
|
||||
import 'package:zap_stream_flutter/main.dart';
|
||||
import 'package:zap_stream_flutter/theme.dart';
|
||||
import 'package:zap_stream_flutter/utils.dart';
|
||||
@ -38,17 +40,20 @@ class _StreamPage extends State<StreamPage> {
|
||||
_controller = VideoPlayerController.networkUrl(
|
||||
Uri.parse(url),
|
||||
httpHeaders: Map.from({"user-agent": userAgent}),
|
||||
videoPlayerOptions: VideoPlayerOptions(allowBackgroundPlayback: true),
|
||||
);
|
||||
() async {
|
||||
await _controller!.initialize();
|
||||
|
||||
_chewieController = ChewieController(
|
||||
videoPlayerController: _controller!,
|
||||
autoPlay: true,
|
||||
);
|
||||
setState(() {
|
||||
// nothing
|
||||
_chewieController = ChewieController(
|
||||
videoPlayerController: _controller!,
|
||||
autoPlay: true,
|
||||
placeholder:
|
||||
(widget.stream.info.image?.isNotEmpty ?? false)
|
||||
? CachedNetworkImage(
|
||||
imageUrl: proxyImg(context, widget.stream.info.image!),
|
||||
)
|
||||
: null,
|
||||
);
|
||||
});
|
||||
}();
|
||||
}
|
||||
@ -75,7 +80,18 @@ class _StreamPage extends State<StreamPage> {
|
||||
child:
|
||||
_chewieController != null
|
||||
? Chewie(controller: _chewieController!)
|
||||
: Container(color: LAYER_1),
|
||||
: Container(
|
||||
color: LAYER_1,
|
||||
child:
|
||||
(widget.stream.info.image?.isNotEmpty ?? false)
|
||||
? CachedNetworkImage(
|
||||
imageUrl: proxyImg(
|
||||
context,
|
||||
widget.stream.info.image!,
|
||||
),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
widget.stream.info.title ?? "",
|
||||
|
Reference in New Issue
Block a user