Skip to content

Commit

Permalink
DEV UPDATE:Add search function
Browse files Browse the repository at this point in the history
  • Loading branch information
misakajimmy committed Jan 30, 2023
1 parent 119c892 commit 1e9334c
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 43 deletions.
7 changes: 4 additions & 3 deletions lib/routes/picture/pictureDetail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class _PictureDetailState extends State<PictureDetail> {
@override
void initState() {
currentIndex = widget.index;
print(currentIndex);
super.initState();
}

Expand Down Expand Up @@ -107,9 +108,9 @@ class _PictureDetailState extends State<PictureDetail> {
onPageChanged: (int index) {
currentIndex = index;
},
// controller: PageController(
// initialPage: currentIndex,
// ),
controller: ExtendedPageController(
initialPage: widget.index,
),
scrollDirection: Axis.horizontal,
),
),
Expand Down
70 changes: 54 additions & 16 deletions lib/routes/picture/pictureList.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import 'dart:math';

import 'package:eoe_fans/common/Api.dart';
import 'package:eoe_fans/models/index.dart';
import 'package:eoe_fans/models/member.dart';
import 'package:eoe_fans/models/picturesRequest.dart';
import 'package:eoe_fans/routes/picture/pictureMemberFilter.dart';
import 'package:eoe_fans/routes/picture/pictureSwiper.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
Expand All @@ -23,6 +25,7 @@ class _PictureListState extends State<PictureList> {

int _page = 0;
bool _loading = false;
MemberEnum? _memberFilter;
List<Dynamic> dynamicList = [];

@override
Expand All @@ -36,9 +39,29 @@ class _PictureListState extends State<PictureList> {
_loading = true;
_page++;
});
PicturesTopic topic = PicturesTopic.all;
switch (_memberFilter) {
case MemberEnum.zao:
topic = PicturesTopic.zao;
break;
case MemberEnum.mi:
topic = PicturesTopic.mi;
break;
case MemberEnum.wan:
topic = PicturesTopic.wan;
break;
case MemberEnum.mo:
topic = PicturesTopic.mo;
break;
case MemberEnum.un:
topic = PicturesTopic.un;
break;
default:
topic = PicturesTopic.all;
}
PicturesRequest param = PicturesRequest()
..page = _page
..topic_id = PicturesTopic.all;
..topic_id = topic;
Pictures pictures = widget.pageType == PicturePageType.recommend
? await Api(context).picturesRecommend(param)
: await Api(context).picturesLatest(param);
Expand All @@ -55,10 +78,8 @@ class _PictureListState extends State<PictureList> {
}

_reloadPictures({int? page}) async {
setState(() {
dynamicList = [];
_page = page ?? 0;
});
dynamicList = [];
_page = page ?? 0;
await _getPictures();
}

