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_compontent.dart'; import 'package:aslan/chatvibe_ui/components/text/at_text.dart'; import 'package:marquee/marquee.dart'; import 'package:provider/provider.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:aslan/chatvibe_ui/components/custom_cached_image.dart'; import 'package:aslan/chatvibe_core/utilities/at_banner_utils.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/country/at_country_flag_image.dart'; class ExplorePage extends StatefulWidget { @override _ExplorePageState createState() => _ExplorePageState(); } class _ExplorePageState extends State with SingleTickerProviderStateMixin { bool _isDrawerOpen = false; final RefreshController _refreshController = RefreshController( initialRefresh: false, ); List rooms = []; List drawerRooms = []; bool isLoading = false; @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(); if (rooms.length > 6) { drawerRooms.addAll(rooms.sublist(6, rooms.length)); } isLoading = false; _refreshController.refreshCompleted(); _refreshController.loadComplete(); if (mounted) setState(() {}); }) .catchError((e) { _refreshController.loadNoData(); _refreshController.refreshCompleted(); isLoading = false; if (mounted) setState(() {}); }); Provider.of(context, listen: false).loadMainBanner(); } @override Widget build(BuildContext context) { return Scaffold( resizeToAvoidBottomInset: false, backgroundColor: Colors.transparent, body: 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, ), ], ), SizedBox(height: 10.w), Row( children: [ SizedBox(width: 10.w), Expanded( child: rooms.isNotEmpty ? _buildItem(true, rooms[0]) : Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all( Radius.circular(12.w), ), ), child: CustomCachedImage( imageUrl: "", fit: BoxFit.cover, borderRadius: 12.w, width: 230.w, height: 230.w, ), ), ), SizedBox(width: 10.w), Column( children: [ rooms.length > 1 ? _buildItem(false, rooms[1]) : Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all( Radius.circular(12.w), ), ), child: CustomCachedImage( imageUrl: "", fit: BoxFit.cover, borderRadius: 12.w, width: 109.w, height: 109.w, ), ), SizedBox(height: 10.w), rooms.length > 2 ? _buildItem(false, rooms[2]) : Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all( Radius.circular(12.w), ), ), child: CustomCachedImage( imageUrl: "", fit: BoxFit.cover, borderRadius: 12.w, width: 109.w, height: 109.w, ), ), ], ), SizedBox(width: 10.w), ], ), SizedBox(height: 10.w), Row( children: [ SizedBox(width: 10.w), Expanded( child: rooms.length > 3 ? _buildItem(false, rooms[3]) : Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all( Radius.circular(12.w), ), ), child: CustomCachedImage( imageUrl: "", fit: BoxFit.cover, borderRadius: 12.w, width: 109.w, height: 109.w, ), ), ), SizedBox(width: 10.w), Expanded( child: rooms.length > 4 ? _buildItem(false, rooms[4]) : Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all( Radius.circular(12.w), ), ), child: CustomCachedImage( imageUrl: "", fit: BoxFit.cover, borderRadius: 12.w, width: 109.w, height: 109.w, ), ), ), SizedBox(width: 10.w), Expanded( child: rooms.length > 5 ? _buildItem(false, rooms[5]) : Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all( Radius.circular(12.w), ), ), child: CustomCachedImage( imageUrl: "", fit: BoxFit.cover, borderRadius: 12.w, width: 109.w, height: 109.w, ), ), ), SizedBox(width: 10.w), ], ), _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>( selector: (_, provider) => List.unmodifiable( provider.exploreBanners, ), builder: (context, exploreBanners, child) { return _banner(exploreBanners); }, ), ], ), ), ), ); } _banner(List 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) { return GestureDetector( child: 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, ), CustomCachedImage( imageUrl: res.roomCover ?? "", fit: BoxFit.cover, borderRadius: 12.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.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) > 10 ? 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: 550), 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.gif", width: big ? 14.w : 12.w, height: big ? 14.w : 12.w, ) : Image.asset( "atu_images/index/at_icon_room_suo.png", 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), ], ), ), ], ), onTap: () { Provider.of( context, listen: false, ).joinRoom(context, res.id ?? ""); }, ); } void _toggleDrawer() { setState(() { _isDrawerOpen = !_isDrawerOpen; }); } Widget _buildDrawerHandle() { return 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), ), ], ), ), ); } Widget _buildDrawerContent() { return _isDrawerOpen ? (drawerRooms.isNotEmpty ? GridView.builder( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 3, 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]); }, ) : Container()) : Container(); } }