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.

152 lines
4.3 KiB

3 years ago
import 'package:flutter/material.dart';
3 years ago
import 'package:flutter_svg/flutter_svg.dart';
import 'package:huixiang/community/community_child_page.dart';
import 'package:huixiang/home/huixiang_brand_page.dart';
import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/view_widget/my_tab.dart';
3 years ago
3 years ago
import 'community_course.dart';
import 'headlines/article_page.dart';
3 years ago
3 years ago
class CommunityPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _CommunityPage();
}
}
3 years ago
class _CommunityPage extends State<CommunityPage>
with SingleTickerProviderStateMixin {
3 years ago
TabController tabcontroller;
CommunityChildPage guanzhu,tuijian ;
final GlobalKey tuijianKey = GlobalKey();
final GlobalKey guanzhuKey = GlobalKey();
3 years ago
List<String> lables = [
"关注",
"分享健康",
"了解健康",
"学习健康",
"关于回乡",
3 years ago
// "直播",
];
ScrollPhysics b = BouncingScrollPhysics();
int scrollCount = 0;
3 years ago
3 years ago
@override
3 years ago
void initState() {
super.initState();
3 years ago
if (tabcontroller == null)
3 years ago
tabcontroller = TabController(length: lables.length, vsync: this, initialIndex: 1);
3 years ago
}
void onChildScroll(){
if(scrollCount == 0){
setState(() {
b = NeverScrollableScrollPhysics();
});
}
scrollCount+=1;
Future.delayed(Duration(seconds:1), () {
scrollCount-=1;
if(scrollCount == 0){
setState(() {
b = BouncingScrollPhysics();
});
}
});
}
_toRelease() async {
3 years ago
await Navigator.of(context).pushNamed('/router/release_dynamic');
if(tabcontroller.index == 0){
CommunityChildPageState page = guanzhuKey.currentState;
page.onRefresh();
}else if(tabcontroller.index == 1){
CommunityChildPageState page = tuijianKey.currentState;
page.onRefresh();
}
}
3 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: MyAppBar(
leading: false,
titleChild: PreferredSize(
preferredSize: Size(
3 years ago
MediaQuery.of(context).size.width - 60.w,
3 years ago
38.h,
),
child: TabBar(
controller: tabcontroller,
automaticIndicatorColorAdjustment: true,
isScrollable: true,
indicatorWeight: 2,
indicatorColor: Color(0xFF39B54A),
labelPadding: EdgeInsets.only(left: 8.w, right: 8.w),
indicatorSize: TabBarIndicatorSize.label,
unselectedLabelStyle: TextStyle(
3 years ago
fontSize: MediaQuery.of(context).size.width >= 650 ? 10.sp : 15.sp,
3 years ago
fontWeight: FontWeight.w400,
),
labelStyle: TextStyle(
color: Colors.black,
3 years ago
fontSize: MediaQuery.of(context).size.width >= 650 ? 12.sp : 18.sp,
3 years ago
fontWeight: FontWeight.bold,
),
labelColor: Colors.black,
tabs: lables.map((e) => MyTab(text: e)).toList(),
),
),
3 years ago
onTap: () {
_toRelease();
3 years ago
},
action: GestureDetector(
behavior: HitTestBehavior.opaque,
child: Container(color: Colors.transparent,
3 years ago
padding: EdgeInsets.only(left: 20.w,right: 20.w),
child: SvgPicture.asset(
"assets/svg/shequ_fabu.svg",
fit: BoxFit.contain,
width: 24,
height: 24,
),)
)
3 years ago
),
body: Container(
padding: EdgeInsets.only(bottom: 76.h),
child: TabBarView(
physics: b,
3 years ago
children: lables.map((e) {
if (e == "关于回乡") {
3 years ago
return BrandPage();
}else if(e == "了解健康"){
3 years ago
return ArticlePage(onChildScroll);
}else if(e == "学习健康"){
3 years ago
return CommunityCourse();
}
else if(e == "分享健康"){
3 years ago
if (tuijian == null){
tuijian = CommunityChildPage(tuijianKey,"分享健康",onChildScroll);
3 years ago
}
return tuijian;
}else if(e == "关注"){
if (guanzhu == null){
guanzhu = CommunityChildPage(guanzhuKey,"关注",onChildScroll);
3 years ago
}
return guanzhu;
3 years ago
}
}).toList(),
controller: tabcontroller,
),
),
);
}
}