Skip to content

Commit

Permalink
add read scene
Browse files Browse the repository at this point in the history
  • Loading branch information
jayden320 committed Jan 20, 2019
1 parent 33a59a5 commit 63ad1e6
Show file tree
Hide file tree
Showing 51 changed files with 715 additions and 76 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@

<img src="https://github.com/huanxsd/flutter_shuqi/blob/master/screenshot/ios_1.png">

<img src="https://github.com/huanxsd/flutter_shuqi/blob/master/screenshot/ios_2.png">

## screen shot for Android

<img src="https://github.com/huanxsd/flutter_shuqi/blob/master/screenshot/android_0.png">

<img src="https://github.com/huanxsd/flutter_shuqi/blob/master/screenshot/android_1.png">

<img src="https://github.com/huanxsd/flutter_shuqi/blob/master/screenshot/android_2.png">

## Setup

1. **Clone the repo**
Expand Down
Binary file added img/2.0x/read_icon_brightness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/2.0x/read_icon_catalog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/2.0x/read_icon_chapter_next.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/2.0x/read_icon_chapter_previous.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/2.0x/read_icon_font.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/2.0x/read_icon_more.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/2.0x/read_icon_setting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/2.0x/read_icon_voice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/2.0x/reader_battery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/read_icon_brightness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/read_icon_catalog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/read_icon_chapter_next.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/read_icon_chapter_previous.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/read_icon_font.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/read_icon_more.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/read_icon_setting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/read_icon_voice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/reader_battery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions lib/app/app_navigator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:shuqi/public.dart';
import 'package:shuqi/novel_detail/novel_detail_scene.dart';
import 'package:shuqi/me/login_scene.dart';
import 'package:shuqi/me/web_scene.dart';
import 'package:shuqi/reader/reader_scene.dart';

class AppNavigator {
static push(BuildContext context, Widget scene) {
Expand All @@ -31,4 +32,10 @@ class AppNavigator {
return WebScene(url: url, title: title);
}));
}

static pushReader(BuildContext context, int articleId) {
Navigator.push(context, MaterialPageRoute(builder: (context) {
return ReaderScene(articleId: articleId);
}));
}
}
2 changes: 1 addition & 1 deletion lib/bookshelf/bookshelf_scene.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class BookshelfState extends State<BookshelfScene> with RouteAware {
this.favoriteNovels = favoriteNovels;
});
} catch (e) {
print(e);
Toast.show(e.toString());
}
}

Expand Down
58 changes: 31 additions & 27 deletions lib/home/home_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,38 @@ class HomeListViewState extends State<HomeListView> with AutomaticKeepAliveClien
bool get wantKeepAlive => true;

Future<void> fetchData() async {
var action;
switch (this.widget.type) {
case HomeListType.excellent:
action = 'home_excellent';
break;
case HomeListType.female:
action = 'home_female';
break;
case HomeListType.male:
action = 'home_male';
break;
case HomeListType.cartoon:
action = 'home_cartoon';
break;
default:
break;
}
var responseJson = await Request.get(action: action);
List moduleData = responseJson['module'];
List<HomeModule> modules = [];
moduleData.forEach((data) {
modules.add(HomeModule.fromJson(data));
});
try {
var action;
switch (this.widget.type) {
case HomeListType.excellent:
action = 'home_excellent';
break;
case HomeListType.female:
action = 'home_female';
break;
case HomeListType.male:
action = 'home_male';
break;
case HomeListType.cartoon:
action = 'home_cartoon';
break;
default:
break;
}
var responseJson = await Request.get(action: action);
List moduleData = responseJson['module'];
List<HomeModule> modules = [];
moduleData.forEach((data) {
modules.add(HomeModule.fromJson(data));
});

setState(() {
this.modules = modules;
this.carouselInfos = carouselInfos;
});
setState(() {
this.modules = modules;
this.carouselInfos = carouselInfos;
});
} catch (e) {
Toast.show(e.toString());
}
}

Widget bookCardWithInfo(HomeModule module) {
Expand Down
36 changes: 22 additions & 14 deletions lib/me/login_scene.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,35 @@ class LoginSceneState extends State {
if (phoneEditer.text.length == 0) {
return;
}
await Request.post(
action: 'sms',
params: {'phone': phoneEditer.text, 'type': 'login'},
);
setState(() {
coldDownSeconds = 60;
});
coldDown();
try {
await Request.post(
action: 'sms',
params: {'phone': phoneEditer.text, 'type': 'login'},
);
setState(() {
coldDownSeconds = 60;
});
coldDown();
} catch (e) {
Toast.show(e.toString());
}
}

login() async {
var phone = phoneEditer.text;
var code = codeEditer.text;

var response = await Request.post(action: 'login', params: {
'phone': phone,
'code': code,
});
UserManager.instance.login(response);
try {
var response = await Request.post(action: 'login', params: {
'phone': phone,
'code': code,
});
UserManager.instance.login(response);

Navigator.pop(context);
Navigator.pop(context);
} catch (e) {
Toast.show(e.toString());
}
}

@override
Expand Down
30 changes: 30 additions & 0 deletions lib/model/article.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Article {
int id;
int novelId;
String title;
String content;
int price;
int idx;
int nextArticleId;
int preArticleId;

List<Map<String, int>> pageOffsets;

Article.fromJson(Map data) {
id = data['id'];
novelId = data['novel_id'];
title = data['title'];
content = data['content'];
content = '  ' + content;
content = content.replaceAll('\n', '\n  ');
price = data['welth'];
idx = data['idx'];
nextArticleId = data['next_id'];
preArticleId = data['prev_id'];
}

String stringAtPageIndex(int index) {
var offset = pageOffsets[index];
return this.content.substring(offset['start'], offset['end']);
}
}
2 changes: 2 additions & 0 deletions lib/model/novel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Novel {
int chapterCount;
int recommendCount;
int commentCount;
int firstArticleId;

List<String> roles;
String status;
Expand All @@ -26,6 +27,7 @@ class Novel {

Novel.fromJson(Map data) {
id = data['bid'];
firstArticleId = data['first_article_id'];
name = data['bookname'];
imgUrl = data['book_cover'];
firstChapter = data['topic_first'];
Expand Down
10 changes: 5 additions & 5 deletions lib/novel_detail/novel_detail_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ class NovelDetailHeader extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(novel.name, style: TextStyle(fontSize: 18, color: Colors.white, fontWeight: FontWeight.bold)),
Text(novel.name, style: TextStyle(fontSize: fixedFontSize(18), color: Colors.white, fontWeight: FontWeight.bold)),
SizedBox(height: 10),
Text(novel.author, style: TextStyle(fontSize: 14, color: SQColor.white)),
Text(novel.author, style: TextStyle(fontSize: fixedFontSize(14), color: SQColor.white)),
SizedBox(height: 10),
Text('${novel.wordCount}万字 ${novel.price}书豆/千字', style: TextStyle(fontSize: 14, color: SQColor.white)),
Text('${novel.wordCount}万字 ${novel.price}书豆/千字', style: TextStyle(fontSize: fixedFontSize(14), color: SQColor.white)),
SizedBox(height: 10),
buildScore(),
SizedBox(height: 10),
Expand All @@ -63,7 +63,7 @@ class NovelDetailHeader extends StatelessWidget {
Expanded(
child: Text(
' 续费包月会员,万本小说免费读 >',
style: TextStyle(fontSize: 14, color: Color(0xFFFEA900)),
style: TextStyle(fontSize: fixedFontSize(14), color: Color(0xFFFEA900)),
maxLines: 1,
),
),
Expand All @@ -78,7 +78,7 @@ class NovelDetailHeader extends StatelessWidget {
}

Widget buildScore() {
List<Widget> children = [Text('评分:${novel.score}分 ', style: TextStyle(fontSize: 14, color: Color(0xfff8e71c)))];
List<Widget> children = [Text('评分:${novel.score}分 ', style: TextStyle(fontSize: fixedFontSize(14), color: Color(0xfff8e71c)))];

var star = novel.score;

Expand Down
42 changes: 23 additions & 19 deletions lib/novel_detail/novel_detail_scene.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class NovelDetailSceneState extends State<NovelDetailScene> with RouteAware {
void didPush() {
// 间隔500毫秒后,再设置状态栏样式。否则设置无效(会被build覆盖?)。
Timer(Duration(milliseconds: 500), () {
Screen.updateStatusBarStyle(SystemUiOverlayStyle.light);
updateStatusBar();
});
}

Expand Down Expand Up @@ -105,27 +105,31 @@ class NovelDetailSceneState extends State<NovelDetailScene> with RouteAware {
}

fetchData() async {
var novelId = this.widget.novelId;
try {
var novelId = this.widget.novelId;

var novelResponse = await Request.post(action: 'novel_detail', params: {'id': novelId});
var novelResponse = await Request.post(action: 'novel_detail', params: {'id': novelId});

var commentsResponse = await Request.post(action: 'novel_comment', params: {'id': novelId});
List<NovelComment> comments = [];
commentsResponse.forEach((data) {
comments.add(NovelComment.fromJson(data));
});
var commentsResponse = await Request.post(action: 'novel_comment', params: {'id': novelId});
List<NovelComment> comments = [];
commentsResponse.forEach((data) {
comments.add(NovelComment.fromJson(data));
});

var recommendResponse = await Request.post(action: 'novel_recommend', params: {'id': novelId});
List<Novel> recommendNovels = [];
recommendResponse.forEach((data) {
recommendNovels.add(Novel.fromJson(data));
});
var recommendResponse = await Request.post(action: 'novel_recommend', params: {'id': novelId});
List<Novel> recommendNovels = [];
recommendResponse.forEach((data) {
recommendNovels.add(Novel.fromJson(data));
});

setState(() {
this.novel = Novel.fromJson(novelResponse);
this.comments = comments;
this.recommendNovels = recommendNovels;
});
setState(() {
this.novel = Novel.fromJson(novelResponse);
this.comments = comments;
this.recommendNovels = recommendNovels;
});
} catch (e) {
Toast.show(e.toString());
}
}

Widget buildNavigationBar() {
Expand Down Expand Up @@ -274,7 +278,7 @@ class NovelDetailSceneState extends State<NovelDetailScene> with RouteAware {
],
),
),
NovelDetailToolbar(),
NovelDetailToolbar(novel),
],
),
buildNavigationBar(),
Expand Down
22 changes: 15 additions & 7 deletions lib/novel_detail/novel_detail_toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import 'package:flutter/material.dart';
import 'package:shuqi/public.dart';

class NovelDetailToolbar extends StatelessWidget {
final Novel novel;
NovelDetailToolbar(this.novel);

read() {}
@override
Widget build(BuildContext context) {
Expand All @@ -20,13 +23,18 @@ class NovelDetailToolbar extends StatelessWidget {
),
),
Expanded(
child: Container(
height: 40,
decoration: BoxDecoration(color: SQColor.primary, borderRadius: BorderRadius.circular(5)),
child: Center(
child: Text(
'开始阅读',
style: TextStyle(fontSize: 16, color: Colors.white),
child: GestureDetector(
onTap: () {
AppNavigator.pushReader(context, novel.firstArticleId);
},
child: Container(
height: 40,
decoration: BoxDecoration(color: SQColor.primary, borderRadius: BorderRadius.circular(5)),
child: Center(
child: Text(
'开始阅读',
style: TextStyle(fontSize: 16, color: Colors.white),
),
),
),
),
Expand Down
5 changes: 5 additions & 0 deletions lib/public.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
library public;

// Vendor

// Global
export 'package:shuqi/global.dart';

// Utility
export 'package:shuqi/utility/utility.dart';
export 'package:shuqi/utility/screen.dart';
export 'package:shuqi/utility/event_bus.dart';
export 'package:shuqi/utility/toast.dart';

// Widget
export 'package:shuqi/widget/novel_cover_image.dart';
Expand All @@ -23,3 +27,4 @@ export 'package:shuqi/app/app_scene.dart';
export 'package:shuqi/model/novel.dart';
export 'package:shuqi/model/chapter.dart';
export 'package:shuqi/model/novel_comment.dart';
export 'package:shuqi/model/article.dart';
10 changes: 10 additions & 0 deletions lib/reader/article_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:shuqi/public.dart';

class ArticleProvider {
static Future<Article> fetchArticle(int articleId) async {
var response = await Request.get(action: 'article_$articleId');
var article = Article.fromJson(response);

return article;
}
}
Loading

0 comments on commit 63ad1e6

Please sign in to comment.