import 'dart:convert';
|
import 'dart:ui';
|
|
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
import '../../api/video_api.dart';
|
import '../../model/video/video_model.dart';
|
import '../../ui/widget/dialog.dart';
|
import '../../ui/widget/refresh_listview.dart';
|
import '../../ui/widget/search_widget.dart';
|
import '../../ui/widget/video_item.dart';
|
import '../../utils/video/search_record_util.dart';
|
import '../../ui/mine/settings.dart';
|
import '../../ui/mine/login.dart';
|
import '../../ui/mine/advice.dart';
|
import '../../api/http.dart';
|
import '../../model/user/user_info.dart';
|
import '../../ui/common/browser.dart';
|
import '../../utils/config_util.dart';
|
import '../../utils/pageutils.dart';
|
import '../../utils/string_util.dart';
|
import '../../utils/ui_constant.dart';
|
import '../../utils/ui_utils.dart';
|
import '../../utils/user_util.dart';
|
|
class SearchResultPage extends StatefulWidget {
|
SearchResultPage({Key? key, required this.title}) : super(key: key);
|
final String title;
|
|
@override
|
_SearchResultPageState createState() => _SearchResultPageState();
|
}
|
|
class _SearchResultPageState extends State<SearchResultPage>
|
with TickerProviderStateMixin {
|
final SugguestSearchController _sugguestSearchController =
|
SugguestSearchController();
|
final SearchController _searchController=SearchController();
|
final MyRefreshController _refreshController = MyRefreshController();
|
bool showClose = false;
|
int page = 1;
|
bool hasMore = true;
|
int? type;
|
List<VideoType> typeList = [];
|
String? kw;
|
List<VideoInfoModel> videoList = [];
|
|
TabController? _tabController;
|
|
VoidCallback? listener;
|
|
@override
|
void initState() {
|
super.initState();
|
kw = widget.title;
|
|
listener = () {
|
if(type!=null){
|
if(type==typeList[_tabController!.index].id){
|
return;
|
}
|
}
|
setState(() {
|
type = typeList[_tabController!.index].id;
|
});
|
page = 1;
|
search(kw!, page);
|
};
|
|
_tabController = TabController(length: typeList.length, vsync: this);
|
}
|
|
void initTab() {
|
if (_tabController != null) {
|
_tabController!.removeListener(listener!);
|
}
|
setState(() {
|
_tabController = TabController(length: typeList.length, vsync: this);
|
});
|
_tabController!.addListener(listener!);
|
}
|
|
void search(String content, int _page) async {
|
setState(() {
|
kw = content;
|
});
|
|
SearchRecordUtil.addRecord(content);
|
page = _page;
|
if (page == 1) {
|
setState(() {
|
videoList = [];
|
});
|
}
|
Map<String, dynamic>? result =
|
await SearchApiUtil.search(context, content, _page, type);
|
//请求失败了
|
if (result == null) {
|
if (page > 1) {
|
page = page - 1;
|
}
|
return;
|
}
|
|
if (result["IsPost"] == "true") {
|
if (type == null && page == 1) {
|
List<dynamic> list = result["Data"]["typeList"];
|
List<VideoType> tempVideoTypeTypeList = [];
|
list.forEach((element) {
|
tempVideoTypeTypeList.add(VideoType.fromJson(element));
|
});
|
setState(() {
|
typeList = tempVideoTypeTypeList;
|
});
|
|
initTab();
|
}
|
|
List<dynamic> list = result["Data"]["data"];
|
List<VideoInfoModel> tempList = [];
|
for (var element in list) {
|
VideoInfoModel videoInfo = VideoInfoModel.fromJson(element);
|
//处理中间剧集
|
List<VideoDetailInfo> detailList = videoInfo.videoDetailList!;
|
if (detailList.length > 5) {
|
detailList = [
|
detailList[0],
|
detailList[1],
|
VideoDetailInfo(tag: "..."),
|
detailList[detailList.length - 2],
|
detailList[detailList.length - 1]
|
];
|
}
|
videoInfo.videoDetailList = detailList;
|
tempList.add(videoInfo);
|
}
|
hasMore = tempList.isNotEmpty;
|
setState(() {
|
if (_page == 1) {
|
videoList = tempList;
|
} else {
|
if (tempList.isNotEmpty) {
|
videoList.addAll(tempList);
|
}
|
}
|
});
|
|
if (_page == 1) {
|
hasMore = true;
|
}
|
|
_refreshController.refreshCompleted();
|
|
if (!hasMore) {
|
_refreshController.loadNoData();
|
} else {
|
_refreshController.loadComplete();
|
}
|
}
|
}
|
|
void getSuggestSearch(String key) async {
|
Map<String, dynamic>? result =
|
await SearchApiUtil.getSuggestSearch(context, key);
|
if (result == null) {
|
return;
|
}
|
if (result["IsPost"] == "true") {
|
List<dynamic> list = result["Data"]["data"];
|
|
List<String> suggestList = [];
|
list.forEach((element) {
|
suggestList.add(element);
|
});
|
|
_sugguestSearchController.setData!(suggestList);
|
if (suggestList.isNotEmpty) {
|
_sugguestSearchController.setShow!(true);
|
} else {
|
_sugguestSearchController.setShow!(false);
|
}
|
} else {
|
_sugguestSearchController.setData!([]);
|
_sugguestSearchController.setShow!(false);
|
}
|
}
|
|
@override
|
Widget build(BuildContext context) {
|
return Scaffold(
|
backgroundColor: Colors.white,
|
body: Stack(children: [
|
Column(
|
children: [
|
Container(
|
height: MediaQuery.of(context).viewPadding.top,
|
),
|
Container(
|
height: 5,
|
),
|
//搜索栏
|
SearchBar(
|
text: kw,
|
onChange: (content) {
|
if (content.isEmpty) {
|
_sugguestSearchController.setData!([]);
|
_sugguestSearchController.setShow!(false);
|
} else {
|
getSuggestSearch(content);
|
}
|
},
|
onSubmit: (content) {
|
type = null;
|
search(content, 1);
|
},
|
searchController: _searchController,
|
),
|
Container(
|
height: 5,
|
),
|
|
///内容
|
///
|
Container(
|
alignment: Alignment.centerLeft,
|
child: TabBar(
|
padding: EdgeInsets.only(top: 5, bottom: 15, left: 2),
|
isScrollable: true,
|
indicatorSize: TabBarIndicatorSize.label,
|
labelColor: ColorConstant.theme,
|
labelStyle: const TextStyle(fontSize: 16),
|
labelPadding: EdgeInsets.only(left: 8, right: 8),
|
unselectedLabelColor: const Color(0xFF666666),
|
indicatorColor: ColorConstant.theme,
|
tabs: typeList.map((e) => Text(e.name!)).toList(),
|
controller: _tabController,
|
)),
|
|
Expanded(
|
child: RefreshListView(
|
content: ListView.builder(
|
itemBuilder: (BuildContext context, int index) {
|
VideoInfoModel video = videoList[index];
|
if (video.showType == 1) {
|
return VideoListUIUtil.getSearchVideoAlbum(
|
context, video);
|
} else {
|
return VideoListUIUtil.getSearchVideoCommon(
|
context, video);
|
}
|
},
|
padding: const EdgeInsets.only(left: 0, right: 0, top: 0),
|
itemCount: videoList.length,
|
),
|
refreshController: _refreshController,
|
refresh: () {
|
page = 1;
|
search(kw!, page);
|
},
|
loadMore: () {
|
search(kw!, page + 1);
|
},
|
),
|
)
|
],
|
),
|
SugguestSearchView(
|
contentList: [],
|
sugguestSearchController: _sugguestSearchController,
|
onCancel: (value) {
|
_sugguestSearchController.setShow!(false);
|
},
|
onItemClick: (value) {
|
FocusScope.of(context).requestFocus(FocusNode());
|
_searchController.setData!(value);
|
_sugguestSearchController.setShow!(false);
|
type = null;
|
search(value, 1);
|
},
|
)
|
]));
|
}
|
|
@override
|
bool get wantKeepAlive => true;
|
}
|