You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

516 lines
17 KiB

3 years ago
import 'dart:math';
import 'package:aku_new_community/base/base_style.dart';
import 'package:aku_new_community/constants/api.dart';
3 years ago
import 'package:aku_new_community/constants/saas_api.dart';
3 years ago
import 'package:aku_new_community/model/common/img_model.dart';
3 years ago
import 'package:aku_new_community/models/community/all_dynamic_list_model.dart';
3 years ago
import 'package:aku_new_community/models/community/information_category_list_model.dart';
import 'package:aku_new_community/models/community/information_list_model.dart';
3 years ago
import 'package:aku_new_community/models/community/topic_model.dart';
3 years ago
import 'package:aku_new_community/provider/app_provider.dart';
import 'package:aku_new_community/provider/user_provider.dart';
import 'package:aku_new_community/ui/community/community_func.dart';
import 'package:aku_new_community/ui/community/community_views/add_new_event_page.dart';
import 'package:aku_new_community/ui/community/community_views/my_community_view.dart';
import 'package:aku_new_community/ui/community/community_views/new_community_view.dart';
import 'package:aku_new_community/ui/community/community_views/topic/topic_community_view.dart';
import 'package:aku_new_community/ui/community/community_views/widgets/chat_card.dart';
import 'package:aku_new_community/ui/home/public_infomation/public_infomation_card.dart';
3 years ago
import 'package:aku_new_community/ui/home/public_infomation/public_infomation_page.dart';
import 'package:aku_new_community/ui/home/public_infomation/public_information_detail_page.dart';
import 'package:aku_new_community/utils/headers.dart';
import 'package:aku_new_community/utils/login_util.dart';
import 'package:aku_new_community/utils/network/base_list_model.dart';
import 'package:aku_new_community/utils/network/base_model.dart';
import 'package:aku_new_community/utils/network/net_util.dart';
3 years ago
import 'package:aku_new_community/widget/others/user_tool.dart';
3 years ago
import 'package:bot_toast/bot_toast.dart';
import 'package:common_utils/common_utils.dart';
3 years ago
import 'package:flutter/cupertino.dart';
4 years ago
import 'package:flutter/material.dart';
3 years ago
import 'package:flutter_easyrefresh/easy_refresh.dart';
4 years ago
import 'package:get/get.dart';
import 'package:intl/intl.dart';
4 years ago
import 'package:provider/provider.dart';
4 years ago
class CommunityPage extends StatefulWidget {
4 years ago
CommunityPage({Key? key}) : super(key: key);
@override
_CommunityPageState createState() => _CommunityPageState();
}
class _CommunityPageState extends State<CommunityPage>
with TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
4 years ago
TabController? _tabController;
3 years ago
late EasyRefreshController _easyRefreshController;
3 years ago
List<String> get _tabs {
if (UserTool.userProvider.isLogin) return ['附近社区', '我的动态'];
return ['附近社区'];
}
GlobalKey<TopicCommunityViewState> topicKey =
GlobalKey<TopicCommunityViewState>();
GlobalKey<MyCommunityViewState> myKey = GlobalKey<MyCommunityViewState>();
GlobalKey<NewCommunityViewState> newKey = GlobalKey<NewCommunityViewState>();
3 years ago
List<AllDynamicListModel> _newItems = [];
List<TopicModel> _gambitModels = [];
3 years ago
List<InformationListModel> _hotNewsModels = [];
3 years ago
int _pageNum = 1;
int _size = 4;
bool _onload = true;
@override
void initState() {
super.initState();
3 years ago
_easyRefreshController = EasyRefreshController();
_tabController = TabController(
vsync: this,
length: _tabs.length,
);
}
@override
void dispose() {
_tabController?.dispose();
3 years ago
_easyRefreshController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
super.build(context);
final userProvider = Provider.of<UserProvider>(context);
final appProvider = Provider.of<AppProvider>(context);
3 years ago
return Scaffold(
3 years ago
appBar: AppBar(
titleSpacing: 0,
title: Align(
alignment: Alignment.centerLeft,
child: Theme(
data: ThemeData(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
),
child: TabBar(
onTap: (index) {
setState(() {});
},
controller: _tabController,
indicatorColor: Color(0xffffc40c),
indicatorPadding: EdgeInsets.only(bottom: 15.w),
indicator: const BoxDecoration(),
tabs: _tabs.map((e) => Tab(text: e)).toList(),
labelStyle:
3 years ago
TextStyle(fontSize: 36.sp, fontWeight: FontWeight.bold),
labelColor: Color(0xD9000000),
unselectedLabelStyle: TextStyle(fontSize: 32.sp),
unselectedLabelColor: Color(0x73000000),
isScrollable: true,
),
)),
3 years ago
backgroundColor: Colors.white,
actions: [
Padding(
padding: EdgeInsets.only(right: 32.w),
child: GestureDetector(
onTap: () async {
if (LoginUtil.isNotLogin) return;
bool? result = await Get.to(() => AddNewEventPage());
if (result == true) {
switch (_tabController!.index) {
case 0:
_easyRefreshController.callRefresh();
3 years ago
break;
case 1:
myKey.currentState!.refresh();
break;
3 years ago
}
3 years ago
}
},
child: Image.asset(R.ASSETS_ICONS_ICON_COMMUNITY_PUSH_PNG,
height: 40.w, width: 40.w),
),
)
],
),
body: TabBarView(
3 years ago
children: [
EasyRefresh(
firstRefresh: true,
header: MaterialHeader(),
controller: _easyRefreshController,
onRefresh: () async {
await (getNewInfo());
_gambitModels = await CommunityFunc.getListGambit();
_hotNewsModels = await CommunityFunc.getHotNews();
_onload = false;
setState(() {});
},
child: _onload
? SizedBox()
: ListView(
children: [
_geSearch(),
2.hb,
_hotNewsModels.isEmpty ? SizedBox() : _getInfo(),
16.hb,
_gambitModels.isEmpty ? SizedBox() : _getNews(),
16.hb,
..._newItems
.map((e) => ChatCard(
model: e,
onDelete: () {
_easyRefreshController.callRefresh();
setState(() {});
}))
.toList()
],
),
),
if (UserTool.userProvider.isLogin) MyCommunityView(key: myKey),
],
controller: _tabController,
3 years ago
),
);
3 years ago
}
Future getNewInfo() async {
3 years ago
BaseListModel baseListModel = await NetUtil().getList(
3 years ago
SAASAPI.community.dynamicList,
3 years ago
params: {"pageNum": _pageNum, "size": _size, 'type': 1});
if (baseListModel.rows.isNotEmpty) {
_newItems = (baseListModel.rows)
.map((e) => AllDynamicListModel.fromJson(e))
3 years ago
.toList();
}
}
Future loadNewInfo() async {
BaseListModel baseListModel =
3 years ago
await NetUtil().getList(API.market.hotTop, params: {
3 years ago
"pageNum": _pageNum,
"size": _size,
});
3 years ago
if (baseListModel.rows.isNotEmpty) {
_newItems.addAll((baseListModel.rows)
.map((e) => AllDynamicListModel.fromJson(e))
3 years ago
.toList());
}
}
3 years ago
///热门资讯
3 years ago
_getInfo() {
return Container(
color: Colors.white,
padding:
EdgeInsets.only(top: 32.w, bottom: 32.w, left: 32.w, right: 32.w),
child: Column(
children: [
3 years ago
_homeTitle('热门资讯', () async {
final cancel = BotToast.showLoading();
3 years ago
BaseModel model =
3 years ago
await NetUtil().get(SAASAPI.information.categoryList);
3 years ago
var category = <InformationCategoryListModel>[];
if (model.success == true && model.data != null) {
3 years ago
category = (model.data as List)
3 years ago
.map((e) => InformationCategoryListModel.fromJson(e))
3 years ago
.toList();
}
cancel();
3 years ago
Get.to(() => PublicInfomationPage(models: category));
3 years ago
}, '更多'),
3 years ago
32.hb,
Container(
height: 204.w,
child: ListView.separated(
padding: EdgeInsets.zero,
separatorBuilder: (context, index) {
return SizedBox(
width: 24.w,
);
},
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
return Container(
width: 396.w,
child: Builder(
builder: (context) {
return _infoCard(_hotNewsModels[index]);
3 years ago
},
),
);
},
itemCount: _hotNewsModels.length,
3 years ago
),
),
3 years ago
],
),
);
}
_homeTitle(String title, VoidCallback onTap, String suffixTitle) {
return Row(
children: [
title.text.size(32.sp).bold.make(),
Spacer(),
GestureDetector(
onTap: onTap,
child: Container(
color: Colors.transparent,
child: Row(
children: [
suffixTitle.text.size(24.sp).color(Color(0xFF999999)).make(),
8.wb,
Icon(
CupertinoIcons.chevron_forward,
size: 24.w,
color: Color(0xFF999999),
),
],
),
),
),
3 years ago
//24.wb,
],
3 years ago
);
}
3 years ago
_next(int min, int max) {
var rng = new Random();
//将 参数min + 取随机数最大值范围参数max - 参数min的结果 赋值给变量 result;
var result = min + rng.nextInt(max - min);
//返回变量 result 的值;
return result;
}
3 years ago
_infoCard(InformationListModel item) {
return GestureDetector(
3 years ago
onTap: () async {
var result =
3 years ago
await Get.to(() => PublicInformationDetailPage(id: item.id));
CommunityFunc.addViews(item.id);
3 years ago
if (result) {
3 years ago
_easyRefreshController.callRefresh();
}
},
child: Stack(
3 years ago
children: [
Container(
width: 396.w,
height: 204.w,
decoration: BoxDecoration(
borderRadius: BorderRadius.horizontal(
right: Radius.circular(12),
left: Radius.circular(16),
3 years ago
),
image: DecorationImage(
image: NetworkImage(
3 years ago
SAASAPI.image(ImgModel.first(item.imgList)),
3 years ago
),
fit: BoxFit.cover,
),
//color: Colors.black38,
),
),
Positioned(
top: 0,
bottom: 0,
left: 0,
right: 0,
child: Container(
alignment: Alignment.center,
width: 396.w,
height: 204.w,
3 years ago
padding: EdgeInsets.only(
top: 32.w, left: 40.w, right: 40.w, bottom: 32.w),
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.5),
borderRadius: BorderRadius.horizontal(
right: Radius.circular(12),
left: Radius.circular(16),
), //color: Colors.black38,
),
3 years ago
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 316.w,
alignment: Alignment.centerLeft,
child: Text(
3 years ago
item.title,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.white.withOpacity(0.85),
fontSize: 28.sp,
fontWeight: FontWeight.bold),
3 years ago
)),
24.hb,
Row(
children: [
Text(
3 years ago
'${item.viewsNum}浏览',
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.white.withOpacity(0.85),
fontSize: 24.sp,
),
),
Spacer(),
Text(
RelativeDateFormat.format(item.createDate.toDate()),
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.white.withOpacity(0.85),
fontSize: 24.sp,
),
)
],
)
],
),
),
),
3 years ago
],
),
);
}
_getNews() {
return Container(
color: Colors.white,
3 years ago
padding: EdgeInsets.only(
top: 32.w,
bottom: 32.w,
),
3 years ago
child: Column(
children: [
Container(
3 years ago
padding: EdgeInsets.only(left: 32.w, right: 32.w),
child: _homeTitle('新鲜话题', () {
Get.to(() => TopicCommunityView());
}, '全部'),
3 years ago
),
32.hb,
_searchHistoryWidget()
],
),
);
}
_geSearch() {
return Container(
padding: EdgeInsets.only(bottom: 20.w, left: 32.w, right: 32.w),
color: Colors.white,
3 years ago
child: MaterialButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
height: 74.w,
shape: StadiumBorder(),
elevation: 0,
minWidth: double.infinity,
color: Color(0xFFF3F3F3),
onPressed: () {
//Get.to(() => SearchGoodsPage());
},
3 years ago
child: Row(
children: [
Icon(
Icons.search,
size: 32.w,
color: Color(0xFF666666),
),
10.wb,
'请输入关键字'.text.size(28.sp).color(ktextSubColor).make().expand(),
],
),
),
3 years ago
);
}
_searchHistoryWidget() {
return Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.only(left: 32.w, right: 32.w),
3 years ago
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
3 years ago
child: Wrap(
children: [..._gambitModels.map((e) => _choiceChip(e)).toList()]
3 years ago
// [_choiceChip('EDG夺冠',1),_choiceChip('双十一',2),
// _choiceChip('11月吃土',2),_choiceChip('成都疫情',0),_choiceChip('万圣节',0)],
),
),
3 years ago
// Spacer()
],
),
);
}
3 years ago
_choiceChip(TopicModel item) {
3 years ago
return Padding(
padding: EdgeInsets.only(right: 12.w, bottom: 24.w),
3 years ago
child: ChoiceChip(
3 years ago
backgroundColor: Color(0xFFF4F7FC),
// disabledColor: Colors.blue,
labelStyle: TextStyle(fontSize: 15 * 2.sp, color: Colors.black),
3 years ago
3 years ago
labelPadding: EdgeInsets.only(right: 12.w, left: 12.w),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onSelected: (bool value) {
3 years ago
// Get.to(() => TopicDetailPage(model: item));
3 years ago
},
label: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
3 years ago
'# ${item.title}',
3 years ago
style: TextStyle(
color: Colors.black.withOpacity(0.65),
fontSize: 28.sp,
fontWeight: FontWeight.w500),
),
3 years ago
item.type != 1 ? 8.wb : SizedBox(),
item.type != 1 ? _chipType(item.type) : SizedBox()
3 years ago
],
3 years ago
),
3 years ago
selected: false,
),
3 years ago
);
}
_chipType(int type) {
return Container(
width: 32.w,
height: 32.w,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(6.4.w),
),
3 years ago
color: type == 1 ? Color(0xFFFFD76F) : Color(0xFFFF8383),
),
3 years ago
child: Text(
type == 1 ? '' : '',
style: TextStyle(
color: type == 1
? Colors.black.withOpacity(0.65)
: Colors.white.withOpacity(0.85),
fontSize: 20.sp,
fontWeight: FontWeight.w500),
),
);
}
@override
bool get wantKeepAlive => true;
}