search image in SauceNAO
This commit is contained in:
@ -19,14 +19,12 @@ class MyMaterialApp extends ConsumerWidget {
|
|||||||
// UniqueKey uniqueKey = ref.watch(uniqueIdProvider);
|
// UniqueKey uniqueKey = ref.watch(uniqueIdProvider);
|
||||||
MyMaterialRouterConfig myMaterialRouterConfig =
|
MyMaterialRouterConfig myMaterialRouterConfig =
|
||||||
MyMaterialRouterConfig(token);
|
MyMaterialRouterConfig(token);
|
||||||
|
return MaterialApp.router(
|
||||||
return SafeArea(
|
|
||||||
child: MaterialApp.router(
|
|
||||||
routerConfig: myMaterialRouterConfig.router,
|
routerConfig: myMaterialRouterConfig.router,
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
theme:
|
theme:
|
||||||
ThemeData(useMaterial3: true, scaffoldBackgroundColor: Colors.white),
|
ThemeData(useMaterial3: true, scaffoldBackgroundColor: Colors.white),
|
||||||
));
|
);
|
||||||
// return FutureBuilder(
|
// return FutureBuilder(
|
||||||
// future: loadToken(),
|
// future: loadToken(),
|
||||||
// builder: (BuildContext context, AsyncSnapshot<String?> snapshot) {
|
// builder: (BuildContext context, AsyncSnapshot<String?> snapshot) {
|
||||||
|
@ -7,6 +7,7 @@ import 'package:go_router/go_router.dart';
|
|||||||
import 'package:momo/models/image_resp.dart';
|
import 'package:momo/models/image_resp.dart';
|
||||||
import 'package:momo/provider/rerender.dart';
|
import 'package:momo/provider/rerender.dart';
|
||||||
import 'package:momo/request/http_client.dart';
|
import 'package:momo/request/http_client.dart';
|
||||||
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
class ImageDetail extends ConsumerStatefulWidget {
|
class ImageDetail extends ConsumerStatefulWidget {
|
||||||
const ImageDetail({Key? key}) : super(key: key);
|
const ImageDetail({Key? key}) : super(key: key);
|
||||||
@ -33,6 +34,16 @@ class _ImageDetailState extends ConsumerState<ImageDetail> {
|
|||||||
// double dx=0;
|
// double dx=0;
|
||||||
double _scale = 1;
|
double _scale = 1;
|
||||||
|
|
||||||
|
|
||||||
|
Future<void> _launchInBrowser(Uri url) async {
|
||||||
|
if (!await launchUrl(
|
||||||
|
url,
|
||||||
|
mode: LaunchMode.externalApplication,
|
||||||
|
)) {
|
||||||
|
throw Exception('Could not launch $url');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
String id = GoRouterState.of(context).queryParams["id"] ?? "";
|
String id = GoRouterState.of(context).queryParams["id"] ?? "";
|
||||||
@ -91,7 +102,17 @@ class _ImageDetailState extends ConsumerState<ImageDetail> {
|
|||||||
onPressed: _scale < 10 ? () {} : null,
|
onPressed: _scale < 10 ? () {} : null,
|
||||||
icon: const Icon(Icons.add_circle_outline)),
|
icon: const Icon(Icons.add_circle_outline)),
|
||||||
IconButton(
|
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(() {});
|
setState(() {});
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.menu_rounded)),
|
icon: const Icon(Icons.menu_rounded)),
|
||||||
|
@ -37,13 +37,7 @@ class ImageGrid extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ImageGridState extends State<ImageGrid> {
|
class _ImageGridState extends State<ImageGrid> {
|
||||||
late ScrollController _scrollController;
|
|
||||||
|
|
||||||
List<ImageResp> imageList = [];
|
|
||||||
int pageNum = 1;
|
|
||||||
int pageSize = 10;
|
int pageSize = 10;
|
||||||
bool hasMore = true;
|
|
||||||
bool loading = false;
|
|
||||||
|
|
||||||
final PagingController<int, ImageResp> _pagingController =
|
final PagingController<int, ImageResp> _pagingController =
|
||||||
PagingController(firstPageKey: 1);
|
PagingController(firstPageKey: 1);
|
||||||
@ -66,26 +60,6 @@ class _ImageGridState extends State<ImageGrid> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<dynamic> loadImages() async {
|
|
||||||
loading = true;
|
|
||||||
if (!hasMore) {
|
|
||||||
loading = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
print(pageNum);
|
|
||||||
var resp = await dio.get("/image/history",
|
|
||||||
queryParameters: {"page": pageNum, "size": pageSize});
|
|
||||||
ImageListResp imageListResp = ImageListResp.fromJson(resp.data);
|
|
||||||
hasMore = imageListResp.hasNext;
|
|
||||||
pageNum = pageNum + 1;
|
|
||||||
if (mounted) {
|
|
||||||
setState(() {
|
|
||||||
imageList.addAll(imageListResp.list);
|
|
||||||
});
|
|
||||||
loading = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
// TODO: implement initState
|
// TODO: implement initState
|
||||||
@ -93,39 +67,19 @@ class _ImageGridState extends State<ImageGrid> {
|
|||||||
_fetchPage(pageKey);
|
_fetchPage(pageKey);
|
||||||
});
|
});
|
||||||
super.initState();
|
super.initState();
|
||||||
// print("init");
|
|
||||||
//
|
|
||||||
// _scrollController = ScrollController(initialScrollOffset: 5.0)
|
|
||||||
// ..addListener(() {
|
|
||||||
// if (_scrollController.offset >=
|
|
||||||
// _scrollController.position.maxScrollExtent &&
|
|
||||||
// !_scrollController.position.outOfRange) {
|
|
||||||
// print("到底了 controller $loading");
|
|
||||||
// if (!loading) {
|
|
||||||
// loadImages();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// loadImages();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return PagedGridView(
|
return RefreshIndicator(
|
||||||
|
child: PagedGridView(
|
||||||
pagingController: _pagingController,
|
pagingController: _pagingController,
|
||||||
builderDelegate: PagedChildBuilderDelegate<ImageResp>(
|
builderDelegate: PagedChildBuilderDelegate<ImageResp>(
|
||||||
itemBuilder: (context, item, index) => ImageItem(image: item)),
|
itemBuilder: (context, item, index) => ImageItem(image: item)),
|
||||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
crossAxisCount: MediaQuery.of(context).size.width > 640 ? 5 : 3),
|
crossAxisCount: MediaQuery.of(context).size.width > 640 ? 5 : 3),
|
||||||
);
|
),
|
||||||
// return GridView.builder(
|
onRefresh: () => Future.sync(() => _pagingController.refresh()));
|
||||||
// itemCount: imageList.length,
|
|
||||||
// controller: _scrollController,
|
|
||||||
// gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
|
||||||
// crossAxisCount: MediaQuery.of(context).size.width > 640 ? 5 : 3),
|
|
||||||
// itemBuilder: (BuildContext context, int index) {
|
|
||||||
// return ImageItem(image: imageList[index]);
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +100,6 @@ class _ImageItemState extends ConsumerState<ImageItem> {
|
|||||||
if (_contextMenuController.isShown) {
|
if (_contextMenuController.isShown) {
|
||||||
_contextMenuController.remove();
|
_contextMenuController.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,44 +186,7 @@ class _ImageItemState extends ConsumerState<ImageItem> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return CupertinoContextMenu(
|
return GestureDetector(
|
||||||
actions: [
|
|
||||||
CupertinoContextMenuAction(
|
|
||||||
trailingIcon: CupertinoIcons.delete,
|
|
||||||
child: const Text('删除'),
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
// Navigator.pop(context);
|
|
||||||
// showDialog(
|
|
||||||
// context: context,
|
|
||||||
// builder: (BuildContext dialogContext) => AlertDialog(
|
|
||||||
// title: const Text('删除图片'),
|
|
||||||
// content: const Text("确认删除图片"),
|
|
||||||
// actions: [
|
|
||||||
// TextButton(
|
|
||||||
// onPressed: () =>
|
|
||||||
// Navigator.pop(dialogContext, 'Cancel'),
|
|
||||||
// child: const Text('Cancel'),
|
|
||||||
// ),
|
|
||||||
// TextButton(
|
|
||||||
// onPressed: () {
|
|
||||||
// Navigator.pop(dialogContext, 'OK');
|
|
||||||
// // Navigator.pop(context);
|
|
||||||
// dio
|
|
||||||
// .delete("/image/delete/${widget.image.id}")
|
|
||||||
// .then((resp) {
|
|
||||||
// ref.read(uniqueIdProvider.notifier).updateId();
|
|
||||||
// // context.go("/");
|
|
||||||
// });
|
|
||||||
// },
|
|
||||||
// child: const Text('OK'),
|
|
||||||
// ),
|
|
||||||
// ],
|
|
||||||
// ));
|
|
||||||
},
|
|
||||||
)
|
|
||||||
],
|
|
||||||
child: GestureDetector(
|
|
||||||
onSecondaryTapUp: (TapUpDetails details) {
|
onSecondaryTapUp: (TapUpDetails details) {
|
||||||
_showContextMenu(details.globalPosition);
|
_showContextMenu(details.globalPosition);
|
||||||
},
|
},
|
||||||
@ -288,6 +204,6 @@ class _ImageItemState extends ConsumerState<ImageItem> {
|
|||||||
return const Icon(Icons.error_outline);
|
return const Icon(Icons.error_outline);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@ class MyMaterialRouterConfig {
|
|||||||
|
|
||||||
final GlobalKey<NavigatorState> _rootNavigatorKey =
|
final GlobalKey<NavigatorState> _rootNavigatorKey =
|
||||||
GlobalKey<NavigatorState>();
|
GlobalKey<NavigatorState>();
|
||||||
|
final GlobalKey<NavigatorState> _shellNavigatorKey =
|
||||||
|
GlobalKey<NavigatorState>();
|
||||||
|
|
||||||
MyMaterialRouterConfig(String? token) {
|
MyMaterialRouterConfig(String? token) {
|
||||||
router = GoRouter(
|
router = GoRouter(
|
||||||
@ -18,6 +20,7 @@ class MyMaterialRouterConfig {
|
|||||||
initialLocation: "/",
|
initialLocation: "/",
|
||||||
routes: <RouteBase>[
|
routes: <RouteBase>[
|
||||||
ShellRoute(
|
ShellRoute(
|
||||||
|
navigatorKey: _shellNavigatorKey,
|
||||||
builder: (BuildContext context, GoRouterState state, Widget child) {
|
builder: (BuildContext context, GoRouterState state, Widget child) {
|
||||||
return HomePage(
|
return HomePage(
|
||||||
content: child,
|
content: child,
|
||||||
@ -28,7 +31,9 @@ class MyMaterialRouterConfig {
|
|||||||
path: "/",
|
path: "/",
|
||||||
name: "相册",
|
name: "相册",
|
||||||
pageBuilder: (BuildContext context, GoRouterState state) =>
|
pageBuilder: (BuildContext context, GoRouterState state) =>
|
||||||
const NoTransitionPage(child: Gallery()),
|
const NoTransitionPage(
|
||||||
|
child: Gallery(),
|
||||||
|
),
|
||||||
redirect: (BuildContext context, GoRouterState state) {
|
redirect: (BuildContext context, GoRouterState state) {
|
||||||
if (token == null || token.isEmpty) {
|
if (token == null || token.isEmpty) {
|
||||||
return '/login';
|
return '/login';
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
// import 'package:fluent_ui/fluent_ui.dart';
|
|
||||||
// import 'package:fluentui_system_icons/fluentui_system_icons.dart'
|
|
||||||
// as fluentui_system_icons;
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
|
@ -900,7 +900,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.2"
|
version: "1.3.2"
|
||||||
url_launcher:
|
url_launcher:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: url_launcher
|
name: url_launcher
|
||||||
sha256: eb1e00ab44303d50dd487aab67ebc575456c146c6af44422f9c13889984c00f3
|
sha256: eb1e00ab44303d50dd487aab67ebc575456c146c6af44422f9c13889984c00f3
|
||||||
|
@ -54,6 +54,7 @@ dependencies:
|
|||||||
git:
|
git:
|
||||||
url: https://github.com/fluttercandies/extended_image.git
|
url: https://github.com/fluttercandies/extended_image.git
|
||||||
infinite_scroll_pagination: ^3.2.0
|
infinite_scroll_pagination: ^3.2.0
|
||||||
|
url_launcher: ^6.1.11
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Reference in New Issue
Block a user