diff --git a/lib/api/content.dart b/lib/api/content.dart index 234a506..4f736b5 100644 --- a/lib/api/content.dart +++ b/lib/api/content.dart @@ -14,7 +14,7 @@ class FictionContent { // https://cn.ttkan.co/novel/user/page_direct?novel_id=jiansong-danshuiluyu&page=760 final url = "https://cn.ttkan.co/novel/user/page_direct?novel_id=$novelID&page=$chapterID"; - final content = await Http.get(url); + final content = await Http.get(Uri.parse(url)); final dom = parse(content.body); final fictionTitle = dom .querySelectorAll( diff --git a/lib/api/detail.dart b/lib/api/detail.dart index a00baa3..0fa9ead 100644 --- a/lib/api/detail.dart +++ b/lib/api/detail.dart @@ -23,7 +23,7 @@ class NovelDetail { static Future from(String novelID, {Language language = Language.ChineseSimplified}) async { final baseUrl = "https://cn.ttkan.co/novel/chapters/"; - final res = await Http.get(baseUrl + novelID); + final res = await Http.get(Uri.parse(baseUrl + novelID)); final dom = parse(res.body); final novelDetail = NovelDetail(); novelDetail.coverUrl = dom @@ -50,11 +50,12 @@ class NovelDetail { } novelDetail.description = dom .querySelector( - "#__layout > div > div:nth-child(2) > div > div.description > p") + "#__layout > div > div:nth-child(2) > div > div.description") + .querySelector("p") .text; - final res2 = await Http.get( - "https://cn.ttkan.co/api/nq/amp_novel_chapters?${language == Language.ChineseSimplified ? "language=cn" : ""}&novel_id=$novelID"); + final res2 = await Http.get(Uri.parse( + "https://cn.ttkan.co/api/nq/amp_novel_chapters?${language == Language.ChineseSimplified ? "language=cn" : ""}&novel_id=$novelID")); final result = JsonDecoder().convert(res2.body)["items"].map((it) { return Chapter(it["chapter_name"], it["chapter_id"].toString()); diff --git a/lib/api/recommendation.dart b/lib/api/recommendation.dart index 72e8705..c5d4cf0 100644 --- a/lib/api/recommendation.dart +++ b/lib/api/recommendation.dart @@ -43,7 +43,7 @@ class Recommendation { static Future create() async { final url = "https://cn.ttkan.co/"; - final res = await Http.get(url); + final res = await Http.get(Uri.parse(url)); final dom = parse(res.body); final recommends = dom .querySelectorAll(".rank_frame > div:not(.rank_title) > a") @@ -57,8 +57,9 @@ class Recommendation { .toList(); final categoryRecommends = - dom.querySelectorAll(".frame_body > .pure-g > div").map((e) { - final category = e.querySelector("h2").text.trim(); + dom.querySelectorAll(".frame_body > .pure-g > div.hot_cell").map((e) { + final element = e.querySelector("h2"); + final category = element.text.trim(); final headerDom = e.querySelector("li").querySelector("a"); final headerDetail = e.querySelectorAll("li div p").map((e) => e.text).toList(); @@ -87,6 +88,6 @@ class Recommendation { } main() async { - await Recommendation.create(); + final reco = await Recommendation.create(); print("hello"); } diff --git a/lib/api/search.dart b/lib/api/search.dart index 5a05d1d..07181a2 100644 --- a/lib/api/search.dart +++ b/lib/api/search.dart @@ -35,7 +35,7 @@ Language getLanguageFromString(String s) { Future> search(String keyword, {Language language = Language.ChineseTraditional}) async { final url = (language == Language.ChineseSimplified ? api_cn : api) + keyword; - final res = await Http.get(url); + final res = await Http.get(Uri.parse(url)); final selector = "#__layout > div > div.frame_body > div.pure-g > div"; diff --git a/lib/database.dart b/lib/database.dart index 7c724c0..b317113 100644 --- a/lib/database.dart +++ b/lib/database.dart @@ -94,7 +94,7 @@ CREATE TABLE IF NOT EXISTS $_historyTable ( result["chapter_title"], result["fiction_id"], result["chapter_id"], - result["content"].split("\n")); + (result["content"] as String).split("\n")); } Future cacheIfNotCached(FictionContent fictionContent) async { diff --git a/lib/pages/fictionrecommand.dart b/lib/pages/fictionrecommand.dart index 6d31e28..9c46d68 100644 --- a/lib/pages/fictionrecommand.dart +++ b/lib/pages/fictionrecommand.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:ui'; import 'package:fiction_reader/api/recommendation.dart'; import 'package:fiction_reader/main.dart'; @@ -17,7 +18,6 @@ class _FictionRecommendationState extends State { @override void initState() { - // TODO: implement initState super.initState(); Recommendation.create() .then((value) => _recommendationController.add(value)); @@ -29,6 +29,85 @@ class _FictionRecommendationState extends State { _jumpToDetail(id); } + List _listItem(Recommendation recommend) { + return recommend.categoryRecommends + .asMap() + .map( + (i, e) => MapEntry( + i, + ListView.builder( + itemCount: recommend.categoryRecommends[i].items.length + 1, + itemBuilder: (_, index) { + if (index == 0) { + final data = recommend.categoryRecommends[i].header; + return SizedBox( + height: 100, + child: InkWell( + onTap: () { + _jumpToDetail(data.fictionId); + }, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Padding( + padding: const EdgeInsets.only(right: 8), + child: Image.network(data.imageUrl), + ), + Expanded( + child: Column( + children: [ + Row( + crossAxisAlignment: + CrossAxisAlignment.baseline, + textBaseline: TextBaseline.ideographic, + children: [ + Text( + data.title, + style: TextStyle(fontSize: 20), + ), + SizedBox( + width: 8, + ), + Text(data.author), + ]), + Text( + data.description, + overflow: TextOverflow.ellipsis, + ), + ], + ), + ) + ], + ), + ), + ), + ); + } else { + return InkWell( + onTap: () { + _jumpToDetail(recommend + .categoryRecommends[i].items[index - 1].fictionId); + }, + child: Padding( + padding: EdgeInsets.all(8), + child: Text( + recommend.categoryRecommends[i].items[index - 1].title, + style: TextStyle(fontSize: 20), + ), + ), + ); + } + }, + ), + ), + ) + .values + .toList(); + } + @override Widget build(BuildContext context) { return Container( @@ -48,7 +127,11 @@ class _FictionRecommendationState extends State { final data = recommend.recommends[index]; return Stack( children: [ - Image.network(data.novelIMG), + Image.network( + data.novelIMG, + height: 130, + width: 98, + ), Positioned.fill( child: Material( color: Colors.transparent, @@ -92,96 +175,7 @@ class _FictionRecommendationState extends State { ), Expanded( child: TabBarView( - children: [ - ...recommend.categoryRecommends - .asMap() - .map( - (i, e) => MapEntry( - i, - ListView.builder( - itemCount: recommend.categoryRecommends[i] - .items.length + - 1, - itemBuilder: (_, index) { - if (index == 0) { - final data = recommend - .categoryRecommends[i].header; - return IntrinsicHeight( - child: InkWell( - onTap: () { - _jumpToDetail(data.fictionId); - }, - child: Padding( - padding: - const EdgeInsets.all(8.0), - child: Row( - mainAxisAlignment: - MainAxisAlignment - .spaceBetween, - children: [ - Image.network( - data.imageUrl), - Expanded( - child: Column( - children: [ - Row( - crossAxisAlignment: - CrossAxisAlignment - .baseline, - textBaseline: - TextBaseline - .ideographic, - children: [ - Text( - data.title, - style: TextStyle( - fontSize: - 20), - ), - SizedBox( - width: 8, - ), - Text(data - .author), - ]), - Text( - data.description, - overflow: - TextOverflow - .ellipsis, - ), - ], - ), - ) - ], - ), - ), - ), - ); - } else { - return InkWell( - onTap: () { - _jumpToDetail(recommend - .categoryRecommends[i] - .items[index - 1] - .fictionId); - }, - child: Padding( - padding: EdgeInsets.all(8), - child: Text( - recommend.categoryRecommends[i] - .items[index - 1].title, - style: TextStyle(fontSize: 20), - ), - ), - ); - } - }, - ), - ), - ) - .values, - ], + children: [...this._listItem(recommend)], ), ) ], diff --git a/pubspec.lock b/pubspec.lock index 9c5dfeb..41d7ea8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,119 +7,119 @@ packages: name: _fe_analyzer_shared url: "https://pub.dartlang.org" source: hosted - version: "11.0.0" + version: "22.0.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "0.40.4" + version: "1.7.1" args: dependency: transitive description: name: args url: "https://pub.dartlang.org" source: hosted - version: "1.6.0" + version: "2.2.0" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.2" + version: "2.8.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.5" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.3" + version: "1.3.1" cli_util: dependency: transitive description: name: cli_util url: "https://pub.dartlang.org" source: hosted - version: "0.2.0" + version: "0.3.3" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.5" + version: "1.15.0" convert: dependency: transitive description: name: convert url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "3.0.1" coverage: dependency: transitive description: name: coverage url: "https://pub.dartlang.org" source: hosted - version: "0.14.1" + version: "1.0.3" crypto: dependency: transitive description: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.1.5" + version: "3.0.1" csslib: dependency: transitive description: name: csslib url: "https://pub.dartlang.org" source: hosted - version: "0.16.2" + version: "0.17.0" cupertino_icons: dependency: "direct main" description: name: cupertino_icons url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "1.0.3" draggable_scrollbar: dependency: "direct main" description: name: draggable_scrollbar url: "https://pub.dartlang.org" source: hosted - version: "0.0.4" + version: "0.1.0" ffi: dependency: transitive description: name: ffi url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "1.1.2" file: dependency: transitive description: name: file url: "https://pub.dartlang.org" source: hosted - version: "5.2.1" + version: "6.1.2" flutter: dependency: "direct main" description: flutter @@ -130,293 +130,279 @@ packages: description: flutter source: sdk version: "0.0.0" + frontend_server_client: + dependency: transitive + description: + name: frontend_server_client + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" glob: dependency: transitive description: name: glob url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "2.0.1" google_fonts: dependency: "direct main" description: name: google_fonts url: "https://pub.dartlang.org" source: hosted - version: "1.1.1" + version: "2.1.0" html: dependency: "direct main" description: name: html url: "https://pub.dartlang.org" source: hosted - version: "0.14.0+4" + version: "0.15.0" http: dependency: "direct main" description: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.12.2" + version: "0.13.3" http_multi_server: dependency: transitive description: name: http_multi_server url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "3.0.1" http_parser: dependency: transitive description: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "3.1.4" - intl: - dependency: transitive - description: - name: intl - url: "https://pub.dartlang.org" - source: hosted - version: "0.16.1" + version: "4.0.0" io: dependency: transitive description: name: io url: "https://pub.dartlang.org" source: hosted - version: "0.3.4" + version: "1.0.3" js: dependency: transitive description: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.3-nullsafety.3" + version: "0.6.3" logging: dependency: transitive description: name: logging url: "https://pub.dartlang.org" source: hosted - version: "0.11.4" + version: "1.0.1" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.9" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.6" + version: "1.3.0" mime: dependency: transitive description: name: mime url: "https://pub.dartlang.org" source: hosted - version: "0.9.7" + version: "1.0.0" nested: dependency: transitive description: name: nested url: "https://pub.dartlang.org" source: hosted - version: "0.0.4" - node_interop: - dependency: transitive - description: - name: node_interop - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.1" - node_io: - dependency: transitive - description: - name: node_io - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.1" + version: "1.0.0" node_preamble: dependency: transitive description: name: node_preamble url: "https://pub.dartlang.org" source: hosted - version: "1.4.12" + version: "2.0.1" package_config: dependency: transitive description: name: package_config url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "2.0.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" path_provider: dependency: transitive description: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "1.6.22" + version: "2.0.2" path_provider_linux: dependency: transitive description: name: path_provider_linux url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+2" + version: "2.0.2" path_provider_macos: dependency: transitive description: name: path_provider_macos url: "https://pub.dartlang.org" source: hosted - version: "0.0.4+4" + version: "2.0.2" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "2.0.1" path_provider_windows: dependency: transitive description: name: path_provider_windows url: "https://pub.dartlang.org" source: hosted - version: "0.0.4+1" + version: "2.0.3" pedantic: dependency: transitive description: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.9.2" + version: "1.11.1" platform: dependency: transitive description: name: platform url: "https://pub.dartlang.org" source: hosted - version: "2.2.1" + version: "3.0.0" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "2.0.1" pool: dependency: transitive description: name: pool url: "https://pub.dartlang.org" source: hosted - version: "1.4.0" + version: "1.5.0" process: dependency: transitive description: name: process url: "https://pub.dartlang.org" source: hosted - version: "3.0.13" + version: "4.2.3" provider: dependency: "direct main" description: name: provider url: "https://pub.dartlang.org" source: hosted - version: "4.3.2+2" + version: "5.0.0" pub_semver: dependency: transitive description: name: pub_semver url: "https://pub.dartlang.org" source: hosted - version: "1.4.4" + version: "2.0.0" shared_preferences: dependency: "direct main" description: name: shared_preferences url: "https://pub.dartlang.org" source: hosted - version: "0.5.12+2" + version: "2.0.6" shared_preferences_linux: dependency: transitive description: name: shared_preferences_linux url: "https://pub.dartlang.org" source: hosted - version: "0.0.2+2" + version: "2.0.2" shared_preferences_macos: dependency: transitive description: name: shared_preferences_macos url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+10" + version: "2.0.2" shared_preferences_platform_interface: dependency: transitive description: name: shared_preferences_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "2.0.0" shared_preferences_web: dependency: transitive description: name: shared_preferences_web url: "https://pub.dartlang.org" source: hosted - version: "0.1.2+7" + version: "2.0.1" shared_preferences_windows: dependency: transitive description: name: shared_preferences_windows url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+1" + version: "2.0.2" shelf: dependency: transitive description: name: shelf url: "https://pub.dartlang.org" source: hosted - version: "0.7.9" + version: "1.2.0" shelf_packages_handler: dependency: transitive description: name: shelf_packages_handler url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "3.0.0" shelf_static: dependency: transitive description: name: shelf_static url: "https://pub.dartlang.org" source: hosted - version: "0.2.8" + version: "1.1.0" shelf_web_socket: dependency: transitive description: name: shelf_web_socket url: "https://pub.dartlang.org" source: hosted - version: "0.2.3" + version: "1.0.1" sky_engine: dependency: transitive description: flutter @@ -428,154 +414,154 @@ packages: name: source_map_stack_trace url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" source_maps: dependency: transitive description: name: source_maps url: "https://pub.dartlang.org" source: hosted - version: "0.10.9" + version: "0.10.10" source_span: dependency: transitive description: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.1" sqflite: dependency: "direct main" description: name: sqflite url: "https://pub.dartlang.org" source: hosted - version: "1.3.1+2" + version: "2.0.0+3" sqflite_common: dependency: transitive description: name: sqflite_common url: "https://pub.dartlang.org" source: hosted - version: "1.0.2+1" + version: "2.0.0+2" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.5" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0" synchronized: dependency: transitive description: name: synchronized url: "https://pub.dartlang.org" source: hosted - version: "2.2.0+2" + version: "3.0.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" test: dependency: "direct dev" description: name: test url: "https://pub.dartlang.org" source: hosted - version: "1.15.4" + version: "1.17.10" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.18" + version: "0.4.2" test_core: dependency: transitive description: name: test_core url: "https://pub.dartlang.org" source: hosted - version: "0.3.11+1" + version: "0.4.0" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.5" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.5" + version: "2.1.0" vm_service: dependency: transitive description: name: vm_service url: "https://pub.dartlang.org" source: hosted - version: "4.2.0" + version: "7.2.0" watcher: dependency: transitive description: name: watcher url: "https://pub.dartlang.org" source: hosted - version: "0.9.7+15" + version: "1.0.0" web_socket_channel: dependency: transitive description: name: web_socket_channel url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "2.1.0" webkit_inspection_protocol: dependency: transitive description: name: webkit_inspection_protocol url: "https://pub.dartlang.org" source: hosted - version: "0.7.3" + version: "1.0.0" win32: dependency: transitive description: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "1.7.3" + version: "2.2.5" xdg_directories: dependency: transitive description: name: xdg_directories url: "https://pub.dartlang.org" source: hosted - version: "0.1.2" + version: "0.2.0" yaml: dependency: transitive description: name: yaml url: "https://pub.dartlang.org" source: hosted - version: "2.2.1" + version: "3.1.0" sdks: - dart: ">=2.12.0-0 <3.0.0" - flutter: ">=1.17.0 <2.0.0" + dart: ">=2.13.0 <3.0.0" + flutter: ">=2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 710a3f2..96f6be1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,21 +10,21 @@ dependencies: flutter: sdk: flutter - cupertino_icons: ^0.1.3 + cupertino_icons: ^1.0.3 - http: ^0.12.2 + http: ^0.13.3 - html: ^0.14.0+4 + html: ^0.15.0 - draggable_scrollbar: ^0.0.4 + draggable_scrollbar: ^0.1.0 - provider: ^4.3.2+2 + provider: ^5.0.0 - sqflite: 1.3.1+2 + sqflite: ^2.0.0+3 - google_fonts: ^1.1.1 + google_fonts: ^2.1.0 - shared_preferences: ^0.5.12+2 + shared_preferences: ^2.0.6 dev_dependencies: test: ^1.15.4