Expand Down Expand Up @@ -101,16 +122,33 @@ class _PictureListState extends State<PictureList> {
onRefresh: _onRefresh,
onLoading: _onLoading,
child: ListView.builder(
itemBuilder: (c, i) => Card(
clipBehavior: Clip.antiAliasWithSaveLayer,
child: SizedBox(
width: double.infinity,
height: 480,
child: PictureSwiper(
dynamicId: dynamicList[i].dynamic_id.toString(),
images: dynamicList[i].pictures.map((e) => e.img_src).toList(),
),
),
itemBuilder: (c, i) => Container(
child: i == 0
? SizedBox(
width: double.infinity,
height: 84,
child: PictureMemberFilter(
filter: _memberFilter,
updateFilterMember: (MemberEnum? value) {
_memberFilter = value;
_reloadPictures();
},
),
)
: SizedBox(
width: double.infinity,
height: 480,
child: Card(
clipBehavior: Clip.antiAliasWithSaveLayer,
child: PictureSwiper(
dynamicId: dynamicList[i].dynamic_id.toString(),
images: dynamicList[i]
.pictures
.map((e) => e.img_src)
.toList(),
),
),
),

// child: Center(
// child: Image(
Expand All @@ -120,7 +158,7 @@ class _PictureListState extends State<PictureList> {
// ),
// ),
),
itemCount: dynamicList.length,
itemCount: dynamicList.length + 1,
),
);
}
Expand Down
85 changes: 85 additions & 0 deletions lib/routes/picture/pictureMemberFilter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import 'package:eoe_fans/common/Global.dart';
import 'package:eoe_fans/models/member.dart';
import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';

class PictureMemberFilter extends StatefulWidget {
const PictureMemberFilter(
{Key? key, required this.filter, required this.updateFilterMember})
: super(key: key);

final ValueChanged<MemberEnum?> updateFilterMember;
final MemberEnum? filter;

@override
State<PictureMemberFilter> createState() => _PictureMemberFilterState();
}

class _PictureMemberFilterState extends State<PictureMemberFilter> {
@override
void initState() {
print('reload');
// TODO: implement initState
super.initState();
}

@override
Widget build(BuildContext context) {
return Container(
child: GridView.count(
crossAxisCount: 5,
childAspectRatio: 1.0,
children: MemberEnum.values
.map(
(m) => GestureDetector(
onTap: () {
setState(() {
if (widget.filter == m) {
widget.updateFilterMember(null);
} else {
widget.updateFilterMember(m);
}
});
},
child: Card(
elevation: widget.filter == m ? 6 : 1,
shadowColor: widget.filter == m
? HexColor(Global.members[m]?.color ?? '#66CCFF')
: null,
child: Container(
padding: EdgeInsets.all(4),
child: Center(
child: Flex(
direction: Axis.vertical,
children: <Widget>[
Expanded(
flex: 3,
child: Image(
image: AssetImage(
'assets/${Global.themes.firstWhere((e) => e.id == m.name, orElse: () => Global.themes.first).filter}',
),
fit: BoxFit.contain,
// fit: BoxFit.fitWidth
),
),
Expanded(
flex: 1,
child: Text(
Global.members[m]?.firstName ?? m.name,
style: const TextStyle(
fontSize: 12,
color: Colors.black54,
),
),
),
],
),
),
),
),
),
)
.toList(),
));
}
}
14 changes: 7 additions & 7 deletions lib/routes/picture/picturePage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class _PicturePageState extends State<PicturePage> {
centerTitle: true,
title: Container(
width: 300,
padding: const EdgeInsets.only(left: 20, right: 20),
padding: const EdgeInsets.only(left: 20, right: 40),
child: const TabBar(
tabs: [
Tab(
Expand All @@ -50,12 +50,12 @@ class _PicturePageState extends State<PicturePage> {
),
),
actions: [
IconButton(
icon: const Icon(
Icons.search,
),
onPressed: () {},
),
// IconButton(
// icon: const Icon(
// Icons.search,
// ),
// onPressed: () {},
// ),
],
flexibleSpace: Container(
height: double.maxFinite,
Expand Down
75 changes: 58 additions & 17 deletions lib/routes/video/videoSearchPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class _VideoSearchPageState extends State<VideoSearchPage> {
String searchString = '';

int _page = 0;
VideosRequestOrder _order = VideosRequestOrder.score;
List<Video> videoList = [];

_searchVideo({required bool refresh}) async {
Expand All @@ -37,7 +38,7 @@ class _VideoSearchPageState extends State<VideoSearchPage> {
if (searchString != '') {
Videos videos = await Api(context).videos(
VideosRequest()
..order = VideosRequestOrder.score
..order = _order
..page = _page
..q = 'tag.' + searchString,
);
Expand Down Expand Up @@ -82,7 +83,7 @@ class _VideoSearchPageState extends State<VideoSearchPage> {
child: Container(
width: double.infinity,
padding: EdgeInsets.only(left: 16, right: 16, bottom: 2),
// width: 120,
height: 32,
child: TextField(
maxLines: 1,
decoration: InputDecoration(
Expand All @@ -93,7 +94,7 @@ class _VideoSearchPageState extends State<VideoSearchPage> {
searchString = v;
},
onSubmitted: (v) {
_searchVideo(refresh: true);
_refreshController.requestRefresh();
},
),
),
Expand All @@ -105,7 +106,7 @@ class _VideoSearchPageState extends State<VideoSearchPage> {
actions: [
TextButton(
onPressed: () {
_searchVideo(refresh: true);
_refreshController.requestRefresh();
},
child: Container(
// color: Colors.amber,
Expand Down Expand Up @@ -167,20 +168,60 @@ class _VideoSearchPageState extends State<VideoSearchPage> {
),
),
),
child: SizedBox(
width: double.infinity,
height: 120,
child: VideoSearchItem(video: videoList[i]),
),
// child: Center(
// child: Image(
// image: CachedNetworkImageProvider(dynamicList[i].pictures[0].img_src),
// fit: BoxFit.fitWidth,
// width: double.infinity,
// ),
// ),
child: i == 0
? Row(
children: [
TextButton(
onPressed: () {
_order = VideosRequestOrder.score;
_refreshController.requestRefresh();
},
child: Text(
'默认排序',
style: TextStyle(
color: _order == VideosRequestOrder.score
? Color.fromRGBO(251, 114, 153, 1)
: Colors.grey,
),
),
),
TextButton(
onPressed: () {
_order = VideosRequestOrder.pubdate;
_refreshController.requestRefresh();
},
child: Text(
'最新发布',
style: TextStyle(
color: _order == VideosRequestOrder.pubdate
? Color.fromRGBO(251, 114, 153, 1)
: Colors.grey,
),
),
),
TextButton(
onPressed: () {
_order = VideosRequestOrder.view;
_refreshController.requestRefresh();
},
child: Text(
'最多播放',
style: TextStyle(
color: _order == VideosRequestOrder.view
? Color.fromRGBO(251, 114, 153, 1)
: Colors.grey,
),
),
),
],
)
: SizedBox(
width: double.infinity,
height: 120,
child: VideoSearchItem(video: videoList[i]),
),
),
itemCount: videoList.length,
itemCount: videoList.length == 0 ? 0 : videoList.length + 1,
),
),
);
Expand Down

0 comments on commit 1e9334c

Please sign in to comment.