From 9261d482cf475b53d9966a531614ce7267d8843f Mon Sep 17 00:00:00 2001 From: quantulr <35954003+quantulr@users.noreply.github.com> Date: Sun, 12 Feb 2023 23:39:41 +0800 Subject: [PATCH] image scale --- lib/main.dart | 2 +- lib/material/detail.dart | 107 ++++++++++++++++++++++++++++++-------- lib/material/gallery.dart | 7 ++- lib/material/profile.dart | 15 +++--- lib/material/router.dart | 10 ++-- pubspec.lock | 20 +++---- pubspec.yaml | 1 - 7 files changed, 110 insertions(+), 52 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 026062d..a3317fe 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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, diff --git a/lib/material/detail.dart b/lib/material/detail.dart index 07a4c56..2d73893 100644 --- a/lib/material/detail.dart +++ b/lib/material/detail.dart @@ -29,10 +29,13 @@ class _ImageDetailState extends ConsumerState { 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 { 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 { } return CircularProgressIndicator(); }), - )), + ), + ), + ), Positioned( bottom: 10, child: Card( @@ -105,19 +156,31 @@ class _ImageDetailState extends ConsumerState { }, 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)), ], ), ), diff --git a/lib/material/gallery.dart b/lib/material/gallery.dart index b70adbe..c0577d6 100644 --- a/lib/material/gallery.dart +++ b/lib/material/gallery.dart @@ -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, + ), ); } } diff --git a/lib/material/profile.dart b/lib/material/profile.dart index 29ee929..fd7f9c0 100644 --- a/lib/material/profile.dart +++ b/lib/material/profile.dart @@ -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')), + ), ); } } diff --git a/lib/material/router.dart b/lib/material/router.dart index bb9de47..46555c5 100644 --- a/lib/material/router.dart +++ b/lib/material/router.dart @@ -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( diff --git a/pubspec.lock b/pubspec.lock index aca4b7c..9f80a76 100644 --- a/pubspec.lock +++ b/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: diff --git a/pubspec.yaml b/pubspec.yaml index 8ad4fcb..c275129 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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