search image in SauceNAO

This commit is contained in:
quantulr
2023-05-14 22:32:13 +08:00
parent c430ef1621
commit eb918803d4
7 changed files with 77 additions and 140 deletions

View File

@ -7,6 +7,7 @@ import 'package:go_router/go_router.dart';
import 'package:momo/models/image_resp.dart';
import 'package:momo/provider/rerender.dart';
import 'package:momo/request/http_client.dart';
import 'package:url_launcher/url_launcher.dart';
class ImageDetail extends ConsumerStatefulWidget {
const ImageDetail({Key? key}) : super(key: key);
@ -33,6 +34,16 @@ class _ImageDetailState extends ConsumerState<ImageDetail> {
// double dx=0;
double _scale = 1;
Future<void> _launchInBrowser(Uri url) async {
if (!await launchUrl(
url,
mode: LaunchMode.externalApplication,
)) {
throw Exception('Could not launch $url');
}
}
@override
Widget build(BuildContext context) {
String id = GoRouterState.of(context).queryParams["id"] ?? "";
@ -91,7 +102,17 @@ class _ImageDetailState extends ConsumerState<ImageDetail> {
onPressed: _scale < 10 ? () {} : null,
icon: const Icon(Icons.add_circle_outline)),
IconButton(
onPressed: () {
onPressed: () async {
final image = await loadImage(id);
final imageUrl =
"https://raichi.hodokencho.com/api/image/${image?.file_path}";
final launchUrl =
"https://saucenao.com/search.php?url=${Uri.encodeComponent(imageUrl)}";
_launchInBrowser(Uri.parse(launchUrl));
},
icon: const Icon(Icons.search)),
IconButton(
onPressed: () async {
setState(() {});
},
icon: const Icon(Icons.menu_rounded)),