feat: 搜索页的数据,缺省页

This commit is contained in:
chengsiwen committed 2026-07-06 20:56:12 +08:00
1 parent 9b0fe51fa4
commit b5bce6edcf
18 files changed
+1101 -171

No files matched your search

+9 -3
View File
@@ -70,10 +70,12 @@ class _RootPageState extends State<FirstPage> {
AppNav.to(SearchPage());
},
),
Expanded(
_homeDatas.isEmpty ? SizedBox() : Expanded(
child: CustomScrollView(
slivers: [
SliverToBoxAdapter(child: HomeFirstView()),
SliverToBoxAdapter(child: HomeFirstView(
categories: _categories,
)),
SliverPadding(
padding: const EdgeInsets.only(left: 16, right: 10, top: 16, bottom: 8),
sliver: SliverToBoxAdapter(
@@ -83,7 +85,11 @@ class _RootPageState extends State<FirstPage> {
SliverPadding(
padding: const EdgeInsetsGeometry.symmetric(horizontal: 16),
sliver: SliverToBoxAdapter(
child: HomeRankWidget(),
child: HomeRankWidget(
dramaRanks: _homeDatas
.firstWhere((element) => element.moduleKey == 'week_ranking')
.dataList,
),
),
),
const SliverToBoxAdapter(child: HomeRemainingSections()),
+115 -9
View File
@@ -1,9 +1,18 @@
import 'package:flutter/material.dart';
import 'package:novyronst/common/api/video_request.dart';
import 'package:novyronst/common/const/const_color.dart';
import 'package:novyronst/common/const/const_string.dart';
import 'package:novyronst/common/help/app_nav.dart';
import 'package:novyronst/common/help/help_image.dart';
import 'package:novyronst/common/help/help_time.dart';
import 'package:novyronst/common/model/ny_drama_model.dart';
import 'package:novyronst/pages/first/pages/search_result_page.dart';
import 'package:novyronst/pages/first/widgets/recent_history_view.dart';
import 'package:novyronst/pages/first/widgets/search_view.dart';
import 'package:novyronst/pages/widgets/ny_tag_widget.dart';
import 'package:novyronst/tools/util/search_history_util.dart';
import 'package:novyronst/tools/widgets/novy_app_bar.dart';
import 'package:novyronst/tools/widgets/novy_com_widget.dart';
class SearchPage extends StatefulWidget {
const SearchPage({super.key});
@@ -18,6 +27,7 @@ class _SearchPageState extends State<SearchPage> {
List<String> _history = [];
final _searchController = TextEditingController();
List<NyDramaModel> _trendingSearches = [];
Future<void> _loadSearchHistory() async {
final list = await SearchHistoryUtil.getSearchList();
@@ -27,13 +37,10 @@ class _SearchPageState extends State<SearchPage> {
});
}
Future<void> _onGoSearch(String keyword,) async {
Future<void> _onGoSearch(String keyword) async {
await SearchHistoryUtil.addSearch(keyword);
await _loadSearchHistory();
// HelpNav.to(ResultPage(
// keyword: keyword,
// ));
// 发起 搜索
AppNav.to(SearchResultPage(searchText: keyword));
}
@@ -41,25 +48,40 @@ class _SearchPageState extends State<SearchPage> {
return _history.isEmpty ? SizedBox() : RecentHistoryView(
searchHistory: _history,
onTapClear: () {
// HelpNav.showDialog(ComConfirmWidget(
// title: 'Clear Search History?',
// ));
_history.clear();
setState(() {});
},
onTapHistory: (value) {
print('object: $value');
// HelpNav.to(ResultPage(keyword: value));
AppNav.to(SearchResultPage(searchText: value));
},
);
}
void _getTrendingSearches() {
VideoRequest.getSearchTrending().then((value) {
setState(() {
_trendingSearches = value;
});
});
}
@override
void initState() {
super.initState();
_getTrendingSearches();
_loadSearchHistory();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: ConstColor.withValue('#110D08'),
appBar: NovyAppBar(
titleWidget: SeSearchView(
controller: _searchController,
onClickSearch: (keyword) => _onGoSearch(keyword),
),
),
@@ -71,6 +93,90 @@ class _SearchPageState extends State<SearchPage> {
child: _buildHistoryView(),
)
),
const SliverToBoxAdapter(child: SizedBox(height: 16,)),
SliverList.separated(
itemBuilder: (context, index) {
return TrendingSearchItem(model: _trendingSearches[index]);
},
itemCount: _trendingSearches.length,
separatorBuilder: (context, index) => const SizedBox(height: 12),
)
],
),
);
}
}
class TrendingSearchItem extends StatelessWidget {
const TrendingSearchItem({super.key,
required this.model,
this.toCate = true,
});
final NyDramaModel model;
final bool toCate;
@override
Widget build(BuildContext context) {
Widget _tagWidget = SizedBox();
String _tag = '';
if (toCate) {
if (model.category!.isNotEmpty) {
_tag = '${model.category!.first}';
}
_tagWidget = NyTagWidget(
text: _tag,
bgColor: Colors.white.withAlpha(127),
textColor: Colors.white.withAlpha(127),
);
} else {
if (model.categoryList!.isNotEmpty) {
_tag = model.categoryList!.first.name;
}
_tagWidget = NyTagWidget(
text: _tag,
bgColor: Colors.white.withAlpha(127),
textColor: Colors.white.withAlpha(127),
);
}
return Container(
height: 96,
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
children: [
HelpImage.network(model.imageUrl, width: 72, height: 96),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
NovyText(model.name, fontSize: 14,
fontFamily: ConstFont.montBold,
),
SizedBox(
height: 36,
child: NovyText(model.description, fontSize: 11,
color: Colors.white.withAlpha(127),
maxLines: 2,
),
),
const SizedBox(height: 5),
Row(
children: [
_tagWidget,
if (_tag!='') const SizedBox(width: 12),
NyHotWidget(text: HelpTime.formatNum(model.watchTotal),
textColor: ConstColor.btGreen,
)
],
)
],
),
)
],
),
);
@@ -0,0 +1,83 @@
import 'package:flutter/material.dart';
import 'package:novyronst/common/api/video_request.dart';
import 'package:novyronst/common/model/ny_drama_model.dart';
import 'package:novyronst/pages/first/pages/search_page.dart';
import 'package:novyronst/pages/widgets/ny_empty_view.dart';
import 'package:novyronst/tools/util/search_history_util.dart';
import 'package:novyronst/tools/widgets/app_toast_util.dart';
import '../../../common/const/const_color.dart';
import '../../../tools/widgets/novy_app_bar.dart';
import '../widgets/search_view.dart';
class SearchResultPage extends StatefulWidget {
const SearchResultPage({super.key,
required this.searchText,
});
final String searchText;
@override
State<StatefulWidget> createState() {
return _SearchResultPageState();
}
}
class _SearchResultPageState extends State<SearchResultPage> {
final _searchController = TextEditingController();
final _searchFocus = FocusNode();
List<NyDramaModel> _searchResult = [];
bool _isLoading = false;
@override
void initState() {
super.initState();
_searchController.text = widget.searchText;
_searchList();
}
void _searchList() async {
String keyword = _searchController.text;
if (keyword.trim().isEmpty) {
_searchFocus.requestFocus();
return;
}
_isLoading = true;
AppToastUtil.showLoading();
// await SearchHistoryUtil.addSearch(keyword);
VideoRequest.search(keyword: keyword).then((valuer) {
_isLoading = false;
AppToastUtil.dismiss();
setState(() {
_searchResult = valuer;
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: ConstColor.withValue('#110D08'),
appBar: NovyAppBar(
titleWidget: SeSearchView(
controller: _searchController,
focusNode: _searchFocus,
onClickSearch: (keyword) => _searchList(),
),
),
body: _searchResult.isEmpty && !_isLoading ? NyEmptyView() : ListView.separated(
itemBuilder: (context, index) {
return TrendingSearchItem(
model: _searchResult[index],
toCate: false,
);
},
separatorBuilder: (context, index) => SizedBox(height: 12),
itemCount: _searchResult.length
)
);
}
}
+9 -3
View File
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:novyronst/common/model/ny_category_model.dart';
import 'package:novyronst/pages/widgets/cut_corner_clipper.dart';
import 'package:novyronst/pages/widgets/ny_progress_widget.dart';
import 'package:novyronst/pages/widgets/ny_tag_widget.dart';
@@ -10,7 +11,11 @@ import 'package:novyronst/tools/widgets/novy_img_bg.dart';
class HomeFirstView extends StatefulWidget {
const HomeFirstView({super.key});
const HomeFirstView({super.key,
required this.categories,
});
final List<NyCategoryModel> categories;
@override
State<StatefulWidget> createState() {
@@ -46,14 +51,15 @@ class _HomeFirstViewState extends State<HomeFirstView> {
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: List.generate(3, (index) {
children: List.generate(widget.categories.length, (index) {
final _item = widget.categories[index];
return Container(
margin: const EdgeInsets.only(right: 8),
child: NovyImgBg(imgBg: ConstImage.cateBg,
height: 52,
child: Stack(
children:[
NovyText('ClassPp', color: ConstColor.btGreen,
NovyText(_item.name, color: ConstColor.btGreen,
fontSize: 21,
textAlign: TextAlign.center,
fontFamily: ConstFont.montBlack,
+111 -24
View File
@@ -1,6 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:novyronst/common/const/const_color.dart';
import 'package:novyronst/common/const/const_string.dart';
import 'package:novyronst/common/help/help_image.dart';
import 'package:novyronst/common/model/ny_drama_model.dart';
import 'package:novyronst/tools/widgets/novy_com_widget.dart';
import '../../../tools/util/app_screen.dart';
@@ -10,7 +13,12 @@ import '../../widgets/ny_tag_widget.dart';
class HomeRankWidget extends StatelessWidget {
const HomeRankWidget({super.key});
const HomeRankWidget({
super.key,
required this.dramaRanks,
});
final List<NyDramaModel> dramaRanks;
@override
Widget build(BuildContext context) {
@@ -20,7 +28,7 @@ class HomeRankWidget extends StatelessWidget {
cutSize: 40,
child: Padding(
padding: const EdgeInsets.all(8),
child: Column(
child: dramaRanks.isEmpty ? SizedBox(height: 20,) : Column(
children: [
_buildRankList(),
const SizedBox(height: 5),
@@ -37,6 +45,7 @@ class HomeRankWidget extends StatelessWidget {
}
Row _buildRankList() {
return Row(
children: [
_firstVideoView(),
@@ -47,38 +56,116 @@ class HomeRankWidget extends StatelessWidget {
}
Widget _firstVideoView() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 160.w, height: 240.w,
decoration: BoxDecoration(
color: Colors.red,
)
),
const SizedBox(height: 10),
NovyText('Star of the ocean', fontSize: 15,
color: Colors.black,
fontFamily: ConstFont.montMedium,
),
const SizedBox(height: 5),
NyTagWidget(text: 'Safiray'),
const SizedBox(height: 8),
],
NyDramaModel _item = dramaRanks.first;
String _tag = "Safiray";
if (_item.categoryList!=null && _item.categoryList!.isNotEmpty) {
_tag = _item.categoryList!.first.name;
}
return SizedBox(
width: 160.w,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(
children: [
SizedBox(
width: 160.w, height: 240.w,
child: HelpImage.network(_item.imageUrl, fit: BoxFit.cover),
),
Positioned(
top: -10, left: 1,
child: _colorsText(1),
)
],
),
const SizedBox(height: 10),
NovyText(_item.name, fontSize: 15,
color: Colors.black,
fontFamily: ConstFont.montMedium,
),
const SizedBox(height: 5),
Row(
children: [
NyTagWidget(text: _tag),
],
),
const SizedBox(height: 8),
],
),
);
}
Widget _otherVideoView() {
int _count = dramaRanks.length - 1;
if (_count > 3) _count = 3;
return Column(
children: List.generate(3, (index) {
children: List.generate(_count, (index) {
NyDramaModel _item = dramaRanks[index + 1];
String _tag = "";
if (_item.categoryList!=null && _item.categoryList!.isNotEmpty) {
_tag = _item.categoryList!.first.name;
}
return Container(
margin: const EdgeInsets.only(bottom: 8),
width: 160.w, height: 93.w,
decoration: BoxDecoration(
color: Colors.grey,
)
child: Row(
children: [
HelpImage.network(_item.imageUrl, width: 62.w, height: 93.w),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_colorsText(index + 2),
const SizedBox(height: 8),
NovyText(_item.name, fontSize: 13,
color: Colors.black,
),
const SizedBox(height: 5),
_tag.isNotEmpty ? NyTagWidget(text: _tag) : SizedBox()
],
),
)
],
),
);
})
);
}
_colorsText(int index) {
if (index == 4) {
return Text(
'$index',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.grey.withAlpha(127),
fontStyle: FontStyle.italic,
),
);
}
return ShaderMask(
shaderCallback: (Rect bounds) {
return LinearGradient(
colors: [
ConstColor.withValue('#3ED71F'),
ConstColor.withValue('#FFFF65'),
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
).createShader(bounds);
},
child: Text(
'$index',
style: TextStyle(
fontSize: index==1 ? 40: 20,
fontWeight: FontWeight.bold,
color: Colors.white,
fontStyle: FontStyle.italic,
),
),
);
}
}
@@ -8,28 +8,6 @@ import 'package:novyronst/tools/widgets/novy_com_widget.dart';
class HomeRemainingSections extends StatelessWidget {
const HomeRemainingSections({super.key});
static const List<_DramaItem> _rankingItems = [
_DramaItem(
title: 'Star Of The Ocean',
category: 'Period Drama',
palette: [Color(0xFF6E4968), Color(0xFFE5A3B8)],
),
_DramaItem(
title: 'Not Your Bride',
category: 'Period Drama',
palette: [Color(0xFF262431), Color(0xFFE0A15F)],
),
_DramaItem(
title: 'Not Your Bride',
category: 'Period Drama',
palette: [Color(0xFF261B16), Color(0xFFD9C2A2)],
),
_DramaItem(
title: 'Not Your Bride',
category: 'Period Drama',
palette: [Color(0xFF223E36), Color(0xFFFFC568)],
),
];
static const _ActorInfo _actor = _ActorInfo(
name: 'Cheng Zi',
@@ -84,8 +62,7 @@ class HomeRemainingSections extends StatelessWidget {
padding: const EdgeInsets.fromLTRB(16, 10, 16, 92),
child: Column(
children: [
const _RankingSection(items: _rankingItems),
const SizedBox(height: 18),
const SizedBox(height: 10),
const _ActorSection(actor: _actor, items: _seriesItems),
const SizedBox(height: 18),
..._categoryTitles.map((title) {
@@ -100,51 +77,6 @@ class HomeRemainingSections extends StatelessWidget {
}
}
class _RankingSection extends StatelessWidget {
const _RankingSection({required this.items});
final List<_DramaItem> items;
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.black, width: 2),
),
child: Column(
children: [
SizedBox(
height: 230,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(flex: 6, child: _TopRankingPoster(item: items.first)),
const SizedBox(width: 8),
Expanded(
flex: 5,
child: Column(
children: List.generate(3, (index) {
return Expanded(
child: _RankingListItem(
rank: index + 2,
item: items[index + 1],
),
);
}),
),
),
],
),
),
const SizedBox(height: 5),
const _GreenActionButton(text: 'View more rankings'),
],
),
);
}
}
class _TopRankingPoster extends StatelessWidget {
const _TopRankingPoster({required this.item});
+16 -7
View File
@@ -94,9 +94,13 @@ class _SearchViewState extends State<HomeSearchView> {
class SeSearchView extends StatefulWidget {
const SeSearchView({super.key,
this.onClickSearch,
required this.controller,
this.focusNode,
});
final Function(String)? onClickSearch;
final TextEditingController controller;
final FocusNode? focusNode;
@override
State<StatefulWidget> createState() {
@@ -106,7 +110,12 @@ class SeSearchView extends StatefulWidget {
class _SeSearchViewState extends State<SeSearchView> {
final _searchController = TextEditingController();
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
@@ -123,8 +132,8 @@ class _SeSearchViewState extends State<SeSearchView> {
Icon(Icons.search, color: Colors.white, size: 24),
Expanded(child: CupertinoTextField(
controller: _searchController,
// focusNode: widget.focusNode,
controller: widget.controller,
focusNode: widget.focusNode,
decoration: BoxDecoration(),
placeholder: 'What are...... ',
placeholderStyle: TextStyle(
@@ -137,8 +146,8 @@ class _SeSearchViewState extends State<SeSearchView> {
),
textInputAction: TextInputAction.search,
onEditingComplete: () {
if (_searchController.text.trim().isNotEmpty) {
widget.onClickSearch?.call(_searchController.text);
if (widget.controller.text.trim().isNotEmpty) {
widget.onClickSearch?.call(widget.controller.text);
}
},
),),
@@ -146,8 +155,8 @@ class _SeSearchViewState extends State<SeSearchView> {
HelpImage.asset(ConstImage.homeSearch,
width: 78, height: 36, fit: BoxFit.fill
).addInkWell(onTap: () {
if (_searchController.text.trim().isNotEmpty) {
widget.onClickSearch?.call(_searchController.text);
if (widget.controller.text.trim().isNotEmpty) {
widget.onClickSearch?.call(widget.controller.text);
}
})