This commit is contained in:
bluesea 2024-05-13 09:36:57 +08:00
parent 3983d553a9
commit 4a8288c907
10 changed files with 78 additions and 70 deletions

View File

@ -5,7 +5,7 @@ import 'collectionpage_controller.dart';
class CollectionPageBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut(() => CollectionPageController());
Get.put(CollectionPageController());
}
}

View File

@ -5,7 +5,7 @@ import 'downloadpage_controller.dart';
class DownloadPageBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut(() => DownloadPageController());
Get.put( DownloadPageController());
}
}

View File

@ -5,7 +5,8 @@ import 'homepage_controller.dart';
class HomePageBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut(() => HomePageController());
// Get.lazyPut(() => HomePageController());
Get.put(HomePageController());
}
}

View File

@ -1,5 +1,25 @@
import 'package:get/get.dart';
import "package:wallpaper/utils/assettool.dart";
class HomePageController extends GetxController {
var typeList = [].obs;
@override
void onReady() async{
super.onReady();
setupTypeListData();
}
void setupTypeListData() async{
var temData = await loadWallpaperJsonFromAsset();
temData.forEach((element) { })
}
@override
void onInit() async {
super.onInit();
}
}

View File

@ -4,48 +4,50 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:transparent_image/transparent_image.dart';
import 'package:wallpaper/pages/homepage/homepage_controller.dart';
class HomePageView extends GetView {
class HomePageView extends GetView <HomePageController> {
const HomePageView({super.key});
@override
Widget build(BuildContext context) {
// Get.put(HomePageController);
const title = "壁纸";
final SizedBox headerView = getHeaderWidget(context);
final GridView bodyView = getBodyWidget();
return MaterialApp(
title: title,
home: Scaffold(
appBar: AppBar(
title: const Text(title),
),
body: Row(
children: [
headerView,
// bodyView,
],
),
),
// final SizedBox headerView = getHeaderWidget(context);
final Widget bodyView = getBodyWidget();
// Obx(() => {
// print(controller.typeList);
// return Text("data");}
// );
print("build......hompage");
return Scaffold(
appBar: AppBar(
title: const Text(title),
),
// body: Row(
// children: [
// headerView,
// // bodyView,
// ],
body:bodyView,
);
}
//
GridView getBodyWidget(){
return GridView.count(
// Create a grid with 2 columns. If you change the scrollDirection to
// horizontal, this produces 2 rows.
Widget getBodyWidget(){
return Obx(() => GridView.count(
crossAxisCount: 2,
// Generate 100 widgets that display their index in the List.
children: List.generate(100, (index) {
children: List.generate(controller.typeList.length, (index) {
return Center(
child: FadeInImage.memoryNetwork(
placeholder: kTransparentImage,
image: 'https://picsum.photos/250?image=9',
image: controller.typeList[index]["data"][0]["previewThumb"],
),
);
}),
);
));
}
//
@ -75,14 +77,31 @@ class HomePageView extends GetView {
width: cw,
color: Colors.yellow,
),
Container(
width: cw,
color: Colors.orange,
),
getCustomContrainer("cuainer"),
],
),
);
}
//customcontainer
Container getCustomContrainer(String title) {
return Container(
alignment: Alignment.center,
// decoration: BoxDecoration( //
// border: Border.all(color: Colors.black12, width: 0.5),
// borderRadius: BorderRadius.all(Radius.circular(5.0))),
color:Colors.red,
padding: EdgeInsets.all(5.0),
// margin: EdgeInsets.fromLTRB(3.0, 0.0, 3.0, 0.0),
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: 100.0,),
child: Text(
title,
softWrap: true,
),
));
}
}

View File

@ -5,7 +5,7 @@ import 'mypage_controller.dart';
class MyPageBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut(() => MyPageController());
Get.put(() => MyPageController());
}
}

View File

@ -7,9 +7,7 @@ class MyPageView extends GetView {
@override
Widget build(BuildContext context) {
const title = '我的';
return MaterialApp(
title: title,
home: Scaffold(
return Scaffold(
appBar: AppBar(
title: const Text(title),
),
@ -29,7 +27,7 @@ class MyPageView extends GetView {
),
],
),
),
);
);
}
}

View File

@ -1,9 +1,7 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter/widgets.dart';
import 'package:wallpaper/pages/homePage/homePage_view.dart';
import 'package:wallpaper/pages/downloadpage/downloadpage_view.dart';
import 'package:wallpaper/pages/collectionpage/collectionpage_view.dart';
import 'package:wallpaper/pages/mypage/mypage_view.dart';
@ -41,10 +39,6 @@ class TabbarPageView extends GetView <TabbarPageController>{
icon: Icon(Icons.collections),
label: "收藏"
),
// const BottomNavigationBarItem(
// icon: Icon(Icons.download),
// label: "下载"
// ),
const BottomNavigationBarItem(
icon: Icon(Icons.person),
label: "我的"

View File

@ -24,31 +24,7 @@ class AppRoutes {
GetPage(
name: initialPage,
page: ()=> const TabbarPageView(),
binding: TabbarPageBinding(),
participatesInRootNavigator: true,
),
GetPage(
name: '/home',
page: ()=> const HomePageView(),
binding: HomePageBinding(),
participatesInRootNavigator: true,
),
GetPage(
name: '/downlaod',
page: ()=> const DownloadPageView(),
binding: DownloadPageBinding(),
participatesInRootNavigator: true,
),
GetPage(
name: '/collection',
page: ()=> const CollectionPageView(),
binding: CollectionPageBinding(),
participatesInRootNavigator: true,
),
GetPage(
name: '/my',
page: ()=> const MyPageView(),
binding: MyPageBinding(),
bindings: [TabbarPageBinding(), HomePageBinding(),DownloadPageBinding(),MyPageBinding()],
participatesInRootNavigator: true,
),
];

View File

@ -1,6 +1,6 @@
import 'package:flutter/services.dart' show rootBundle;
import 'dart:convert';
Future<Map<String, dynamic>> loadWallpaperJsonFromAsset() async {
Future<List> loadWallpaperJsonFromAsset() async {
String jsonStr = await rootBundle.loadString('assets/wallpaper.json');
return jsonDecode(jsonStr);
}