8 changed files with 211 additions and 6 deletions
Unified View
Diff Options
-
BINassets/images/star_sky_bg.png
-
BINassets/images/test1.png
-
BINassets/images/test2.png
-
9lib/components/sphere_cloud.dart
-
45lib/controller/home/real_home_controller.dart
-
3lib/generated/assets.dart
-
155lib/pages/home/real_home_page.dart
-
5lib/pages/main/main_page.dart
@ -0,0 +1,45 @@ |
|||||
|
import 'package:dating_touchme_app/model/home/marriage_data.dart'; |
||||
|
import 'package:dating_touchme_app/network/home_api.dart'; |
||||
|
import 'package:flutter/material.dart'; |
||||
|
import 'package:get/get.dart'; |
||||
|
|
||||
|
class RealHomeController extends GetxController { |
||||
|
|
||||
|
late final HomeApi _homeApi; |
||||
|
// 推荐列表数据 |
||||
|
final recommendFeed = <MarriageData>[].obs; |
||||
|
|
||||
|
@override |
||||
|
void onInit() { |
||||
|
super.onInit(); |
||||
|
// 从全局依赖中获取HomeApi |
||||
|
_homeApi = Get.find<HomeApi>(); |
||||
|
getListData(); |
||||
|
} |
||||
|
|
||||
|
getListData() async { |
||||
|
try { |
||||
|
var response = await _homeApi.getMarriageList( |
||||
|
pageNum: 1, |
||||
|
pageSize: 100, |
||||
|
type: 0, |
||||
|
); |
||||
|
if (response.data.isSuccess) { |
||||
|
final allRecords = response.data.data!.records |
||||
|
.map((item) => MarriageData.fromJson(item as Map<String, dynamic>)) |
||||
|
.toList(); |
||||
|
|
||||
|
// 过滤掉直播类型的项 |
||||
|
final records = allRecords!.where((item) => !item.isLive).toList(); |
||||
|
recommendFeed.addAll(records); |
||||
|
update(); |
||||
|
} else { |
||||
|
// 响应失败,抛出异常 |
||||
|
throw Exception(response.data.message); |
||||
|
} |
||||
|
} catch(e) { |
||||
|
// 向上抛出异常,让调用方处理 |
||||
|
rethrow; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,155 @@ |
|||||
|
import 'package:dating_touchme_app/components/page_appbar.dart'; |
||||
|
import 'package:dating_touchme_app/components/sphere_cloud.dart'; |
||||
|
import 'package:dating_touchme_app/controller/home/real_home_controller.dart'; |
||||
|
import 'package:dating_touchme_app/generated/assets.dart'; |
||||
|
import 'package:flutter/material.dart'; |
||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
||||
|
import 'package:get/get.dart'; |
||||
|
|
||||
|
class RealHomePage extends StatefulWidget { |
||||
|
const RealHomePage({super.key}); |
||||
|
|
||||
|
@override |
||||
|
State<RealHomePage> createState() => _RealHomePageState(); |
||||
|
} |
||||
|
|
||||
|
class _RealHomePageState extends State<RealHomePage> with AutomaticKeepAliveClientMixin { |
||||
|
|
||||
|
@override |
||||
|
Widget build(BuildContext context) { |
||||
|
super.build(context); |
||||
|
return GetBuilder<RealHomeController>( |
||||
|
init: RealHomeController(), |
||||
|
builder: (controller){ |
||||
|
return Stack( |
||||
|
children: [ |
||||
|
Image.asset( |
||||
|
Assets.imagesStarSkyBg, |
||||
|
width: 375.w, |
||||
|
fit: BoxFit.cover, |
||||
|
alignment: AlignmentGeometry.topCenter, |
||||
|
), |
||||
|
Scaffold( |
||||
|
backgroundColor: Colors.transparent, |
||||
|
appBar: PageAppbar(title: "快乐星球", color: Colors.white, backgroundColor: Colors.transparent,), |
||||
|
body: Container( |
||||
|
width: 375.w, |
||||
|
padding: EdgeInsets.symmetric(horizontal: 15.w), |
||||
|
child: SingleChildScrollView( |
||||
|
child: Column( |
||||
|
children: [ |
||||
|
SizedBox( |
||||
|
width: 345.w, |
||||
|
height: 345.w, |
||||
|
child: SphereCloud( |
||||
|
itemSize: 36.w, |
||||
|
items: [ |
||||
|
...controller.recommendFeed.map((e){ |
||||
|
return SizedBox( |
||||
|
width: 36.w, |
||||
|
child: Column( |
||||
|
children: [ |
||||
|
Text( |
||||
|
e.nickName, |
||||
|
maxLines: 1, |
||||
|
overflow: TextOverflow.ellipsis, |
||||
|
style: TextStyle( |
||||
|
fontSize: 12.w, |
||||
|
color: Colors.white, |
||||
|
fontWeight: FontWeight.w400 |
||||
|
), |
||||
|
), |
||||
|
Image.network( |
||||
|
e.profilePhoto, |
||||
|
width: 18.w, |
||||
|
height: 18.w, |
||||
|
fit: BoxFit.cover, |
||||
|
) |
||||
|
], |
||||
|
), |
||||
|
); |
||||
|
}), |
||||
|
] |
||||
|
), |
||||
|
), |
||||
|
Container( |
||||
|
width: 92.w, |
||||
|
height: 21.w, |
||||
|
margin: EdgeInsets.symmetric(vertical: 20.w), |
||||
|
decoration: BoxDecoration( |
||||
|
borderRadius: BorderRadius.all(Radius.circular(21.w)), |
||||
|
color: const Color.fromRGBO(255, 255, 255, .1) |
||||
|
), |
||||
|
child: Row( |
||||
|
mainAxisAlignment: MainAxisAlignment.center, |
||||
|
children: [ |
||||
|
Icon( |
||||
|
Icons.autorenew, |
||||
|
size: 18.w, |
||||
|
color: Colors.white, |
||||
|
), |
||||
|
SizedBox(width: 4.w,), |
||||
|
Text( |
||||
|
"换一批", |
||||
|
style: TextStyle( |
||||
|
fontSize: 12.w, |
||||
|
color: Colors.white |
||||
|
), |
||||
|
) |
||||
|
], |
||||
|
), |
||||
|
), |
||||
|
Row( |
||||
|
children: [ |
||||
|
Text( |
||||
|
"趣味测试", |
||||
|
style: TextStyle( |
||||
|
fontSize: 16.w, |
||||
|
color: Colors.white |
||||
|
), |
||||
|
) |
||||
|
], |
||||
|
), |
||||
|
SizedBox(height: 7.w,), |
||||
|
Row( |
||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
||||
|
children: [ |
||||
|
Image.asset( |
||||
|
Assets.imagesTest1, |
||||
|
width: 170.w, |
||||
|
), |
||||
|
Image.asset( |
||||
|
Assets.imagesTest2, |
||||
|
width: 170.w, |
||||
|
), |
||||
|
], |
||||
|
), |
||||
|
SizedBox(height: 15.w,), |
||||
|
Row( |
||||
|
children: [ |
||||
|
Text( |
||||
|
"热门帖子", |
||||
|
style: TextStyle( |
||||
|
fontSize: 16.w, |
||||
|
color: Colors.white |
||||
|
), |
||||
|
) |
||||
|
], |
||||
|
), |
||||
|
SizedBox(height: 7.w,), |
||||
|
], |
||||
|
), |
||||
|
), |
||||
|
), |
||||
|
) |
||||
|
], |
||||
|
); |
||||
|
}, |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
@override |
||||
|
bool get wantKeepAlive => true; |
||||
|
} |
||||
|
|
||||
Write
Preview
Loading…
Cancel
Save