181 lines
5.3 KiB
Dart
181 lines
5.3 KiB
Dart
import 'dart:async';
|
||
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||
import 'package:talk/tools/find/find_model.dart';
|
||
import 'package:talk/tools/find/recommend_page.dart';
|
||
|
||
import '../../beans/find_type_bean.dart';
|
||
import 'multiplex_page.dart';
|
||
|
||
///发现
|
||
class FindPage extends StatefulWidget {
|
||
const FindPage({super.key});
|
||
|
||
@override
|
||
State<FindPage> createState() => _FindPageState();
|
||
}
|
||
|
||
class _FindPageState extends State<FindPage> {
|
||
late StreamSubscription subscription;
|
||
final PageController _pageController = PageController();
|
||
int currentIndex = 0;
|
||
|
||
final FindModel _viewmodel = FindModel();
|
||
|
||
List<FindTypeBean> findList = [];
|
||
|
||
@override
|
||
void initState() {
|
||
// TODO: implement initState
|
||
super.initState();
|
||
|
||
subscription = _viewmodel.streamController.stream.listen((newData) {
|
||
String code = newData['code'];
|
||
if (code.isNotEmpty) {
|
||
switch (code) {
|
||
case "getChatInfo":
|
||
findList = newData['data'];
|
||
break;
|
||
|
||
default:
|
||
EasyLoading.showToast(newData['data']);
|
||
break;
|
||
}
|
||
setState(() {});
|
||
EasyLoading.dismiss();
|
||
}
|
||
});
|
||
|
||
EasyLoading.show(status: "loading...");
|
||
_viewmodel.getCategoryList();
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
// TODO: implement dispose
|
||
_pageController.dispose();
|
||
subscription.cancel();
|
||
super.dispose();
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
backgroundColor: Color(0xFF121213),
|
||
body: Stack(
|
||
children: [
|
||
PageView.builder(
|
||
controller: _pageController,
|
||
itemCount: 10, // 假设有5个页面,其中第一个是固定的
|
||
itemBuilder: (context, index) {
|
||
if (index == 0) {
|
||
// 第一个页面固定
|
||
return RecommendPage();
|
||
} else {
|
||
// 其他页面动态生成
|
||
return MultiplexPage(
|
||
id: findList[index].id.toString(),
|
||
);
|
||
}
|
||
},
|
||
physics: NeverScrollableScrollPhysics(),
|
||
),
|
||
|
||
///title
|
||
Container(
|
||
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top + 9, left: 16, right: 16),
|
||
// width: MediaQuery.of(context).size.width,
|
||
color: Color(0x66121213),
|
||
child: Row(
|
||
crossAxisAlignment: CrossAxisAlignment.center,
|
||
children: [
|
||
///展开分类
|
||
// Image(
|
||
// width: 16,
|
||
// height: 15,
|
||
// image: AssetImage('assets/images/ic_type.png'),
|
||
// ),
|
||
|
||
///tab
|
||
Expanded(
|
||
child: SizedBox(
|
||
height: 30,
|
||
child: ListView.builder(
|
||
itemCount: findList.length,
|
||
itemBuilder: (BuildContext context, int index) {
|
||
return _item(index, findList[index]);
|
||
},
|
||
scrollDirection: Axis.horizontal,
|
||
),
|
||
),
|
||
),
|
||
|
||
///搜索
|
||
// Container(
|
||
// width: 72,
|
||
// height: 27,
|
||
// decoration: BoxDecoration(
|
||
// color: Color(0x1AFFFFFF),
|
||
// borderRadius: BorderRadius.all(Radius.circular(14)),
|
||
// border: Border.all(color: Color(0xFF777777), width: 0.33)),
|
||
// child: Row(
|
||
// mainAxisAlignment: MainAxisAlignment.center,
|
||
// children: [
|
||
// Text(
|
||
// '搜索',
|
||
// style: TextStyle(fontSize: 12, color: Color(0xFFAEAEAE)),
|
||
// ),
|
||
// Container(
|
||
// margin: EdgeInsets.only(left: 5),
|
||
// child: Image(
|
||
// width: 16,
|
||
// image: AssetImage('assets/images/ic_search2.png'),
|
||
// ),
|
||
// )
|
||
// ],
|
||
// ),
|
||
// ),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
_item(index, FindTypeBean data) {
|
||
return Container(
|
||
margin: EdgeInsets.only(left: 5, right: 12),
|
||
child: Column(
|
||
children: [
|
||
GestureDetector(
|
||
onTap: () {
|
||
currentIndex = index;
|
||
_pageController.animateToPage(
|
||
index,
|
||
duration: const Duration(milliseconds: 500), // 动画时长
|
||
curve: Curves.ease, // 动画曲线
|
||
);
|
||
setState(() {});
|
||
},
|
||
child: Text(
|
||
"${data.name}",
|
||
style: TextStyle(color: Color(currentIndex == index ? 0xFFFF9000 : 0xFF8D8D8D)),
|
||
),
|
||
),
|
||
currentIndex == index
|
||
? Container(
|
||
child: Image(
|
||
width: 20,
|
||
height: 5,
|
||
image: AssetImage('assets/images/ic_note.png'),
|
||
),
|
||
)
|
||
: Container(),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|