s
This commit is contained in:
parent
6d393401c0
commit
d49d39165f
@ -1,11 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:wallpaper/utils/downloadmanager.dart';
|
||||
|
||||
|
||||
// import 'TestApp.dart';
|
||||
import 'WallPaperApp.dart';
|
||||
Future<void> main() async {
|
||||
await DownloadManager.downloadImgWithUrl("https://resource-sg-public.lux-ad.com/wallpaper/4f1e7f66f26003b0ea83f4934302ce84.jpg");
|
||||
void main() {
|
||||
runApp(const WallPaperApp());
|
||||
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:wallpaper/routes/app_routes.dart';
|
||||
import "package:wallpaper/utils/assettool.dart";
|
||||
import 'package:wallpaper/models/imgnetodel.dart';
|
||||
class HomePageController extends GetxController {
|
||||
@ -9,10 +10,15 @@ class HomePageController extends GetxController {
|
||||
super.onReady();
|
||||
|
||||
setupTypeListData();
|
||||
|
||||
}
|
||||
|
||||
void setupTypeListData() async{
|
||||
var temData = await loadWallpaperJsonFromAsset();
|
||||
typeList.value = temData.map((e) => NetImgCategory.fromJson(e)).toList();
|
||||
}
|
||||
|
||||
void goCategoryView(var title,var dataModel){
|
||||
Get.toNamed(AppRoutes.imgcategorypage, arguments: {"stitle":title,"dataModel":dataModel});
|
||||
}
|
||||
}
|
||||
@ -62,7 +62,8 @@ class HomePageView extends GetView <HomePageController> {
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Get.to(ImgCategoryPageView(stitle: title,dataModel: controller.typeList[index]));
|
||||
// Get.to(ImgCategoryPageView(stitle: title,dataModel: controller.typeList[index]));
|
||||
controller.goCategoryView(title, controller.typeList[index]);
|
||||
},
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
|
||||
@ -1,5 +1,22 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:wallpaper/models/imgnetodel.dart';
|
||||
import 'package:wallpaper/utils/downloadmanager.dart';
|
||||
|
||||
class ImgCategoryPageController extends GetxController {
|
||||
|
||||
var stitle = RxString("");
|
||||
// ignore: prefer_typing_uninitialized_variables
|
||||
late NetImgCategory dataModel;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
stitle.value = Get.arguments["stitle"];
|
||||
dataModel = Get.arguments["dataModel"];
|
||||
}
|
||||
|
||||
Future < void> downloadImg(String urlStr) async {
|
||||
await DownloadManager.downloadImgWithUrl(urlStr);
|
||||
//提示框
|
||||
//....已下载
|
||||
}
|
||||
}
|
||||
@ -1,25 +1,27 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:wallpaper/pages/imgcategorypage/imgcategorypage_controller.dart';
|
||||
import 'package:wallpaper/models/imgnetodel.dart';
|
||||
// import 'package:wallpaper/models/imgnetodel.dart';
|
||||
import 'package:transparent_image/transparent_image.dart';
|
||||
import 'package:wallpaper/pages/imgscanpage/imgscanpage_view.dart';
|
||||
|
||||
class ImgCategoryPageView extends GetView {
|
||||
class ImgCategoryPageView extends GetView<ImgCategoryPageController> {
|
||||
const ImgCategoryPageView({super.key});
|
||||
|
||||
// const ImgCategoryPageView({super.key});
|
||||
final String stitle;
|
||||
final NetImgCategory dataModel;
|
||||
const ImgCategoryPageView({super.key, required this.stitle,required this.dataModel});
|
||||
// final String stitle;
|
||||
// final NetImgCategory dataModel;
|
||||
// const ImgCategoryPageView({super.key, required this.stitle,required this.dataModel});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Widget bodyView = getBodyWidget();
|
||||
Widget build(BuildContext context) {
|
||||
final Widget bodyView = getBodyWidget();
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(stitle),
|
||||
title: Obx(() => Text(controller.stitle.value)) ,
|
||||
),
|
||||
body: bodyView,
|
||||
body: bodyView ,
|
||||
);
|
||||
}
|
||||
|
||||
@ -29,20 +31,29 @@ class ImgCategoryPageView extends GetView {
|
||||
|
||||
|
||||
//返回内容
|
||||
Widget getBodyWidget(){
|
||||
return GridView.count(
|
||||
crossAxisCount: 2,
|
||||
mainAxisSpacing: 2,
|
||||
crossAxisSpacing: 2,
|
||||
childAspectRatio: 0.7,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 5),
|
||||
children: List.generate(dataModel.data!.length, (index) {
|
||||
return getBodyItem(dataModel.data![index].previewThumb!, index);
|
||||
}),
|
||||
);
|
||||
Widget getBodyWidget() {
|
||||
return GridView.count(
|
||||
crossAxisCount: 2,
|
||||
mainAxisSpacing: 2,
|
||||
crossAxisSpacing: 2,
|
||||
childAspectRatio: 0.7,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 5),
|
||||
children: List.generate(controller.dataModel.data!.length, (index) {
|
||||
return getBodyItem(controller.dataModel.data![index].previewThumb!, index);
|
||||
}));
|
||||
// return Obx(() => GridView.count(
|
||||
// crossAxisCount: 2,
|
||||
// mainAxisSpacing: 2,
|
||||
// crossAxisSpacing: 2,
|
||||
// childAspectRatio: 0.7,
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 5),
|
||||
// children: List.generate(controller.dataModel.data!.length, (index) {
|
||||
// return getBodyItem(controller.dataModel.data![index].previewThumb!, index);
|
||||
// }),
|
||||
// ));
|
||||
}
|
||||
|
||||
Stack getBodyItem(String imgUrl,int index){
|
||||
Stack getBodyItem(String imgUrl,int index) {
|
||||
return Stack(//堆叠效果
|
||||
children: [
|
||||
FadeInImage.memoryNetwork(
|
||||
@ -57,7 +68,7 @@ class ImgCategoryPageView extends GetView {
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Get.to(ImgScanPageView(dataModel: dataModel,currentIndex: index,));
|
||||
Get.to(ImgScanPageView(dataModel: controller.dataModel,currentIndex: index,));
|
||||
},
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
@ -71,10 +82,13 @@ class ImgCategoryPageView extends GetView {
|
||||
// 交叉轴的布局方式,对于column来说就是水平方向的布局方式
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
IconButton(onPressed:() {
|
||||
IconButton(onPressed:() {
|
||||
print("download....");
|
||||
|
||||
controller.downloadImg(imgUrl);
|
||||
|
||||
}, icon: Icon(Icons.download),color: Colors.white,),
|
||||
|
||||
IconButton(onPressed:() {
|
||||
print("设置壁纸");
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import 'package:wallpaper/pages/homepage/homepage_binding.dart';
|
||||
import 'package:wallpaper/pages/imgcategorypage/imgcategorypage_binding.dart';
|
||||
import 'package:wallpaper/pages/imgcategorypage/imgcategorypage_view.dart';
|
||||
import 'package:wallpaper/pages/imgscanpage/imgscanpage_binding.dart';
|
||||
|
||||
import 'package:wallpaper/pages/tabarpage/tabarpage_binding.dart';
|
||||
@ -17,14 +18,18 @@ import 'package:get/get.dart';
|
||||
class AppRoutes {
|
||||
AppRoutes._();
|
||||
static const initialPage = '/tabvc';
|
||||
|
||||
static const imgcategorypage = "/ImgCategoryPage";
|
||||
static final routes= [
|
||||
GetPage(
|
||||
name: initialPage,
|
||||
page: ()=> const TabbarPageView(),
|
||||
bindings: [TabbarPageBinding(), HomePageBinding(),DownloadPageBinding(),MyPageBinding(),ImgCategoryPageBinding(),ImgScanPageBinding()],
|
||||
participatesInRootNavigator: true,
|
||||
bindings: [TabbarPageBinding(), HomePageBinding(),DownloadPageBinding(),MyPageBinding(),ImgScanPageBinding()],
|
||||
),
|
||||
GetPage(
|
||||
name: imgcategorypage,
|
||||
page: ()=> const ImgCategoryPageView(),
|
||||
bindings: [ImgCategoryPageBinding()],
|
||||
),
|
||||
];
|
||||
|
||||
}
|
||||
@ -1,16 +1,21 @@
|
||||
|
||||
import 'dart:io';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:wallpaper/utils/local_img_manager.dart';
|
||||
|
||||
class DownloadManager {
|
||||
static Future<void> downloadImgWithUrl(String urlStr) async {
|
||||
var httpClient = HttpClient();
|
||||
try {
|
||||
// option: Options(responseType: ResponseType.bytes)
|
||||
var reqiest = await httpClient.getUrl(Uri.parse(urlStr));
|
||||
var response = await reqiest.close();
|
||||
// var bytes = await consolidateHttpClientResponseBytes(response);
|
||||
var bytes = await consolidateHttpClientResponseBytes(response);
|
||||
print("the bytes:${bytes}");
|
||||
var fileName = await LocalImgManager.saveImgDataBytes(bytes);
|
||||
// print(fileName);
|
||||
//写入数据库信息
|
||||
//.....
|
||||
}
|
||||
catch(error) {
|
||||
print("the error:${error}");
|
||||
|
||||
@ -19,13 +19,13 @@ class LocalImgManager {
|
||||
String fileName = "img_${LocalImgManager.sha1RandomString()}.jpg";
|
||||
var localDir = await getImgLocalDir();
|
||||
var filePath = '$localDir/$fileName';
|
||||
|
||||
// print("the filepath:$filePath ");
|
||||
File imageFile=File(filePath);
|
||||
if(imageFile.existsSync()){
|
||||
print("图片已存在");
|
||||
return "";
|
||||
}
|
||||
imageFile.writeAsBytes(data);
|
||||
await imageFile.writeAsBytes(data);
|
||||
return fileName;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user