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.
 
 
 
 
 
 

157 lines
4.3 KiB

import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:huixiang/community/community_child_page.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/view_widget/my_tab.dart';
import '../utils/upload_async.dart';
import 'community_course.dart';
class CommunityPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _CommunityPage();
}
}
class _CommunityPage extends State<CommunityPage>
with
SingleTickerProviderStateMixin,
AutomaticKeepAliveClientMixin,
UploadObserver {
TabController? tabcontroller;
CommunityChildPage? guanzhu, tuijian;
final GlobalKey tuijianKey = GlobalKey();
final GlobalKey guanzhuKey = GlobalKey();
List<String> lables = [
"关注",
"广场",
// "了解健康",
"视频",
// "关于回乡",
// "直播",
];
ScrollPhysics b = BouncingScrollPhysics();
int scrollCount = 0;
@override
void initState() {
super.initState();
UploadInstance.instance.uploadObserverList.add(this);
if (tabcontroller == null)
tabcontroller = TabController(length: lables.length, vsync: this, initialIndex: 1);
}
@override
void dispose() {
super.dispose();
UploadInstance.instance.uploadObserverList.remove(this);
}
void onChildScroll() {
if (scrollCount == 0) {
setState(() {
b = NeverScrollableScrollPhysics();
});
}
scrollCount += 1;
Future.delayed(Duration(seconds: 1), () {
scrollCount -= 1;
if (scrollCount == 0) {
setState(() {
b = BouncingScrollPhysics();
});
}
});
}
@override
void onUploadFinish() {
if (tabcontroller?.index == 0) {
CommunityChildPageState? page =
guanzhuKey.currentState as CommunityChildPageState?;
page?.onRefresh();
} else if (tabcontroller?.index == 1) {
CommunityChildPageState? page =
tuijianKey.currentState as CommunityChildPageState?;
page?.onRefresh();
}
}
_toRelease() async {
Navigator.of(context).pushNamed('/router/release_dynamic');
}
@override
Widget build(BuildContext context) {
super.build(context);
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: SizedBox(
width: MediaQuery.of(context).size.width - 160,
child: TabBar(
controller: tabcontroller,
automaticIndicatorColorAdjustment: true,
isScrollable: false,
indicatorWeight: 2,
dividerHeight: 0,
dividerColor: Colors.transparent,
indicatorColor: Color(0xFF39B54A),
labelPadding: EdgeInsets.only(left: 8.w, right: 8.w),
indicatorSize: TabBarIndicatorSize.label,
unselectedLabelStyle: TextStyle(
fontSize: MediaQuery.of(context).size.width >= 650 ? 10.sp : 15.sp,
fontWeight: FontWeight.w400,
),
labelStyle: TextStyle(
color: Colors.black,
fontSize:
MediaQuery.of(context).size.width >= 650 ? 12.sp : 18.sp,
fontWeight: FontWeight.bold,
),
labelColor: Colors.black,
tabs: lables.map((e) => MyTab(text: e)).toList(),
),
),
),
body: Container(
padding: EdgeInsets.only(bottom: 76.h),
child: TabBarView(
physics: b,
children: lables.map((e) {
// if (e == "关于回乡") {
// return BrandPage();
// } else if(e == "了解健康"){
// return ArticlePage(onChildScroll);
// } else
if (e == "视频") {
return CommunityCourse();
} else if (e == "广场") {
if (tuijian == null){
tuijian = CommunityChildPage(tuijianKey,"广场",onChildScroll,_toRelease);
}
return tuijian!;
} else if (e == "关注") {
if (guanzhu == null){
guanzhu = CommunityChildPage(guanzhuKey,"关注",onChildScroll,_toRelease);
}
return guanzhu!;
}
return tuijian!;
}).toList(),
controller: tabcontroller,
),
),
);
}
@override
bool get wantKeepAlive => true;
}