WallPaper_ZZH_Flutter/wallpaper/lib/pages/downloadpage/downloadpage_view.dart
bluesea badd6b9f13 s
2024-05-15 16:03:20 +08:00

102 lines
3.7 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:transparent_image/transparent_image.dart';
import 'package:wallpaper/pages/downloadpage/downloadpage_controller.dart';
class DownloadPageView extends GetView<DownloadPageController> {
// const DownloadPageView({super.key});
@override
Widget build(BuildContext context) {
final Widget bodyView = getBodyWidget();
return Scaffold(
appBar: AppBar(
title: const Text("下载"),
),
body: bodyView,
);
}
//返回内容
Widget getBodyWidget(){
return Obx(() => GridView.count(
crossAxisCount: 2,
mainAxisSpacing: 2,
crossAxisSpacing: 2,
childAspectRatio: 0.7,
padding: const EdgeInsets.symmetric(horizontal: 5),
// padding: const EdgeInsets.fromLTRB(5, 50, 5, 0),
children: List.generate(controller.dataItems.length, (index) {
return getBodyItem(controller.dataItems[index].localUrl!);
}),
));
}
Stack getBodyItem(String fileName) {
var imgUrl = controller.localDir.value +'/'+ fileName;
return Stack(//堆叠效果
children: [
Image.file(
File(imgUrl),
width: double.infinity,
height: double.infinity,
fit: BoxFit.cover,
),
// Image.file(imgUrl),
// FadeInImage.loadImageByFile(
// width: double.infinity,
// height: double.infinity,
// placeholder: kTransparentImage,
// image: imgUrl,
// fit: BoxFit.cover,
// ),
Material(
color: Colors.transparent,
child: InkWell(
onTap: () {
//前往看大图
//.....
},
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
color: Colors.black.withAlpha(160),
height: 40,
width: double.infinity,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
// 交叉轴的布局方式对于column来说就是水平方向的布局方式
crossAxisAlignment: CrossAxisAlignment.center,
children: getButtomWidge(imgUrl),
),
),
),
),
),
],
);
}
List<Widget> getButtomWidge(String imgUrl){
List<Widget> wg = [
IconButton(onPressed:() {
controller.saveImgToAlbum(imgUrl);
}, icon: const Icon(Icons.album),color: Colors.white,),
];
if (controller.isAndroid) {
wg.add(IconButton(onPressed:() {
controller.setWallpaper(imgUrl);
}, icon: const Icon(Icons.wallpaper),color: Colors.white,));
}
return wg;
}
}