From 3f7a15bb71435e3d6f063bf6cc5213fd0812622d Mon Sep 17 00:00:00 2001 From: yuluo Date: Thu, 21 Oct 2021 10:07:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=95=E5=85=A5=E5=AD=97=E4=BD=93=E5=9B=BE?= =?UTF-8?q?=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- douban_app/lib/models/book_av_model.dart | 120 ++++++++++++++++++ douban_app/lib/service/http_book_av.dart | 10 ++ douban_app/lib/service/request.dart | 22 ++++ .../views/book/tab_pages/read/book_card.dart | 46 +++++++ .../lib/views/book/tab_pages/read/index.dart | 53 +++++--- douban_app/pubspec.yaml | 2 +- 6 files changed, 237 insertions(+), 16 deletions(-) create mode 100644 douban_app/lib/models/book_av_model.dart create mode 100644 douban_app/lib/service/http_book_av.dart create mode 100644 douban_app/lib/service/request.dart create mode 100644 douban_app/lib/views/book/tab_pages/read/book_card.dart diff --git a/douban_app/lib/models/book_av_model.dart b/douban_app/lib/models/book_av_model.dart new file mode 100644 index 0000000..0d345bf --- /dev/null +++ b/douban_app/lib/models/book_av_model.dart @@ -0,0 +1,120 @@ +/// rating : ["9.6","50"] +/// rank : 2 +/// cover_url : "https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2561716440.webp" +/// is_playable : true +/// id : "1291546" +/// types : ["剧情","爱情","同性"] +/// regions : ["中国大陆","中国香港"] +/// title : "霸王别姬" +/// url : "https://movie.douban.com/subject/1291546/" +/// release_date : "1993-07-26" +/// actor_count : 26 +/// vote_count : 1835269 +/// score : "9.6" +/// actors : ["张国荣","张丰毅","巩俐","葛优","英达","蒋雯丽","吴大维","吕齐","雷汉","尹治","马明威","费振翔","智一桐","李春","赵海龙","李丹","童弟","沈慧芬","黄斐","徐杰","黄磊","冯远征","杨立新","方征","周璞","隋永清"] +/// is_watched : false + +class Book_av_model { + Book_av_model({ + List rating, + int rank, + String coverUrl, + bool isPlayable, + String id, + List types, + List regions, + String title, + String url, + String releaseDate, + int actorCount, + int voteCount, + String score, + List actors, + bool isWatched,}){ + _rating = rating; + _rank = rank; + _coverUrl = coverUrl; + _isPlayable = isPlayable; + _id = id; + _types = types; + _regions = regions; + _title = title; + _url = url; + _releaseDate = releaseDate; + _actorCount = actorCount; + _voteCount = voteCount; + _score = score; + _actors = actors; + _isWatched = isWatched; +} + + Book_av_model.fromJson(dynamic json) { + _rating = json['rating'] != null ? json['rating'].cast() : []; + _rank = json['rank']; + _coverUrl = json['cover_url']; + _isPlayable = json['is_playable']; + _id = json['id']; + _types = json['types'] != null ? json['types'].cast() : []; + _regions = json['regions'] != null ? json['regions'].cast() : []; + _title = json['title']; + _url = json['url']; + _releaseDate = json['release_date']; + _actorCount = json['actor_count']; + _voteCount = json['vote_count']; + _score = json['score']; + _actors = json['actors'] != null ? json['actors'].cast() : []; + _isWatched = json['is_watched']; + } + List _rating; + int _rank; + String _coverUrl; + bool _isPlayable; + String _id; + List _types; + List _regions; + String _title; + String _url; + String _releaseDate; + int _actorCount; + int _voteCount; + String _score; + List _actors; + bool _isWatched; + + List get rating => _rating; + int get rank => _rank; + String get coverUrl => _coverUrl; + bool get isPlayable => _isPlayable; + String get id => _id; + List get types => _types; + List get regions => _regions; + String get title => _title; + String get url => _url; + String get releaseDate => _releaseDate; + int get actorCount => _actorCount; + int get voteCount => _voteCount; + String get score => _score; + List get actors => _actors; + bool get isWatched => _isWatched; + + Map toJson() { + final map = {}; + map['rating'] = _rating; + map['rank'] = _rank; + map['cover_url'] = _coverUrl; + map['is_playable'] = _isPlayable; + map['id'] = _id; + map['types'] = _types; + map['regions'] = _regions; + map['title'] = _title; + map['url'] = _url; + map['release_date'] = _releaseDate; + map['actor_count'] = _actorCount; + map['vote_count'] = _voteCount; + map['score'] = _score; + map['actors'] = _actors; + map['is_watched'] = _isWatched; + return map; + } + +} \ No newline at end of file diff --git a/douban_app/lib/service/http_book_av.dart b/douban_app/lib/service/http_book_av.dart new file mode 100644 index 0000000..66db1dd --- /dev/null +++ b/douban_app/lib/service/http_book_av.dart @@ -0,0 +1,10 @@ +import 'package:douban_app/service/request.dart'; + +class BookAvRequest { + Future getMovieTopList(int start, int count) async { + final url = "https://movie.douban.com/j/chart/top_list?type=11&interval_id=100%3A90&action=&start=$start&limit=$count"; + final result = await HttpRequest.request(url); + // List movieList = []; + print(result); + } +} \ No newline at end of file diff --git a/douban_app/lib/service/request.dart b/douban_app/lib/service/request.dart new file mode 100644 index 0000000..75925af --- /dev/null +++ b/douban_app/lib/service/request.dart @@ -0,0 +1,22 @@ + +import 'package:dio/dio.dart'; + +const timeout = 5000; + +class HttpRequest { + static BaseOptions baseOptions = BaseOptions(connectTimeout: timeout); + static Dio dio = Dio(baseOptions); + + static Future request(String url, {String method = 'get', Map params}) async { + // 单独相关的设置 + Options options = Options(); + options.method = method; + // 发送网络请求 + try { + Response response = await dio.request(url, queryParameters: params, options: options); + return response.data; + } on DioError catch(e) { + throw e; + } + } +} \ No newline at end of file diff --git a/douban_app/lib/views/book/tab_pages/read/book_card.dart b/douban_app/lib/views/book/tab_pages/read/book_card.dart new file mode 100644 index 0000000..eb27dbb --- /dev/null +++ b/douban_app/lib/views/book/tab_pages/read/book_card.dart @@ -0,0 +1,46 @@ +import 'package:flutter/material.dart'; + +Widget bookCard() { + return Container( + width: 290, + // height: 200, + padding: EdgeInsets.all(12), + decoration: BoxDecoration( + border: Border.all(width: 1, color: Color(0xFFE0E0E0)), + borderRadius: BorderRadius.circular(12) + ), + child: Row( + children: [ + Image.network('https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2561716440.jpg', height: 140,width: 98,), + SizedBox(width: 10,), + Expanded( + child: Container( + child: Column( + children: [ + Text('霸王别姬', style: TextStyle(color: Color(0xFF191919), fontSize: 18),), + Text('8757人想读/[日]上野千鹤子', style: TextStyle(color: Color(0xFF818181), fontSize: 12),), + Row( + children: [ + _tag('女性主义'), + _tag('上野千鹤子'), + ], + ) + ], + ), + ), + ) + ], + ), + ); +} + +Widget _tag(String text) { + return Container( + padding: EdgeInsets.symmetric(vertical: 4, horizontal: 8), + decoration: BoxDecoration( + color: Color(0xFFF7F7F7), + borderRadius: BorderRadius.circular(10) + ), + child: Text(text, style: TextStyle(fontSize: 12),), + ); +} \ No newline at end of file diff --git a/douban_app/lib/views/book/tab_pages/read/index.dart b/douban_app/lib/views/book/tab_pages/read/index.dart index 614b7da..4a4ba8a 100644 --- a/douban_app/lib/views/book/tab_pages/read/index.dart +++ b/douban_app/lib/views/book/tab_pages/read/index.dart @@ -1,4 +1,6 @@ +import 'package:douban_app/service/http_book_av.dart'; import 'package:douban_app/utils/my_icon.dart'; +import 'package:douban_app/views/book/tab_pages/read/book_card.dart'; import 'package:douban_app/views/book/tab_pages/read/top_card.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -10,6 +12,15 @@ class TabRead extends StatefulWidget { class _TabReadState extends State { + // 实例化请求 + BookAvRequest bookAvRequest = BookAvRequest(); + + @override + void initState() { + super.initState(); + bookAvRequest.getMovieTopList(1, 10); + } + String currentTabItem = '全部'; List bookTypeList = ['全部', '文学', '小说', '历史文化', '社会纪实', '科学新知', '游戏']; @@ -34,27 +45,39 @@ class _TabReadState extends State { ), Container( margin: EdgeInsets.only(top: 10, bottom: 10), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + child: Column( children: [ - Text('新书速递', style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),), Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text('全部 ', style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),), - Text('200', style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold)), - Icon(Icons.chevron_right) + Text('新书速递', style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),), + Row( + children: [ + Text('全部 ', style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),), + Text('200', style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold)), + Icon(Icons.chevron_right) + ], + ), ], + ), + Container( + height: 50, + child: ListView( + scrollDirection: Axis.horizontal, + children: bookTypeList.map((text) => bookTypeBtn(text)).toList() + ), + ), + Container( + height: 170, + child: ListView( + scrollDirection: Axis.horizontal, + children: [ + bookCard() + ], + ), ) ], - ), - ), - Container( - height: 50, - width: 375, - child: ListView( - scrollDirection: Axis.horizontal, - children: bookTypeList.map((text) => bookTypeBtn(text)).toList() - ), + ) ), Padding( padding: EdgeInsets.symmetric(vertical: 10), diff --git a/douban_app/pubspec.yaml b/douban_app/pubspec.yaml index d0ee777..edea2ac 100644 --- a/douban_app/pubspec.yaml +++ b/douban_app/pubspec.yaml @@ -27,7 +27,7 @@ dependencies: json_annotation: any freezed_annotation: any flutter_screenutil: ^5.0.0+2 - + dio: ^4.0.0 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^0.1.3 -- Gitee