-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8cb9674
commit 119c892
Showing
7 changed files
with
507 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| import 'package:cached_network_image/cached_network_image.dart'; | ||
| import 'package:eoe_fans/common/Time.dart'; | ||
| import 'package:eoe_fans/models/video.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:url_launcher/url_launcher.dart'; | ||
|
|
||
| class VideoSearchItem extends StatelessWidget { | ||
| const VideoSearchItem({Key? key, required this.video}) : super(key: key); | ||
| final Video video; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return GestureDetector( | ||
| onTap: () async { | ||
| var _url = 'bilibili://video/' + video.bvid; | ||
| if (!await launchUrl(Uri.parse(_url))) { | ||
| throw 'Could not launch $_url'; | ||
| } | ||
| }, | ||
| child: Container( | ||
| padding: EdgeInsets.all(10), | ||
| child: Flex( | ||
| direction: Axis.horizontal, | ||
| children: [ | ||
| Expanded( | ||
| flex: 4, | ||
| child: Container( | ||
| clipBehavior: Clip.antiAliasWithSaveLayer, | ||
| decoration: BoxDecoration( | ||
| //设置四周圆角 角度 这里的角度应该为 父Container height 的一半 | ||
| borderRadius: const BorderRadius.all(Radius.circular(4.0)), | ||
| ), | ||
| child: Stack( | ||
| children: [ | ||
| SizedBox( | ||
| width: double.infinity, | ||
| height: double.maxFinite, | ||
| child: Image( | ||
| image: CachedNetworkImageProvider(video.pic), | ||
| fit: BoxFit.cover, | ||
| ), | ||
| ), | ||
| Positioned( | ||
| bottom: 4, | ||
| right: 4, | ||
| child: Container( | ||
| padding: const EdgeInsets.all(2), | ||
| decoration: BoxDecoration( | ||
| borderRadius: const BorderRadius.all(Radius.circular(4.0)), | ||
| color: Color.fromRGBO(0, 0, 0, .3), | ||
| ), | ||
| child: Text( | ||
| SecondToDate(int.parse(video.duration)), | ||
| textAlign: TextAlign.center, | ||
| style: const TextStyle( | ||
| fontSize: 10, | ||
| color: Colors.white, | ||
| ), | ||
| ), | ||
| ), | ||
| ) | ||
| ], | ||
| ), | ||
| ), | ||
| ), | ||
| Expanded( | ||
| flex: 5, | ||
| child: Container( | ||
| margin: EdgeInsets.only(left: 8), | ||
| child: Flex( | ||
| direction: Axis.vertical, | ||
| mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
| children: [ | ||
| SizedBox( | ||
| width: double.infinity, | ||
| child: Text( | ||
| video.title, | ||
| textAlign: TextAlign.left, | ||
| style: const TextStyle( | ||
| fontSize: 14, | ||
| ), | ||
| maxLines: 2, | ||
| ), | ||
| ), | ||
| Column( | ||
| children: [ | ||
| Row( | ||
| children: [ | ||
| Container( | ||
| padding: const EdgeInsets.only( | ||
| left: 1, right: 1, top: 1, bottom: 0), | ||
| decoration: BoxDecoration( | ||
| //设置四周圆角 角度 这里的角度应该为 父Container height 的一半 | ||
| borderRadius: const BorderRadius.all( | ||
| Radius.circular(4.0)), | ||
| //设置四周边框 | ||
| border: | ||
| Border.all(width: 1, color: Colors.grey), | ||
| ), | ||
| child: Text( | ||
| 'UP', | ||
| style: const TextStyle( | ||
| fontSize: 8, color: Colors.grey), | ||
| textAlign: TextAlign.center, | ||
| ), | ||
| ), | ||
| Container( | ||
| padding: const EdgeInsets.only(left: 2.0), | ||
| child: Text( | ||
| video.name, | ||
| textAlign: TextAlign.center, | ||
| style: const TextStyle( | ||
| fontSize: 10, | ||
| color: Colors.grey, | ||
| ), | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| Row( | ||
| children: [ | ||
| const Icon( | ||
| Icons.ondemand_video_sharp, | ||
| size: 12, | ||
| color: Colors.grey, | ||
| ), | ||
| Container( | ||
| padding: const EdgeInsets.only(left: 2.0), | ||
| child: Text( | ||
| video.view < 10000 | ||
| ? video.view.toString() | ||
| : '${(video.view / 10000).toStringAsFixed(1)}万', | ||
| textAlign: TextAlign.center, | ||
| style: const TextStyle( | ||
| fontSize: 12, color: Colors.grey), | ||
| ), | ||
| ), | ||
| Container( | ||
| padding: const EdgeInsets.only(left: 4.0), | ||
| child: const Icon( | ||
| Icons.list_alt, | ||
| size: 12, | ||
| color: Colors.grey, | ||
| ), | ||
| ), | ||
| Container( | ||
| padding: const EdgeInsets.only(left: 2.0), | ||
| child: Text( | ||
| video.danmaku < 10000 | ||
| ? video.danmaku.toString() + '条' | ||
| : '${(video.danmaku / 10000).toStringAsFixed(2)}万', | ||
| style: const TextStyle( | ||
| fontSize: 12, color: Colors.grey), | ||
| ), | ||
| ) | ||
| ], | ||
| ), | ||
| ], | ||
| ) | ||
| ], | ||
| ), | ||
| ), | ||
| ) | ||
| ], | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| import 'dart:ffi'; | ||
|
|
||
| import 'package:eoe_fans/common/Api.dart'; | ||
| import 'package:eoe_fans/models/video.dart'; | ||
| import 'package:eoe_fans/models/videos.dart'; | ||
| import 'package:eoe_fans/models/videosRequest.dart'; | ||
| import 'package:eoe_fans/routes/video/videoSearchItem.dart'; | ||
| import 'package:eoe_fans/states/ProfileChangeNotifier.dart'; | ||
| import 'package:flutter/cupertino.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter/services.dart'; | ||
| import 'package:fluttertoast/fluttertoast.dart'; | ||
| import 'package:provider/provider.dart'; | ||
| import 'package:pull_to_refresh/pull_to_refresh.dart'; | ||
|
|
||
| class VideoSearchPage extends StatefulWidget { | ||
| const VideoSearchPage({Key? key}) : super(key: key); | ||
|
|
||
| @override | ||
| State<VideoSearchPage> createState() => _VideoSearchPageState(); | ||
| } | ||
|
|
||
| class _VideoSearchPageState extends State<VideoSearchPage> { | ||
| RefreshController _refreshController = | ||
| RefreshController(initialRefresh: false); | ||
| String searchString = ''; | ||
|
|
||
| int _page = 0; | ||
| List<Video> videoList = []; | ||
|
|
||
| _searchVideo({required bool refresh}) async { | ||
| if (refresh) { | ||
| _page = 0; | ||
| videoList = []; | ||
| } | ||
| _page++; | ||
| if (searchString != '') { | ||
| Videos videos = await Api(context).videos( | ||
| VideosRequest() | ||
| ..order = VideosRequestOrder.score | ||
| ..page = _page | ||
| ..q = 'tag.' + searchString, | ||
| ); | ||
| if (videos.numResults == videoList.length) { | ||
| Fluttertoast.showToast( | ||
| msg: "到头了喵", | ||
| toastLength: Toast.LENGTH_SHORT, | ||
| gravity: ToastGravity.CENTER, | ||
| timeInSecForIosWeb: 1, | ||
| backgroundColor: Color.fromRGBO(255, 255, 255, 0.3), | ||
| textColor: Colors.white, | ||
| fontSize: 16.0, | ||
| ); | ||
| } | ||
| if (videos.result.length != 0) { | ||
| setState(() { | ||
| videoList = [...videoList, ...videos.result]; | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void _onRefresh() async { | ||
| // monitor network fetch | ||
| await _searchVideo(refresh: true); | ||
| // if failed,use refreshFailed() | ||
| _refreshController.refreshCompleted(); | ||
| } | ||
|
|
||
| void _onLoading() async { | ||
| await _searchVideo(refresh: false); | ||
| _refreshController.loadComplete(); | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Scaffold( | ||
| appBar: AppBar( | ||
| title: Container( | ||
| width: double.infinity, | ||
| height: 32, | ||
| child: Container( | ||
| width: double.infinity, | ||
| padding: EdgeInsets.only(left: 16, right: 16, bottom: 2), | ||
| // width: 120, | ||
| child: TextField( | ||
| maxLines: 1, | ||
| decoration: InputDecoration( | ||
| border: InputBorder.none, | ||
| ), | ||
| textInputAction: TextInputAction.search, | ||
| onChanged: (v) { | ||
| searchString = v; | ||
| }, | ||
| onSubmitted: (v) { | ||
| _searchVideo(refresh: true); | ||
| }, | ||
| ), | ||
| ), | ||
| decoration: BoxDecoration( | ||
| color: Colors.white, | ||
| borderRadius: const BorderRadius.all(Radius.circular(16)), | ||
| ), | ||
| ), | ||
| actions: [ | ||
| TextButton( | ||
| onPressed: () { | ||
| _searchVideo(refresh: true); | ||
| }, | ||
| child: Container( | ||
| // color: Colors.amber, | ||
| padding: EdgeInsets.only(bottom: 4), | ||
| child: Text( | ||
| '搜索', | ||
| textAlign: TextAlign.center, | ||
| style: TextStyle( | ||
| fontSize: 16, | ||
| fontWeight: FontWeight.w500, | ||
| color: Colors.black87, | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ], | ||
| flexibleSpace: Container( | ||
| height: double.maxFinite, | ||
| child: Image( | ||
| image: AssetImage( | ||
| 'assets/${Provider.of<ThemeModel>(context).assets}/head_tab_bg.jpg'), | ||
| fit: BoxFit.cover, | ||
| ), | ||
| ), | ||
| ), | ||
| body: SmartRefresher( | ||
| enablePullDown: true, | ||
| enablePullUp: true, | ||
| header: WaterDropHeader(), | ||
| footer: CustomFooter(builder: (BuildContext context, LoadStatus? mode) { | ||
| Widget body; | ||
| if (mode == LoadStatus.idle) { | ||
| body = Text("上拉加载"); | ||
| } else if (mode == LoadStatus.loading) { | ||
| body = CupertinoActivityIndicator(); | ||
| } else if (mode == LoadStatus.failed) { | ||
| body = Text("加载失败!点击重试!"); | ||
| } else if (mode == LoadStatus.canLoading) { | ||
| body = Text("松手,加载更多!"); | ||
| } else { | ||
| body = Text("没有更多数据了!"); | ||
| } | ||
| return Container( | ||
| child: Center(child: body), | ||
| ); | ||
| }), | ||
| controller: _refreshController, | ||
| onRefresh: _onRefresh, | ||
| onLoading: _onLoading, | ||
| child: ListView.builder( | ||
| itemBuilder: (c, i) => Container( | ||
| clipBehavior: Clip.antiAliasWithSaveLayer, | ||
| decoration: BoxDecoration( | ||
| color: Colors.white, | ||
| border: Border( | ||
| bottom: BorderSide( | ||
| width: 1, | ||
| color: Color.fromRGBO(240, 240, 240, 1), | ||
| ), | ||
| ), | ||
| ), | ||
| 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, | ||
| // ), | ||
| // ), | ||
| ), | ||
| itemCount: videoList.length, | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.