diff --git a/assets/images/star_sky_bg.png b/assets/images/star_sky_bg.png new file mode 100644 index 0000000..7991346 Binary files /dev/null and b/assets/images/star_sky_bg.png differ diff --git a/assets/images/test1.png b/assets/images/test1.png new file mode 100644 index 0000000..c926830 Binary files /dev/null and b/assets/images/test1.png differ diff --git a/assets/images/test2.png b/assets/images/test2.png new file mode 100644 index 0000000..23dd5c4 Binary files /dev/null and b/assets/images/test2.png differ diff --git a/lib/components/sphere_cloud.dart b/lib/components/sphere_cloud.dart index e50bbd8..4569991 100644 --- a/lib/components/sphere_cloud.dart +++ b/lib/components/sphere_cloud.dart @@ -1,14 +1,15 @@ import 'dart:math' as math; import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; class SphereCloud extends StatefulWidget { - const SphereCloud({ + SphereCloud({ super.key, required this.items, this.radius = 140, - this.itemSize = 48, - this.cameraZ = 400, // 相机离球心距离,越大透视越弱 - this.focal = 240, // 焦距,影响投影与缩放 + required this.itemSize, + this.cameraZ = 360, // 相机离球心距离,越大透视越弱 + this.focal = 320, // 焦距,影响投影与缩放 this.minScale = 0.45, this.maxScale = 1.25, }); diff --git a/lib/controller/home/real_home_controller.dart b/lib/controller/home/real_home_controller.dart new file mode 100644 index 0000000..5bea0b8 --- /dev/null +++ b/lib/controller/home/real_home_controller.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 = [].obs; + + @override + void onInit() { + super.onInit(); + // 从全局依赖中获取HomeApi + _homeApi = Get.find(); + 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)) + .toList(); + + // 过滤掉直播类型的项 + final records = allRecords!.where((item) => !item.isLive).toList(); + recommendFeed.addAll(records); + update(); + } else { + // 响应失败,抛出异常 + throw Exception(response.data.message); + } + } catch(e) { + // 向上抛出异常,让调用方处理 + rethrow; + } + } +} \ No newline at end of file diff --git a/lib/generated/assets.dart b/lib/generated/assets.dart index 7aff101..b8b68cc 100644 --- a/lib/generated/assets.dart +++ b/lib/generated/assets.dart @@ -198,12 +198,15 @@ class Assets { static const String imagesSplash = 'assets/images/splash.png'; static const String imagesSquareNol = 'assets/images/square_nol.png'; static const String imagesSquarePre = 'assets/images/square_pre.png'; + static const String imagesStarSkyBg = 'assets/images/star_sky_bg.png'; static const String imagesSubscript = 'assets/images/subscript.png'; static const String imagesSuccessIcon = 'assets/images/success_icon.png'; static const String imagesTabChangeIcon = 'assets/images/tab_change_icon.png'; static const String imagesTalkIcon = 'assets/images/talk_icon.png'; static const String imagesTeenagerBg = 'assets/images/teenager_bg.png'; static const String imagesTeenagerList = 'assets/images/teenager_list.png'; + static const String imagesTest1 = 'assets/images/test1.png'; + static const String imagesTest2 = 'assets/images/test2.png'; static const String imagesUnreadIcon = 'assets/images/unread_icon.png'; static const String imagesUpdataBg = 'assets/images/updata_bg.png'; static const String imagesUpdataFont = 'assets/images/updata_font.png'; diff --git a/lib/pages/home/real_home_page.dart b/lib/pages/home/real_home_page.dart new file mode 100644 index 0000000..5e249b8 --- /dev/null +++ b/lib/pages/home/real_home_page.dart @@ -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 createState() => _RealHomePageState(); +} + +class _RealHomePageState extends State with AutomaticKeepAliveClientMixin { + + @override + Widget build(BuildContext context) { + super.build(context); + return GetBuilder( + 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; +} + diff --git a/lib/pages/main/main_page.dart b/lib/pages/main/main_page.dart index fb87a7d..211a52b 100644 --- a/lib/pages/main/main_page.dart +++ b/lib/pages/main/main_page.dart @@ -1,5 +1,6 @@ import 'package:dating_touchme_app/extension/ex_widget.dart'; import 'package:dating_touchme_app/generated/assets.dart'; +import 'package:dating_touchme_app/pages/home/real_home_page.dart'; import 'package:dating_touchme_app/pages/home/send_timeline.dart'; import 'package:dating_touchme_app/pages/home/timeline_page.dart'; import 'package:dating_touchme_app/pages/home/timeline_window.dart'; @@ -34,7 +35,7 @@ class _MainPageState extends State { int currentIndex = 0; // 使用普通int替代RxInt // 将页面实例存储为成员变量,避免每次build都重新创建 - late HomePage homePage; + late RealHomePage homePage; late DiscoverPage discoverPage; late TimelinePage timelinePage; late MessagePage messagePage; @@ -45,7 +46,7 @@ class _MainPageState extends State { super.initState(); // 初始化页面实例 - homePage = HomePage(); + homePage = RealHomePage(); // discoverPage = DiscoverPage(); timelinePage = TimelinePage(); messagePage = MessagePage();