478 lines
17 KiB
Dart
478 lines
17 KiB
Dart
import 'package:cached_network_image/cached_network_image.dart';
|
||
import 'package:circle_app/app/circle/logic.dart';
|
||
import 'package:circle_app/app/circle/view.dart';
|
||
import 'package:circle_app/app/circle/widgets/info_list_view.dart';
|
||
import 'package:circle_app/app/userinfo/logic.dart';
|
||
import 'package:circle_app/router/app_routers.dart';
|
||
import 'package:circle_app/util/eventBus.dart';
|
||
import 'package:circle_app/util/util.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||
import 'package:flutter_swiper/flutter_swiper.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:get/get_core/src/get_main.dart';
|
||
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
||
|
||
class Vicinity extends StatefulWidget {
|
||
CircleLogic logic;
|
||
// TODO: add state variables, methods and constructor params
|
||
Vicinity(this.logic);
|
||
|
||
@override
|
||
State<Vicinity> createState() => _VicinityState();
|
||
}
|
||
|
||
class _VicinityState extends State<Vicinity> with AutomaticKeepAliveClientMixin {
|
||
var sub;
|
||
ScrollController _scrollController = ScrollController();
|
||
@override
|
||
void initState() {
|
||
// TODO: implement initState
|
||
super.initState();
|
||
sub = EventBusManager.on<NearScrollTap>().listen((event) {
|
||
_scrollController.animateTo(0,
|
||
duration: const Duration(milliseconds: 300), curve: Curves.easeInOut);
|
||
});
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
// TODO: implement dispose
|
||
super.dispose();
|
||
_scrollController.dispose();
|
||
sub.cancel();
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
// TODO: add widget build method
|
||
if (widget.logic.myVip == 0) {
|
||
_scrollController.jumpTo(_scrollController.offset - 150.sp);
|
||
}
|
||
return widget.logic.vicinityList.isNotEmpty ? Stack(
|
||
fit: StackFit.expand,
|
||
children: [
|
||
SmartRefresher(
|
||
controller: widget.logic.refreshController,
|
||
onRefresh: _onRefresh,
|
||
onLoading: _onLoading,
|
||
enablePullUp: true,
|
||
child: ListView.builder(
|
||
controller: _scrollController,
|
||
physics: widget.logic.myVip ==0 ? NeverScrollableScrollPhysics() : BouncingScrollPhysics(),
|
||
padding: EdgeInsets.all(10.sp),
|
||
itemCount: widget.logic.vicinityList.length + 1,
|
||
itemBuilder: (context, index) {
|
||
if (index == 0) {
|
||
return bannerView(widget.logic);
|
||
} else {
|
||
return ListItem(widget.logic.vicinityList[index - 1], index - 1);
|
||
}
|
||
},
|
||
),
|
||
),
|
||
if (widget.logic.myVip == 0)
|
||
Positioned(
|
||
bottom: 0,
|
||
child: showVipView())
|
||
],
|
||
) : loaddingWidget(true);
|
||
}
|
||
|
||
Widget bannerView(CircleLogic controller) {
|
||
return SizedBox(
|
||
height: 160.sp,
|
||
// margin: EdgeInsets.symmetric(horizontal: 16.sp),
|
||
child: Swiper(
|
||
autoplay: widget.logic.bannerList.length > 1,
|
||
controller: widget.logic.swiperController,
|
||
autoplayDelay: 6000,
|
||
loop: widget.logic.bannerList.length > 1 ? true : false,
|
||
// index:logic.index,
|
||
itemBuilder: (BuildContext context, int index) {
|
||
return GestureDetector(
|
||
onTap: () async {
|
||
// print(logic.bannerList[index].param);
|
||
navigateToCustomRoute(widget.logic.bannerList[index]);
|
||
},
|
||
child: SizedBox(
|
||
width: Get.width,
|
||
child: ClipRRect(
|
||
borderRadius: BorderRadius.circular(15.sp),
|
||
child: CachedNetworkImage(
|
||
imageUrl: widget.logic.bannerList[index].picUrl,
|
||
fit: BoxFit.fill,
|
||
width: Get.width,
|
||
),
|
||
)),
|
||
);
|
||
},
|
||
itemCount: widget.logic.bannerList.length,
|
||
pagination: SwiperPagination(
|
||
margin: EdgeInsets.all(5.0.sp), // 设置外边距
|
||
alignment: Alignment.bottomCenter,
|
||
builder: DotSwiperPaginationBuilder(
|
||
color: Color(0x00FFFFFF), // 小圆点的颜色
|
||
activeColor: widget.logic.bannerList.length == 1
|
||
? Color(0x00FFFFFF)
|
||
: Color(0x00FFFFFF), // 当前索引小圆点的颜色
|
||
),
|
||
),
|
||
// control: new SwiperControl(), //左右的那个箭头,在某模拟器中会出现蓝线
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget circleList(CircleLogic controller) {
|
||
return Swiper(
|
||
itemBuilder: (BuildContext context, int index) {
|
||
var bean = widget.logic.circle.lists[index];
|
||
// final GlobalKey<InfoListViewState> infoListViewKey = GlobalKey<InfoListViewState>();
|
||
return InfoListView(index, bean, widget.logic);
|
||
},
|
||
onIndexChanged: (index) {
|
||
controller.state.index = index;
|
||
if (index == widget.logic.circle.lists.length - 1) {
|
||
widget.logic.loadMore();
|
||
}
|
||
print(index.toString());
|
||
},
|
||
index: controller.state.index,
|
||
itemCount: widget.logic.circle.lists.length,
|
||
viewportFraction: 0.93,
|
||
// scale: 0.9,
|
||
loop: false,
|
||
// key: UniqueKey(),
|
||
// pagination: new SwiperPagination(),//如果不填则不显示指示点
|
||
// control: new SwiperControl(),//如果不填则不显示左右按钮
|
||
);
|
||
}
|
||
|
||
Widget showVipView() {
|
||
return Container(
|
||
width: Get.width,
|
||
// margin: EdgeInsets.only(top: 10.sp),
|
||
color: Colors.black87,
|
||
padding: EdgeInsets.symmetric(vertical: 14.sp, horizontal: 20.sp),
|
||
child: Column(
|
||
children: [
|
||
Center(
|
||
child: Text(
|
||
"VIP特权",
|
||
style: TextStyle(color: Colors.white, fontSize: 16.sp),
|
||
),
|
||
),
|
||
Container(
|
||
padding: EdgeInsets.only(top: 18.sp),
|
||
child: Text(
|
||
"开通VIP后,才能查看更多附近的圈友,也可以根据您的喜好、属性、角色、取向等筛选出想要认识的人,还可以获得其他十几种会员特权,拥有更多不一样的体验",
|
||
style: TextStyle(color: Colors.white, fontSize: 14.sp),
|
||
),
|
||
),
|
||
GestureDetector(
|
||
onTap: () async {
|
||
widget.logic.showRechargeDialog();
|
||
},
|
||
child: Center(
|
||
child: Container(
|
||
margin: EdgeInsets.only(top: 14.sp),
|
||
decoration: BoxDecoration(
|
||
borderRadius: BorderRadius.circular(17),
|
||
gradient: const LinearGradient(
|
||
colors: [
|
||
Color(0xFF06F9FA),
|
||
Color(0xFFDC5BFD),
|
||
],
|
||
begin: Alignment.centerLeft,
|
||
end: Alignment.centerRight,
|
||
),
|
||
),
|
||
padding: EdgeInsets.symmetric(
|
||
vertical: 10.sp,
|
||
horizontal: 55.sp,
|
||
),
|
||
child: const Text(
|
||
"前往开通VIP",
|
||
style: TextStyle(
|
||
color: Colors.white,
|
||
fontSize: 12,
|
||
),
|
||
),
|
||
),
|
||
))
|
||
],
|
||
));
|
||
}
|
||
|
||
Widget ListItem(VicinityItemBean item, int index) {
|
||
return GestureDetector(
|
||
onTap: () {
|
||
Get.toNamed(AppRoutes.UserInfoActivity, arguments: item.id.toString());
|
||
},
|
||
child: Container(
|
||
margin: EdgeInsets.only(top: 10.sp),
|
||
// padding: EdgeInsets.only( left: 8.sp, right: 8.sp),
|
||
width: Get.width,
|
||
height: 200.sp,
|
||
decoration: BoxDecoration(
|
||
image: DecorationImage(
|
||
fit: BoxFit.fill,
|
||
image: AssetImage(
|
||
getCircleImage('pic_bg'),
|
||
))),
|
||
child: Stack(
|
||
children: [
|
||
Container(
|
||
margin: EdgeInsets.only(top: 1.sp, left: 1.sp, right: 1.sp),
|
||
child: ClipRRect(
|
||
borderRadius: BorderRadius.only(
|
||
topLeft: Radius.circular(10.sp),
|
||
topRight: Radius.circular(10.sp),
|
||
),
|
||
child: item.images.length == 0
|
||
? Image(
|
||
image: AssetImage(getCircleImage("icon_list_null")),
|
||
width: Get.width,
|
||
fit: BoxFit.fill,
|
||
height: 92.sp,
|
||
)
|
||
: Container(),
|
||
),
|
||
),
|
||
Column(children: [
|
||
Container(
|
||
margin: EdgeInsets.only(right: 2.sp),
|
||
child: Row(
|
||
children: [
|
||
Container(
|
||
margin: EdgeInsets.only(top: 6.sp, left: 8.sp),
|
||
width: 88.sp,
|
||
height: 88.sp,
|
||
decoration: BoxDecoration(
|
||
borderRadius: BorderRadius.circular(8.0),
|
||
gradient: const LinearGradient(
|
||
begin: Alignment.topCenter,
|
||
end: Alignment.bottomCenter,
|
||
colors: [
|
||
Color(0xFF71F3F2),
|
||
Color(0xFFF558FF),
|
||
],
|
||
stops: [0.0365, 0.9427],
|
||
),
|
||
),
|
||
padding: EdgeInsets.all(2.sp),
|
||
child: ClipRRect(
|
||
borderRadius: BorderRadius.circular(8.0),
|
||
child: Image.network(item.avatarThumb,
|
||
width: 88.sp, height: 88.sp, fit: BoxFit.cover),
|
||
),
|
||
),
|
||
Expanded(
|
||
child: SingleChildScrollView(
|
||
scrollDirection: Axis.horizontal,
|
||
child: Container(
|
||
margin: EdgeInsets.only(top: 6.sp),
|
||
child: Row(
|
||
children: [
|
||
for (int i = 0; i < item.images.length; i++)
|
||
GestureDetector(
|
||
onTap: () {
|
||
Get.toNamed(AppRoutes.Swiper,
|
||
arguments: {
|
||
'imaglist': item.images,
|
||
'index': i
|
||
});
|
||
},
|
||
child: ListAlbumItem(item.images[i], i)),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
Container(
|
||
margin: EdgeInsets.only(top: 6.sp, left: 9.sp),
|
||
child: Row(
|
||
children: [
|
||
Text(
|
||
item.nickname,
|
||
style: TextStyle(
|
||
fontWeight: FontWeight.bold,
|
||
color: const Color.fromRGBO(247, 250, 250, 1.0),
|
||
fontSize: 16.sp,
|
||
),
|
||
),
|
||
SizedBox(width: 8.sp),
|
||
_buildInfoRow(item),
|
||
const Spacer(),
|
||
Container(
|
||
margin: EdgeInsets.only(right: 8.sp),
|
||
child: Text(
|
||
item.onlineFlag.toString(),
|
||
style: TextStyle(
|
||
color: const Color.fromRGBO(247, 250, 250, 1.0),
|
||
fontSize: 12.sp,
|
||
),
|
||
)),
|
||
],
|
||
),
|
||
),
|
||
Container(
|
||
height: 38.sp, // 设置固定高度
|
||
width: Get.width,
|
||
margin: EdgeInsets.symmetric(horizontal: 8.0),
|
||
child: Align(
|
||
alignment: Alignment.centerLeft, // 文本左对齐,垂直居中
|
||
child: Text(
|
||
item.signature,
|
||
maxLines: 2,
|
||
style: TextStyle(color: Colors.white, fontSize: 14.sp),
|
||
overflow: TextOverflow.ellipsis,
|
||
),
|
||
),
|
||
),
|
||
Container(
|
||
margin: EdgeInsets.only(left: 8.sp, right: 3.sp,bottom: 5.sp),
|
||
child: _buildInterestsListView(item.interests))
|
||
]),
|
||
],
|
||
)),
|
||
);
|
||
}
|
||
|
||
Widget ListAlbumItem(String item, int index) {
|
||
return Container(
|
||
margin: EdgeInsets.symmetric(horizontal: 2.sp),
|
||
child: CachedNetworkImage(
|
||
width: 88.sp,
|
||
height: 88.sp,
|
||
fit: BoxFit.cover,
|
||
imageUrl: item + "?imageView2/1/w/176/h/176/q/75",
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildInfoRow(VicinityItemBean item) {
|
||
String ageMsg =
|
||
getAgeCOntent(item!.gender, item!.age, item!.role, item!.orientation);
|
||
return Row(
|
||
children: [
|
||
Container(
|
||
decoration: BoxDecoration(
|
||
borderRadius: BorderRadius.circular(17),
|
||
gradient: const LinearGradient(
|
||
colors: [
|
||
Color.fromRGBO(141, 255, 248, 1.0),
|
||
Color.fromRGBO(181, 211, 255, 1.0),
|
||
],
|
||
begin: Alignment.centerLeft,
|
||
end: Alignment.centerRight,
|
||
),
|
||
),
|
||
padding: EdgeInsets.only(
|
||
top: 2.sp,
|
||
bottom: 2.sp,
|
||
left: 10.sp,
|
||
right: 10.sp,
|
||
),
|
||
child: Text(
|
||
ageMsg,
|
||
style: const TextStyle(
|
||
color: Colors.black,
|
||
fontSize: 10,
|
||
),
|
||
),
|
||
),
|
||
const SizedBox(width: 6),
|
||
if (item.vip > 0)
|
||
Image(
|
||
image: AssetImage(getBaseImage(item.vip == 1 ? "vip" : 'year_vip')),
|
||
width: 44.sp,
|
||
height: 18.sp,
|
||
),
|
||
],
|
||
);
|
||
}
|
||
|
||
Widget _buildInterestsListView(List<Interest> interests) {
|
||
return Align(
|
||
alignment: Alignment.centerLeft,
|
||
child: SingleChildScrollView(
|
||
scrollDirection: Axis.horizontal,
|
||
child: Row(
|
||
children: [
|
||
for (int index = 0; index < interests.length; index++)
|
||
GestureDetector(
|
||
onTap: () {
|
||
Get.toNamed(AppRoutes.Signal_circle_list,
|
||
arguments: interests[index].id);
|
||
},
|
||
child: Container(
|
||
margin: EdgeInsets.only(right: 11.sp),
|
||
decoration: BoxDecoration(
|
||
borderRadius: BorderRadius.circular(17.0),
|
||
gradient: const LinearGradient(
|
||
colors: [
|
||
Color(0xFF06F9FA),
|
||
Color(0xFFDC5BFD),
|
||
],
|
||
),
|
||
color: const Color(0xFF392D53),
|
||
),
|
||
child: Container(
|
||
margin: EdgeInsets.all(1.sp),
|
||
decoration: BoxDecoration(
|
||
borderRadius: BorderRadius.circular(17.0),
|
||
color: const Color(0xFF392D53),
|
||
),
|
||
child: Padding(
|
||
padding: EdgeInsets.only(
|
||
top: 2.sp,
|
||
bottom: 2.sp,
|
||
left: 15.sp,
|
||
right: 15.sp,
|
||
),
|
||
child: Center(
|
||
child: Text(
|
||
interests[index].title,
|
||
style: const TextStyle(
|
||
fontSize: 13.0,
|
||
color: Colors.white,
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
void _onRefresh() async {
|
||
widget.logic.vicinityPage = 1;
|
||
widget.logic.offset = 0;
|
||
widget.logic.getNearByList();
|
||
// logic.refreshController.refreshCompleted();
|
||
}
|
||
|
||
void _onLoading() async {
|
||
// if (widget.logic.myVip > 0) {
|
||
// widget.logic.vicinityPage = widget.logic.vicinityPage + 1;
|
||
// logic.offset = 0;
|
||
//
|
||
widget.logic.getNearByList();
|
||
// } else {
|
||
// widget.logic.refreshController.loadComplete();
|
||
// }
|
||
}
|
||
|
||
@override
|
||
// TODO: implement wantKeepAlive
|
||
bool get wantKeepAlive => true;
|
||
}
|