feat: setup deep link handler

closes #34
This commit is contained in:
2025-05-22 10:46:47 +01:00
parent 4e4061b808
commit 4db0317c0b
2 changed files with 41 additions and 1 deletions

View File

@ -76,7 +76,7 @@ void runZapStream() {
if (state.extra is StreamEvent) {
return StreamPage(stream: state.extra as StreamEvent);
} else {
throw UnimplementedError();
return StreamPage.loader(state.pathParameters["id"]!);
}
},
),
@ -119,6 +119,21 @@ void runZapStream() {
),
],
),
GoRoute(
path: "/:id",
redirect: (context, state) {
final id = state.pathParameters["id"]!;
if (id.startsWith("naddr1") ||
id.startsWith("nevent1") ||
id.startsWith("note1")) {
return "/e/$id";
} else if (id.startsWith("npub1") ||
id.startsWith("nprofile1")) {
return "/p/$id";
}
return null;
},
),
],
),
],

View File

@ -1,5 +1,6 @@
import 'dart:developer' as developer;
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:ndk/ndk.dart';
@ -24,6 +25,30 @@ class StreamPage extends StatefulWidget {
const StreamPage({super.key, required this.stream});
static Widget loader(String id) {
final entity = decodeBech32ToTLVEntity(id);
return RxFilter<Nip01Event>(
Key("stream-loader:$id"),
filters: [entity.toFilter()],
builder: (context, state) {
final stream = state?.firstWhereOrNull(
(e) => e.getDtag() == entity.specialUtf8,
);
if (stream != null) {
return StreamPage(stream: StreamEvent(stream));
} else {
return Center(
child: SizedBox(
width: 40,
height: 40,
child: CircularProgressIndicator(),
),
);
}
},
);
}
@override
State<StatefulWidget> createState() => _StreamPage();
}