image scale
This commit is contained in:
@ -14,7 +14,7 @@ void main() async {
|
||||
// Must add this line.
|
||||
await windowManager.ensureInitialized();
|
||||
WindowOptions windowOptions = const WindowOptions(
|
||||
size: Size(800, 600),
|
||||
size: Size(880, 600),
|
||||
center: true,
|
||||
minimumSize: Size(300, 400),
|
||||
// backgroundColor: Colors.transparent,
|
||||
|
@ -29,10 +29,13 @@ class _ImageDetailState extends ConsumerState<ImageDetail> {
|
||||
return null;
|
||||
}
|
||||
|
||||
double? dx;
|
||||
double? dy;
|
||||
// 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"] ?? "";
|
||||
@ -40,34 +43,80 @@ class _ImageDetailState extends ConsumerState<ImageDetail> {
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
color: Colors.white,
|
||||
// TODO: 缩放组件溢出
|
||||
// TODO: 拖动
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Positioned(
|
||||
left: dx,
|
||||
top: dy,
|
||||
// left: dx,
|
||||
|
||||
child: GestureDetector(
|
||||
onTapDown: (TapDownDetails details) {
|
||||
print("tap start");
|
||||
print(details.globalPosition.dx);
|
||||
offsetBeforeDrag = details.globalPosition;
|
||||
},
|
||||
child: Draggable(
|
||||
onDragUpdate: (drag) {
|
||||
print(drag);
|
||||
// setState(() {
|
||||
// dx = drag.localPosition.dx;
|
||||
// dy = drag.localPosition.dy;
|
||||
// });
|
||||
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 Transform.scale(
|
||||
scale: _scale,
|
||||
child: child,
|
||||
return ClipRect(
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
child: Transform.scale(
|
||||
origin: Offset(166, 0),
|
||||
scale: _scale,
|
||||
child: child),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Center(
|
||||
@ -85,7 +134,9 @@ class _ImageDetailState extends ConsumerState<ImageDetail> {
|
||||
}
|
||||
return CircularProgressIndicator();
|
||||
}),
|
||||
)),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
bottom: 10,
|
||||
child: Card(
|
||||
@ -105,19 +156,31 @@ class _ImageDetailState extends ConsumerState<ImageDetail> {
|
||||
},
|
||||
icon: const Icon(Icons.delete)),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_scale -= 0.1;
|
||||
});
|
||||
},
|
||||
onPressed: _scale > 0.2
|
||||
? () {
|
||||
setState(() {
|
||||
_scale -= 1;
|
||||
});
|
||||
}
|
||||
: null,
|
||||
icon: const Icon(Icons.remove_circle_outline)),
|
||||
IconButton(
|
||||
onPressed: _scale < 10
|
||||
? () {
|
||||
setState(() {
|
||||
_scale += 1;
|
||||
});
|
||||
}
|
||||
: null,
|
||||
icon: const Icon(Icons.add_circle_outline)),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_scale += 0.1;
|
||||
// _scale += 0.1;
|
||||
ox += 100 / 2;
|
||||
});
|
||||
},
|
||||
icon: const Icon(Icons.add_circle_outline)),
|
||||
icon: const Icon(Icons.chevron_left)),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -12,8 +12,11 @@ class Gallery extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
UniqueKey key = ref.watch(uniqueIdProvider);
|
||||
return ImageGrid(
|
||||
key: key,
|
||||
return Container(
|
||||
color: Colors.white,
|
||||
child: ImageGrid(
|
||||
key: key,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,15 @@ class Profile extends ConsumerWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
ref.watch(tokenProvider.notifier).removeToken();
|
||||
},
|
||||
child: const Text('quit')),
|
||||
return Container(
|
||||
color: Colors.white,
|
||||
child: Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
ref.watch(tokenProvider.notifier).removeToken();
|
||||
},
|
||||
child: const Text('quit')),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -27,10 +27,8 @@ class MyMaterialRouterConfig {
|
||||
GoRoute(
|
||||
path: "/",
|
||||
name: "相册",
|
||||
pageBuilder: (BuildContext context, GoRouterState state) =>
|
||||
const NoTransitionPage(
|
||||
child: Gallery(),
|
||||
),
|
||||
builder: (BuildContext context, GoRouterState state) =>
|
||||
const Gallery(),
|
||||
redirect: (BuildContext context, GoRouterState state) {
|
||||
if (token == null || token.isEmpty) {
|
||||
return '/login';
|
||||
@ -47,8 +45,8 @@ class MyMaterialRouterConfig {
|
||||
GoRoute(
|
||||
path: "/profile",
|
||||
name: "个人资料",
|
||||
pageBuilder: (BuildContext context, GoRouterState state) =>
|
||||
const NoTransitionPage(child: Profile())),
|
||||
builder: (BuildContext context, GoRouterState state) =>
|
||||
const Profile()),
|
||||
],
|
||||
),
|
||||
GoRoute(
|
||||
|
20
pubspec.lock
20
pubspec.lock
@ -29,10 +29,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: args
|
||||
sha256: "139d809800a412ebb26a3892da228b2d0ba36f0ef5d9a82166e5e52ec8d61611"
|
||||
sha256: "4cab82a83ffef80b262ddedf47a0a8e56ee6fbf7fe21e6e768b02792034dd440"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
source: hosted
|
||||
version: "2.3.2"
|
||||
version: "2.4.0"
|
||||
async:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -365,14 +365,6 @@ packages:
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
http:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: http
|
||||
sha256: "6aa2946395183537c8b880962d935877325d6a09a2867c3970c05c0fed6ac482"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
source: hosted
|
||||
version: "0.13.5"
|
||||
http_multi_server:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -521,10 +513,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_linux
|
||||
sha256: ab0987bf95bc591da42dffb38c77398fc43309f0b9b894dcc5d6f40c4b26c379
|
||||
sha256: "2e32f1640f07caef0d3cb993680f181c79e54a3827b997d5ee221490d131fbd9"
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
source: hosted
|
||||
version: "2.1.7"
|
||||
version: "2.1.8"
|
||||
path_provider_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -934,10 +926,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: xdg_directories
|
||||
sha256: bd512f03919aac5f1313eb8249f223bacf4927031bf60b02601f81f687689e86
|
||||
sha256: ee1505df1426458f7f60aac270645098d318a8b4766d85fde75f76f2e21807d1
|
||||
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
|
||||
source: hosted
|
||||
version: "0.2.0+3"
|
||||
version: "1.0.0"
|
||||
xml:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -39,7 +39,6 @@ dependencies:
|
||||
go_router: ^6.0.1
|
||||
fluentui_system_icons: ^1.1.190
|
||||
json_annotation: ^4.8.0
|
||||
http: ^0.13.5
|
||||
fluent_ui: ^4.2.0
|
||||
flutter_launcher_icons: ^0.11.0
|
||||
shared_preferences: ^2.0.17
|
||||
|
Reference in New Issue
Block a user