This commit is contained in:
bluesea 2024-05-15 09:55:14 +08:00
parent 33537c10fd
commit 39ea0327ba
2 changed files with 41 additions and 12 deletions

View File

@ -2,10 +2,13 @@ import 'package:get/get.dart';
import 'package:get/get_rx/get_rx.dart'; import 'package:get/get_rx/get_rx.dart';
import 'package:wallpaper/models/imgnetodel.dart'; import 'package:wallpaper/models/imgnetodel.dart';
import 'package:wallpaper/utils/downloadmanager.dart'; import 'package:wallpaper/utils/downloadmanager.dart';
import 'dart:async';
class ImgScanPageController extends GetxController { class ImgScanPageController extends GetxController {
late NetImgCategory dataModel; late NetImgCategory dataModel;
RxInt currentIndex = RxInt(0); RxInt currentIndex = RxInt(0);
RxInt showAppbar = RxInt(0);//appbar显示....
Timer? _timer;
@override @override
void onInit(){ void onInit(){
@ -14,10 +17,36 @@ class ImgScanPageController extends GetxController {
dataModel = Get.arguments["dataModel"]; dataModel = Get.arguments["dataModel"];
} }
@override
void onClose() {
cancelTimer();
super.onClose();
}
void cancelTimer() {
if (_timer != null) {
_timer!.cancel();
_timer = null;
}
}
Future < void> downloadImg() async { Future < void> downloadImg() async {
String urlStr = dataModel.data![currentIndex.value].original!; String urlStr = dataModel.data![currentIndex.value].original!;
await DownloadManager.downloadImgWithUrl(urlStr); await DownloadManager.downloadImgWithUrl(urlStr);
// //
//.... //....
} }
void showAppbarAction(){
showAppbar.value = 1;
cancelTimer();
const oneSec = Duration(seconds: 3);
_timer = Timer.periodic(oneSec, (Timer timer) {
timer.cancel();
_timer = null;
showAppbar.value = 0;
});
}
} }

View File

@ -20,13 +20,13 @@ class ImgScanPageView extends GetView<ImgScanPageController> {
backgroundColor: Colors.black, backgroundColor: Colors.black,
appBar:PreferredSize( appBar:PreferredSize(
preferredSize: const Size.fromHeight(44), preferredSize: const Size.fromHeight(44),
child: AppBar( child: Obx(() => controller.showAppbar.value == 0 ? Text("") :AppBar(
centerTitle: true, centerTitle: true,
title: const Text("查看大图"), title: const Text("查看大图"),
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
foregroundColor: Colors.white, foregroundColor: Colors.white,
), )),
), ),
body: Stack( body: Stack(
children: [ children: [
@ -39,7 +39,7 @@ class ImgScanPageView extends GetView<ImgScanPageController> {
minScale: PhotoViewComputedScale.contained*0.4, minScale: PhotoViewComputedScale.contained*0.4,
maxScale: PhotoViewComputedScale.contained * 4, maxScale: PhotoViewComputedScale.contained * 4,
onTapDown: (context, details, controllerValue) { onTapDown: (context, details, controllerValue) {
print("touch down..."); controller.showAppbarAction();
}, },
// heroAttributes: PhotoViewHeroAttributes(tag: galleryItems[index].id), // heroAttributes: PhotoViewHeroAttributes(tag: galleryItems[index].id),
); );