From 7124e884e2c8bff0f64eb1872ee462a88af159f4 Mon Sep 17 00:00:00 2001 From: Abobo7 <2557826346@qq.com> Date: Mon, 25 Nov 2024 15:32:25 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E5=88=A4=E6=96=AD=E6=9C=89=E6=97=A0?= =?UTF-8?q?=E4=BA=8C=E7=BB=B4=E7=A0=81+=E5=BC=B9=E5=87=BA=E5=8A=A8?= =?UTF-8?q?=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../view/image_view/image_view_page.dart | 88 ++++++++++++++++--- 1 file changed, 74 insertions(+), 14 deletions(-) diff --git a/lib/feedback/view/image_view/image_view_page.dart b/lib/feedback/view/image_view/image_view_page.dart index 900c9018..3bd547d6 100644 --- a/lib/feedback/view/image_view/image_view_page.dart +++ b/lib/feedback/view/image_view/image_view_page.dart @@ -17,6 +17,7 @@ import 'package:qr_code_tools/qr_code_tools.dart'; import '../../../commons/themes/template/wpy_theme_data.dart'; import '../../../commons/themes/wpy_theme.dart'; +import 'package:flutter/animation.dart'; class ImageViewPageArgs { final List urlList; @@ -37,14 +38,36 @@ class ImageViewPage extends StatefulWidget { _ImageViewPageState createState() => _ImageViewPageState(); } -class _ImageViewPageState extends State { +class _ImageViewPageState extends State + with SingleTickerProviderStateMixin { final String baseUrl = '${EnvConfig.QNHDPIC}download/origin/'; late int indexNow; + bool hasQRCode = false; + + late AnimationController _animationController; + late Animation _scaleAnimation; @override void initState() { indexNow = widget.args.indexNow; super.initState(); + _checkQRCode(); + + _animationController = AnimationController( + vsync: this, + duration: Duration(milliseconds: 300), + ); + + _scaleAnimation = CurvedAnimation( + parent: _animationController, + curve: Curves.easeOutBack, + ); + } + + @override + void dispose() { + _animationController.dispose(); + super.dispose(); } @override @@ -96,7 +119,11 @@ class _ImageViewPageState extends State { initialPage: indexNow, ), onPageChanged: (c) { - indexNow = c; + setState(() { + indexNow = c; + hasQRCode = false; + }); + _checkQRCode(); }, ), Align( @@ -111,7 +138,6 @@ class _ImageViewPageState extends State { .withOpacity(0.8), borderRadius: BorderRadius.all(Radius.circular(14.r))), - // 这里设置不一样是因为 返回图标的中心靠右 往左稍微拉一点 padding: EdgeInsets.fromLTRB(12.w, 10.w, 14.w, 10.w), child: Icon( Icons.arrow_back_ios_new, @@ -137,18 +163,27 @@ class _ImageViewPageState extends State { child: Row( mainAxisSize: MainAxisSize.min, children: [ - WButton( - child: Icon( - Icons.qr_code_scanner_outlined, - color: WpyTheme.of(context) - .get(WpyColorKey.primaryBackgroundColor), - size: 30.h, - ), - onPressed: () { - recognizeQRCode(); - }, + ScaleTransition( + scale: _scaleAnimation, + child: hasQRCode + ? Row( + children: [ + WButton( + child: Icon( + Icons.qr_code_scanner_outlined, + color: WpyTheme.of(context).get( + WpyColorKey.primaryBackgroundColor), + size: 30.h, + ), + onPressed: () { + recognizeQRCode(); + }, + ), + SizedBox(width: 30.w), + ], + ) + : SizedBox.shrink(), ), - SizedBox(width: 30.w), WButton( child: Icon( Icons.file_download_outlined, @@ -181,6 +216,31 @@ class _ImageViewPageState extends State { ); } + void _checkQRCode() async { + try { + final imageUrl = baseUrl + widget.args.urlList[indexNow]; + final imagePath = await StorageUtil.saveTempFileFromNetwork(imageUrl, + filename: widget.args.urlList[indexNow]); + String? qrResult = await QrCodeToolsPlugin.decodeFrom(imagePath); + if (qrResult != null && qrResult.isNotEmpty) { + setState(() { + hasQRCode = true; + }); + _animationController.forward(); + } else { + setState(() { + hasQRCode = false; + }); + _animationController.reverse(); + } + } catch (e) { + setState(() { + hasQRCode = false; + }); + _animationController.reverse(); + } + } + void saveImage() async { ToastProvider.running('保存中'); await GallerySaver.saveImage(baseUrl + widget.args.urlList[indexNow],