2026-07-01 18:25:58 +08:00

775 lines
35 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:aslan/app_localizations.dart';
import 'package:aslan/chatvibe_ui/components/at_debounce_widget.dart';
import 'package:aslan/chatvibe_ui/components/at_compontent.dart';
import 'package:aslan/chatvibe_ui/components/text/at_text.dart';
import 'package:aslan/chatvibe_core/utilities/at_banner_utils.dart';
import 'package:marquee/marquee.dart';
import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:aslan/chatvibe_data/sources/repositories/room_repository_imp.dart';
import 'package:aslan/chatvibe_domain/models/res/at_index_banner_res.dart';
import 'package:aslan/chatvibe_domain/models/res/room_res.dart';
import 'package:aslan/chatvibe_managers/app_general_manager.dart';
import 'package:aslan/chatvibe_managers/rtc_manager.dart';
import 'package:aslan/chatvibe_ui/widgets/room/explore_banner_view.dart';
import 'package:aslan/chatvibe_core/constants/at_global_config.dart';
import 'package:aslan/chatvibe_core/config/business_logic_strategy.dart';
import 'package:aslan/chatvibe_ui/widgets/country/at_country_flag_image.dart';
class ExplorePage2 extends StatefulWidget {
@override
_ExplorePage2State createState() => _ExplorePage2State();
}
class _ExplorePage2State extends State<ExplorePage2>
with SingleTickerProviderStateMixin {
bool _isDrawerOpen = false;
final RefreshController _refreshController = RefreshController(
initialRefresh: false,
);
List<ChatVibeRoomRes> rooms = [];
List<ChatVibeRoomRes> drawerRooms = [];
bool isLoading = false;
bool isGrid = true;
// 获取业务逻辑策略
BusinessLogicStrategy get _strategy => ATGlobalConfig.businessLogicStrategy;
@override
void initState() {
super.initState();
loadData();
}
@override
void dispose() {
super.dispose();
}
loadData() {
setState(() {
isLoading = true;
});
ChatRoomRepository()
.discovery(allRegion: true)
.then((values) {
rooms = values;
drawerRooms.clear();
// 使用策略获取房间显示阈值
final threshold = _strategy.getExploreRoomDisplayThreshold();
if (rooms.length > threshold) {
drawerRooms.addAll(rooms.sublist(threshold, rooms.length));
}
isLoading = false;
_refreshController.refreshCompleted();
_refreshController.loadComplete();
if (mounted) setState(() {});
})
.catchError((e) {
_refreshController.loadNoData();
_refreshController.refreshCompleted();
isLoading = false;
if (mounted) setState(() {});
});
Provider.of<AppGeneralManager>(context, listen: false).loadMainBanner();
}
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: Colors.transparent,
body: Stack(
alignment: AlignmentDirectional.bottomCenter,
children: [
SmartRefresher(
enablePullDown: true,
enablePullUp: false,
controller: _refreshController,
onRefresh: () {
loadData();
},
onLoading: () {},
child:
rooms.isEmpty
? GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
loadData();
},
child:
isLoading
? Center(child: CupertinoActivityIndicator())
: mainEmpty(
msg: ATAppLocalizations.of(context)!.noData,
),
)
: SingleChildScrollView(
child: Column(
children: [
Row(
children: [
SizedBox(width: 10.w),
text(
ATAppLocalizations.of(context)!.hotRooms,
fontSize: 14.sp,
textColor: Colors.black,
fontWeight: FontWeight.w600,
),
Spacer(),
ATDebounceWidget(
child: Image.asset(
isGrid
? _strategy.getExploreGridIcon()
: _strategy.getExploreListIcon(),
height: 25.w,
),
onTap: () {
setState(() {
isGrid = !isGrid;
});
},
),
SizedBox(width: 10.w),
],
),
SizedBox(height: 10.w),
isGrid
? Row(
children: [
SizedBox(width: 10.w),
Expanded(
child:
rooms.isNotEmpty
? _buildItem(true, rooms[0], 0)
: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(12.w),
),
),
child: SizedBox(
width: 230.w,
height: 230.w,
),
),
),
SizedBox(width: 10.w),
Column(
children: [
rooms.length > 1
? _buildItem(false, rooms[1], 1)
: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(12.w),
),
),
child: SizedBox(
width: 109.w,
height: 109.w,
),
),
SizedBox(height: 10.w),
rooms.length > 2
? _buildItem(false, rooms[2], 2)
: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(12.w),
),
),
child: SizedBox(
width: 109.w,
height: 109.w,
),
),
],
),
SizedBox(width: 10.w),
],
)
: Column(
spacing: 8.w,
children: [
rooms.isNotEmpty
? _buildItem(true, rooms[0], 0)
: SizedBox.shrink(),
rooms.length > 1
? _buildItem(false, rooms[1], 1)
: SizedBox.shrink(),
rooms.length > 2
? _buildItem(false, rooms[2], 2)
: SizedBox.shrink(),
],
),
SizedBox(height: 10.w),
isGrid
? Row(
children: [
SizedBox(width: 10.w),
Expanded(
child:
rooms.length > 3
? _buildItem(false, rooms[3], 3)
: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(12.w),
),
),
child: SizedBox(
width: 109.w,
height: 109.w,
),
),
),
SizedBox(width: 10.w),
Expanded(
child:
rooms.length > 4
? _buildItem(false, rooms[4], 4)
: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(12.w),
),
),
child: SizedBox(
width: 109.w,
height: 109.w,
),
),
),
SizedBox(width: 10.w),
Expanded(
child:
rooms.length > 5
? _buildItem(false, rooms[5], 5)
: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(12.w),
),
),
child: SizedBox(
width: 109.w,
height: 109.w,
),
),
),
SizedBox(width: 10.w),
],
)
: Container(),
_buildDrawerContent(),
_buildDrawerHandle(),
Container(
alignment: AlignmentDirectional.centerStart,
margin: EdgeInsetsDirectional.only(
start: 10.w,
bottom: 10.w,
),
child: text(
ATAppLocalizations.of(context)!.activity,
fontSize: 16.sp,
fontWeight: FontWeight.w600,
textColor: Colors.black,
),
),
Selector<AppGeneralManager, List<ATIndexBannerRes>>(
selector:
(_, provider) =>
List<ATIndexBannerRes>.unmodifiable(
provider.exploreBanners,
),
builder: (context, exploreBanners, child) {
return _banner(exploreBanners);
},
),
],
),
),
),
_isDrawerOpen
? GestureDetector(
onTap: _toggleDrawer,
child: Container(
height: 45.w,
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
text(
ATAppLocalizations.of(context)!.viewMore,
fontSize: 14.sp,
textColor: Colors.black54,
),
AnimatedSwitcher(
duration: const Duration(milliseconds: 350),
child: const Icon(Icons.keyboard_arrow_up, size: 20),
),
],
),
),
)
: Container(),
],
),
);
}
_banner(List<ATIndexBannerRes> exploreBanners) {
return exploreBanners.isNotEmpty
? Container(
margin: EdgeInsets.symmetric(horizontal: 10.w),
child: ListView.separated(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: exploreBanners.length,
// 列表项数量
padding: EdgeInsets.only(bottom: 15.w),
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
print('ads:${exploreBanners[index].toJson()}');
ATBannerUtils.openBanner(exploreBanners[index], context);
},
child: netImage(
height: 118.w,
url: exploreBanners[index].cover ?? "",
fit: BoxFit.fill,
borderRadius: BorderRadius.all(Radius.circular(12.w)),
),
);
},
separatorBuilder: (BuildContext context, int index) {
return SizedBox(height: 10.w);
},
),
)
: Container();
}
_buildItem(bool big, ChatVibeRoomRes res, int index) {
return GestureDetector(
child:
isGrid
? Stack(
alignment: Alignment.bottomCenter,
children: [
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(12.w)),
),
width: big ? 230.w : 109.w,
height: big ? 230.w : 109.w,
),
netImage(
url: res.roomCover ?? "",
fit: BoxFit.cover,
borderRadius: BorderRadius.all(Radius.circular(12.w)),
border:
index < 3
? null
: Border.all(
color: _strategy.getExploreRoomBorderColor(),
width: _strategy.getExploreRoomBorderWidth().w,
),
width: big ? 230.w : 109.w,
height: big ? 230.w : 109.w,
),
Container(
height: big ? 44.w : 30.w,
width: big ? 230.w : 109.w,
decoration: BoxDecoration(
color: Colors.black38,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(12.w),
bottomRight: Radius.circular(12.w),
),
),
child: Row(
children: [
SizedBox(width: 10.w),
ATCountryFlagImage(
countryName: res.countryName,
width: big ? 20.w : 15.w,
height: big ? 13.w : 8.w,
borderRadius: BorderRadius.all(
Radius.circular(big ? 2.w : 1.w),
),
),
SizedBox(width: big ? 10.w : 5.w),
Expanded(
child: Container(
constraints: BoxConstraints(
maxHeight: big ? 21.w : 18.w,
),
child:
(res.roomName?.length ?? 0) >
_strategy
.getExploreRoomNameMarqueeThreshold()
? Marquee(
text: res.roomName ?? "",
style: TextStyle(
fontSize: big ? 15.sp : 10.sp,
color: Colors.white,
decoration: TextDecoration.none,
),
scrollAxis: Axis.horizontal,
crossAxisAlignment:
CrossAxisAlignment.start,
blankSpace: 20.0,
velocity: 40.0,
pauseAfterRound: Duration(seconds: 1),
accelerationDuration: Duration(
seconds: 1,
),
accelerationCurve: Curves.easeOut,
decelerationDuration: Duration(
milliseconds: 500,
),
decelerationCurve: Curves.easeOut,
)
: Text(
res.roomName ?? "",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: big ? 15.sp : 10.sp,
color: Colors.white,
decoration: TextDecoration.none,
),
),
),
),
SizedBox(width: big ? 5.w : 3.w),
(res.extValues?.roomSetting?.password?.isEmpty ?? false)
? Image.asset(
"atu_images/general/at_icon_online_user.png",
width: big ? 14.w : 12.w,
height: big ? 14.w : 12.w,
)
: (_strategy.shouldShowPasswordRoomIcon()
? Image.asset(
"atu_images/index/at_icon_room_suo.png",
width: big ? 20.w : 16.w,
height: big ? 20.w : 16.w,
)
: Container(
width: big ? 20.w : 16.w,
height: big ? 20.w : 16.w,
)),
(res.extValues?.roomSetting?.password?.isEmpty ?? false)
? SizedBox(width: 3.w)
: Container(height: 10.w),
(res.extValues?.roomSetting?.password?.isEmpty ?? false)
? text(
res.extValues?.memberQuantity ?? "0",
textColor: Colors.white,
fontSize: big ? 12.sp : 10.sp,
)
: Container(height: 10.w),
SizedBox(width: 10.w),
],
),
),
index < 3
? IgnorePointer(
child: Image.asset(
_strategy.getExploreRankIconPattern(true, index + 1),
width: big ? 230.w : 109.w,
height: big ? 230.w : 109.w,
),
)
: Container(),
],
)
: SizedBox(
height: 105.w,
child: Stack(
alignment: Alignment.center,
children: [
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(13.w),
border:
index < 3
? null
: Border.all(
color: _strategy.getExploreRoomBorderColor(),
width:
_strategy.getExploreRoomBorderWidth().w,
),
),
margin: EdgeInsetsDirectional.symmetric(
horizontal: 10.w,
vertical: 3.w,
),
),
Row(
children: [
SizedBox(width: 20.w),
netImage(
url: res.roomCover ?? "",
fit: BoxFit.cover,
borderRadius: BorderRadius.all(Radius.circular(12.w)),
width: 85.w,
height: 85.w,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 15.w),
Row(
children: [
SizedBox(width: 8.w),
ATCountryFlagImage(
countryName: res.countryName,
width: 25.w,
height: 15.w,
borderRadius: BorderRadius.all(
Radius.circular(3.w),
),
),
SizedBox(width: 5.w),
Container(
constraints: BoxConstraints(
maxHeight: 21.w,
maxWidth: 150.w,
),
child:
(res.roomName?.length ?? 0) >
_strategy
.getExploreRoomNameMarqueeThreshold()
? Marquee(
text: res.roomName ?? "",
style: TextStyle(
fontSize: 15.sp,
color: Colors.black,
decoration: TextDecoration.none,
),
scrollAxis: Axis.horizontal,
crossAxisAlignment:
CrossAxisAlignment.start,
blankSpace: 20.0,
velocity: 40.0,
pauseAfterRound: Duration(
seconds: 1,
),
accelerationDuration: Duration(
seconds: 1,
),
accelerationCurve: Curves.easeOut,
decelerationDuration: Duration(
milliseconds: 500,
),
decelerationCurve: Curves.easeOut,
)
: Text(
res.roomName ?? "",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 15.sp,
color: Colors.black,
decoration: TextDecoration.none,
),
),
),
],
),
SizedBox(height: 3.w),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(width: 8.w),
text(
"ID:${res.roomAccount}",
fontWeight: FontWeight.w600,
textColor: Colors.black,
fontSize: 15.sp,
),
],
),
SizedBox(height: 3.w),
Row(
children: [
SizedBox(width: 8.w),
Image.asset(
"atu_images/family/at_icon_announcement_tag.png",
height: 25.w,
width: 25.w,
),
SizedBox(width: 4.w),
Container(
constraints: BoxConstraints(
maxHeight: 21.w,
maxWidth: 170.w,
),
child:
(res.roomDesc?.length ?? 0) >
_strategy
.getExploreRoomDescMarqueeThreshold()
? Marquee(
text: res.roomDesc ?? "",
style: TextStyle(
fontSize: 15.sp,
color: Colors.black,
decoration: TextDecoration.none,
),
scrollAxis: Axis.horizontal,
crossAxisAlignment:
CrossAxisAlignment.start,
blankSpace: 20.0,
velocity: 40.0,
pauseAfterRound: Duration(
seconds: 1,
),
accelerationDuration: Duration(
seconds: 1,
),
accelerationCurve: Curves.easeOut,
decelerationDuration: Duration(
milliseconds: 500,
),
decelerationCurve: Curves.easeOut,
)
: Text(
res.roomDesc ?? "",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 15.sp,
color: Colors.black,
decoration: TextDecoration.none,
),
),
),
],
),
],
),
],
),
index < 3
? IgnorePointer(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10.w),
child: Image.asset(
_strategy.getExploreRankIconPattern(
false,
index + 1,
),
fit: BoxFit.fill,
),
),
)
: Container(),
],
),
),
onTap: () {
Provider.of<RtcProvider>(
context,
listen: false,
).joinRoom(context, res.id ?? "");
},
);
}
void _toggleDrawer() {
setState(() {
_isDrawerOpen = !_isDrawerOpen;
});
}
Widget _buildDrawerHandle() {
return !_isDrawerOpen
? GestureDetector(
onTap: _toggleDrawer,
child: Container(
height: 45.w,
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
text(
ATAppLocalizations.of(context)!.viewMore,
fontSize: 14.sp,
textColor: Colors.black38,
),
AnimatedSwitcher(
duration: const Duration(milliseconds: 350),
child:
_isDrawerOpen
? const Icon(Icons.keyboard_arrow_up, size: 20)
: const Icon(Icons.keyboard_arrow_down, size: 20),
),
],
),
),
)
: Container();
}
Widget _buildDrawerContent() {
return _isDrawerOpen
? (drawerRooms.isNotEmpty
? Column(
spacing: 8.w,
mainAxisSize: MainAxisSize.min,
children: [
if (isGrid) SizedBox(height: 8.w),
ExploreBannerView(),
if (!isGrid && rooms.length > 3) _buildItem(false, rooms[3], 3),
if (!isGrid && rooms.length > 4) _buildItem(false, rooms[4], 4),
if (!isGrid && rooms.length > 5) _buildItem(false, rooms[5], 5),
isGrid
? GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount:
_strategy.getExploreDrawerGridCrossAxisCount(),
childAspectRatio: 1,
mainAxisSpacing: 10,
crossAxisSpacing: 10,
),
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
padding: EdgeInsets.all(10),
itemCount: drawerRooms.length,
itemBuilder: (context, index) {
return _buildItem(false, drawerRooms[index], index + 6);
},
)
: ListView.separated(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: drawerRooms.length,
itemBuilder: (context, index) {
return _buildItem(false, drawerRooms[index], index + 9);
},
separatorBuilder: (BuildContext context, int index) {
return SizedBox(height: 8.w);
},
),
],
)
: Container())
: Container();
}
}