use extended_image

This commit is contained in:
quantulr
2023-02-13 00:36:25 +08:00
parent 9261d482cf
commit cdd930d523
5 changed files with 89 additions and 116 deletions

View File

@ -1,4 +1,5 @@
import 'package:dio/dio.dart';
import 'package:extended_image/extended_image.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
@ -32,10 +33,6 @@ class _ImageDetailState extends ConsumerState<ImageDetail> {
// double dx=0;
double _scale = 1;
Offset offsetBeforeDrag = const Offset(0, 0);
Offset origin = const Offset(0, 0);
double ox = 0;
@override
Widget build(BuildContext context) {
String id = GoRouterState.of(context).queryParams["id"] ?? "";
@ -48,95 +45,27 @@ class _ImageDetailState extends ConsumerState<ImageDetail> {
alignment: Alignment.center,
children: [
Positioned(
// left: dx,
child: GestureDetector(
onTapDown: (TapDownDetails details) {
print("tap start");
print(details.globalPosition.dx);
offsetBeforeDrag = details.globalPosition;
},
child: Draggable(
onDragUpdate: (details) {
print("on drag update");
print(details.globalPosition.dx - offsetBeforeDrag.dx);
// print(details.localPosition - offsetBeforeDrag);
// print(offsetBeforeDrag.dx - details.localPosition.dx);
// print(offsetBeforeDrag.dy - details.localPosition.dy);
//
setState(() {
origin = (offsetBeforeDrag - details.localPosition);
// /
// (_scale - 1);
});
},
feedback: const SizedBox(),
child: FutureBuilder(
future: loadImage(id),
builder: (BuildContext context, snapshot) {
if (snapshot.hasData) {
// return ClipRect(
// child: SizedBox(
// width: double.infinity,
// height: double.infinity,
// child: Transform.scale(
// origin: Offset(0, 0),
// scale: _scale,
// child: Image.network(
// "${dio.options.baseUrl}/image/${snapshot.data?.file_path}",
// loadingBuilder: (BuildContext context, child,
// loadingProgress) {
// if (loadingProgress == null) {
// return child;
// }
// return Center(
// child: CircularProgressIndicator(
// value: loadingProgress.expectedTotalBytes !=
// null
// ? loadingProgress
// .cumulativeBytesLoaded /
// loadingProgress.expectedTotalBytes!
// : null,
// ),
// );
// }),
// ),
// ),
// );
return Image.network(
"${dio.options.baseUrl}/image/${snapshot.data?.file_path}",
loadingBuilder:
(BuildContext context, child, loadingProgress) {
if (loadingProgress == null) {
return ClipRect(
child: SizedBox(
width: double.infinity,
height: double.infinity,
child: Transform.scale(
origin: Offset(166, 0),
scale: _scale,
child: child),
),
);
}
return Center(
child: CircularProgressIndicator(
value: loadingProgress.expectedTotalBytes != null
? loadingProgress.cumulativeBytesLoaded /
loadingProgress.expectedTotalBytes!
: null,
),
);
});
} else if (snapshot.hasError) {
print(snapshot.error);
return ErrorWidget("err");
}
return CircularProgressIndicator();
}),
),
),
),
child: FutureBuilder(
future: loadImage(id),
builder: (context, snapshot) {
if (snapshot.hasData) {
return ClipRect(
child: SizedBox(
width: double.infinity,
height: double.infinity,
child: ExtendedImage.network(
"${dio.options.baseUrl}/image/${snapshot.data?.file_path}",
mode: ExtendedImageMode.gesture,
// scale: 3,
),
));
} else if (snapshot.hasError) {
return ErrorWidget("13");
}
return const Center(
child: CircularProgressIndicator(),
);
})),
Positioned(
bottom: 10,
child: Card(
@ -156,31 +85,16 @@ class _ImageDetailState extends ConsumerState<ImageDetail> {
},
icon: const Icon(Icons.delete)),
IconButton(
onPressed: _scale > 0.2
? () {
setState(() {
_scale -= 1;
});
}
: null,
onPressed: _scale > 0.2 ? () {} : null,
icon: const Icon(Icons.remove_circle_outline)),
IconButton(
onPressed: _scale < 10
? () {
setState(() {
_scale += 1;
});
}
: null,
onPressed: _scale < 10 ? () {} : null,
icon: const Icon(Icons.add_circle_outline)),
IconButton(
onPressed: () {
setState(() {
// _scale += 0.1;
ox += 100 / 2;
});
setState(() {});
},
icon: const Icon(Icons.chevron_left)),
icon: const Icon(Icons.menu_rounded)),
],
),
),

View File

@ -27,8 +27,8 @@ class MyMaterialRouterConfig {
GoRoute(
path: "/",
name: "相册",
builder: (BuildContext context, GoRouterState state) =>
const Gallery(),
pageBuilder: (BuildContext context, GoRouterState state) =>
const NoTransitionPage(child: Gallery()),
redirect: (BuildContext context, GoRouterState state) {
if (token == null || token.isEmpty) {
return '/login';
@ -45,8 +45,8 @@ class MyMaterialRouterConfig {
GoRoute(
path: "/profile",
name: "个人资料",
builder: (BuildContext context, GoRouterState state) =>
const Profile()),
pageBuilder: (BuildContext context, GoRouterState state) =>
const NoTransitionPage(child: Profile())),
],
),
GoRoute(

View File

@ -5,6 +5,7 @@
import FlutterMacOS
import Foundation
import path_provider_foundation
import screen_retriever
import shared_preferences_foundation
import tray_manager
@ -12,6 +13,7 @@ import url_launcher_macos
import window_manager
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
TrayManagerPlugin.register(with: registry.registrar(forPlugin: "TrayManagerPlugin"))

View File

@ -217,6 +217,22 @@ packages:
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "4.0.6"
extended_image:
dependency: "direct main"
description:
name: extended_image
sha256: "6494c5728d0a8216fafcda7a4125f7a6da3d510ab00677a630d01dbb1125da96"
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "7.0.1"
extended_image_library:
dependency: transitive
description:
name: extended_image_library
sha256: b1de389378589e4dffb3564d782373238f19064037458092c49b3043b2791b2b
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "3.4.1"
fake_async:
dependency: transitive
description:
@ -365,6 +381,22 @@ packages:
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.2.0"
http:
dependency: transitive
description:
name: http
sha256: "6aa2946395183537c8b880962d935877325d6a09a2867c3970c05c0fed6ac482"
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "0.13.5"
http_client_helper:
dependency: transitive
description:
name: http_client_helper
sha256: "1f32359bd07a064ad256d1f84ae5f973f69bc972e7287223fa198abe1d969c28"
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.0.3"
http_multi_server:
dependency: transitive
description:
@ -509,6 +541,30 @@ packages:
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "1.8.2"
path_provider:
dependency: transitive
description:
name: path_provider
sha256: dcea5feb97d8abf90cab9e9030b497fb7c3cbf26b7a1fe9e3ef7dcb0a1ddec95
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.0.12"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
sha256: a776c088d671b27f6e3aa8881d64b87b3e80201c64e8869b811325de7a76c15e
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.0.22"
path_provider_foundation:
dependency: transitive
description:
name: path_provider_foundation
sha256: "62a68e7e1c6c459f9289859e2fae58290c981ce21d1697faf54910fe1faa4c74"
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.1.1"
path_provider_linux:
dependency: transitive
description:

View File

@ -50,6 +50,7 @@ dependencies:
http_parser: ^4.0.2
mime: ^1.0.4
context_menus: ^1.0.2
extended_image: ^7.0.1
dev_dependencies:
flutter_test: