提交 a4d27b1e authored 作者: yueweilu's avatar yueweilu

优化阅读页代码

上级 9bfd0e61
......@@ -71,7 +71,6 @@ class _ReadPageState extends State<ReadPage> {
child: Stack(
children: [
InAppWebView(
// initialFile:''assets/html/read_unline.html'',
initialFile: readController.existDownFile && !readController.netStatus?'assets/html/read_unline.html':'assets/html/read.html',
// initialUrlRequest:URLRequest(
// url:WebUri.uri(Uri.parse(kReadTestUnderLineBook))
......@@ -82,16 +81,9 @@ class _ReadPageState extends State<ReadPage> {
// http的请求也不做限制
mixedContentMode:MixedContentMode.MIXED_CONTENT_ALWAYS_ALLOW
),
// initialOptions: InAppWebViewGroupOptions(
// crossPlatform: InAppWebViewOptions(
// clearCache: true
// )
// ),
contextMenu: ContextMenu(
// options: ContextMenuOptions(hideDefaultSystemContextMenuItems: true),
settings: ContextMenuSettings(
hideDefaultSystemContextMenuItems: true,
)
),
onWebViewCreated: (InAppWebViewController controller){
......@@ -103,30 +95,22 @@ class _ReadPageState extends State<ReadPage> {
Console.log("Received message from WebView-----------------------------: ${consoleMessage.message}");
},
onLoadStop: (controller, url) {
// flutter 主动给 js 传参数
// String str = '$kServerUrl,${readController.bookId},${readController.chapterId},${UserStore.to.token},${readController.noteId},${readController.sModel.bookId =='0'?'':readController.sModel.combinedContent}';
// controller.evaluateJavascript(source: 'callbackInFlutterComponent("$str");');
// Console.log('传给前端的参数--------------------------------$str');
// String jsonStr = jsonEncode(param);
// controller.evaluateJavascript(source: 'callbackInFlutterComponent($jsonStr)');
if(readController.existDownFile && !readController.netStatus){
String temp = readController.existDownFile && !readController.netStatus?'assets/html/read_unline.html':'assets/html/read.html';
Console.log('-----------------加载离线数据---------------$temp');
Console.log('-----------------加载离线数据---------------');
readController.getOffLineInfo();
}
else {
// controller.loadFile(assetFilePath: 'assets/html/read.html');
Console.log('-----------------加载在线数据---------------');
String str = '$kServerUrl,${readController.bookId},${readController.chapterId},${UserStore.to.token},${readController.noteId},${readController.sModel.bookId =='0'?'':readController.sModel.combinedContent}';
controller.evaluateJavascript(source: 'callbackInFlutterComponent("$str");');
}
// 添加单击事件
controller.evaluateJavascript(source: '''
document.addEventListener('click', function() {
window.flutter_inappwebview.callHandler('onTap');
});
''');
// 监听js单击回调
controller.addJavaScriptHandler(handlerName: 'onTap', callback: (args){
readController.setShow(readController.show);
......@@ -158,12 +142,6 @@ class _ReadPageState extends State<ReadPage> {
controller.addJavaScriptHandler(handlerName: 'readCallBack', callback: (args){
Console.log('监听朗读回调------------------------------------------------$args');
readController.speak(args.first.toString());
// readController.speak('中国共产党(英文名:the Communist Party of China,简写CPC),'
// '创建于1921年7月23日,1921年中国共产党成立后,确立了新民主主义革命的正确道路,让灾难深重的中'
// '国人民看到了新的希望、有了新的依靠。我们党探索出农村包围城市、武装夺取政权的正确革命道路,“唤起工'
// '农千百万”“夺过鞭子揍敌人”,经过土地革命战争、抗日战争、解放战争,推翻了压在中国人民头上的帝国主义、'
// '封建主义、官僚资本主义“三座大山”,建立了人民当家作主的中华人民共和国,彻底结束了近代以来中国内忧外患、积贫积弱的悲惨境地,开启了中华民族发展进步的新纪元'
// );
});
// 监听讨论回调
......@@ -174,6 +152,7 @@ class _ReadPageState extends State<ReadPage> {
readController.noteTitle = args.first.toString();
});
// 答题和答题结果页回调
controller.addJavaScriptHandler(handlerName: 'answerResultCallBack', callback: (args){
Console.log('监听答题回调------------------------------------------------$args');
......@@ -245,6 +224,7 @@ class _ReadPageState extends State<ReadPage> {
Console.log('监听画廊 扩展于都---------------给页面传参---------------------------------$params');
context.pushNamed(Routes.readInfo,queryParameters: params);
});
// 图片预览
controller.addJavaScriptHandler(handlerName: 'scaleImageCallback', callback: (args){
String url = args.first[0].toString();
......@@ -274,23 +254,13 @@ class _ReadPageState extends State<ReadPage> {
});
/// 离线需要参数
// //
// Map<String, dynamic> param111 = {
// 'book_id': readController.bookId,
// 'chapter_id': readController.chapterId,
// 'token':UserStore.to.token
// };
// String jsonStr = jsonEncode(param111);
// controller.evaluateJavascript(source: 'offlineCallbackInFlutterComponent($jsonStr)');
// // controller.evaluateJavascript(source: 'callbackInFlutterComponent("$str");');
// 添加高亮划线笔记
controller.addJavaScriptHandler(handlerName: 'offlineAddNoteCallBack', callback: (args){
Console.log('添加笔记回调------------------------------------------${args[0]}');
Map<String,dynamic> data = args[0];
readController.addLocalNote(data);
});
// 删除高亮划线笔记
controller.addJavaScriptHandler(handlerName: 'offlineDelNoteCallBack', callback: (args){
Console.log('删除笔记回调------------------------------------------${args[0]}');
......@@ -316,26 +286,6 @@ class _ReadPageState extends State<ReadPage> {
}
readController.updateLocalNote(notesId: notesId,id:id, data: data);
});
// 查询高亮划线笔记
// controller.addJavaScriptHandler(handlerName: 'offlineQueryNoteCallBack', callback: (args){
//
// });
// // 上一节下一节
// controller.addJavaScriptHandler(handlerName: 'offlineReadNoteCallBack', callback: (args){
// int type = 0;
// // 上一节
// if (type == 0){
// readController.readChapter(type: 0);
// }
// // 下一节
// else{
// readController.readChapter(type: 1);
// }
//
// });
},
),
Positioned(
......@@ -405,7 +355,7 @@ class _ReadPageState extends State<ReadPage> {
}
/// 目录 笔记 讨论 工具栏
// 目录 笔记 讨论 工具栏
Widget _createToolBar(ReadController controller){
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
......@@ -439,7 +389,6 @@ class _ReadPageState extends State<ReadPage> {
);
}
Widget detail(ReadController controller,ToolModel model){
if(model.tag == 0){
return ReadCategoryPage(controller: controller,
......@@ -508,7 +457,7 @@ class _ReadPageState extends State<ReadPage> {
}
return const SizedBox();
}
/// 目录、评论、笔记 背景
// 目录、评论、笔记 背景
Widget _showContent(ReadController controller,ToolModel model) {
if (controller.show){
if(model.selected){
......@@ -540,12 +489,10 @@ class _ReadPageState extends State<ReadPage> {
}
return const SizedBox();
}
}
/// 定制 悬浮按钮位置
// 定制 悬浮按钮位置
class MyFloatingActionButtonLocation extends FloatingActionButtonLocation {
@override
Offset getOffset(ScaffoldPrelayoutGeometry scaffoldGeometry) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论