ella_saas_flutter

Last updated:

0 purchases

ella_saas_flutter Image
ella_saas_flutter Images
Add to Cart

Description:

ella saas flutter

Flutter 插件集成指南(iOS 部分暂未实现) #
安装 #
在工程 pubspec.yaml 中加入 dependencies
// pub 集成
dependencies:
ella_saas_flutter: ^0.1.0
copied to clipboard
使用 #
导包
// 下载、打开、删除图书的方法在这个插件中
import 'package:ella_saas_flutter/ella_saas_flutter.dart';
// 控制阅读器的方法,在这个插件中
import 'package:ella_saas_flutter/read_book_flutter.dart';
copied to clipboard
自定义 Flutter 界面
可以在阅读器界面上自定义 Flutter 的界面,用来控制图书的翻页、暂停、切换播放模式等功能,自定义界面的路由为com.ellabook/controlView',参考下面👇代码
void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(routes: {
'com.ellabook/controlView': (context) => const ControlView(),
}, home: MyHomePage());
}
}
copied to clipboard
因为要把 Flutter 界面的点击事件传递给原生阅读器进行处理,所以 Flutter 要实现这部分代码,插件已经将事件处理这部分代码抽取成了一个 widget,只需要在写 Flutter 界面的时候,引用EllaGestureDetector即可,示例代码如下
@override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
return MaterialApp(
theme: ThemeData(canvasColor: Colors.transparent),
home: EllaGestureDetector(
readBookFlutterPlugin: _readBookFlutterPlugin,
child: ...,
),
);
}
copied to clipboard
APIs #
通用 API

initConfig
addEventHandler
downloadBook
openBook
deleteBook
addBookEventHandler
getBookPlayMode
exit
showTips
pageUp
pageDown
pause
resume
refreshReader
setBookPlayMode

initConfig
初始化设置
final _ellaSaasFlutterPlugin = EllaSaasFlutter();
_ellaSaasFlutterPlugin.initConfig(
androidAppKey: "androidAppkey",
androidAppSecret: "androidAppSecret"
);
copied to clipboard
addEventHandler
添加事件监听方法
final _ellaSaasFlutterPlugin = EllaSaasFlutter();
_ellaSaasFlutterPlugin.addEventHandler(
// 开始下载
onStart: (Map<String, dynamic> message) async {
String bookCode = message[Constants.bookCode];
},
// 下载中
onProgress: (Map<String, dynamic> message) async {
double progress = message[Constants.progress];
String bookCode = message[Constants.bookCode];
},
// 下载完成
onFinish: (Map<String, dynamic> message) async {
String bookCode = message[Constants.bookCode];
},
// 下载出错
onDownloadError: (Map<String, dynamic> message) async {
String bookCode = message[Constants.bookCode];
int errorCode = message['errorCode'];
String msg = message['msg'];
},
// 打开图书出错
onBookError: (Map<String, dynamic> message) async {
int errorCode = message['errorCode'];
String msg = message['msg'];
},
);
});
copied to clipboard
downloadBook
下载图书
final _ellaSaasFlutterPlugin = EllaSaasFlutter();
/**
* isTry:是否试读模式,true 试读
* bookCode:书籍编号
* isSplit:是否分包下载,默认 false,不分包
*/
_ellaSaasFlutterPlugin.downloadBook({
required bool isTry,
required String bookCode,
bool isSplit = false,
});
copied to clipboard
openBook
打开图书
final _ellaSaasFlutterPlugin = EllaSaasFlutter();
/// isTry:是否试读模式,true 试读
/// bookCode:书籍编号
/// bookPlayMode:书籍播放模式,精读模式:0,泛读模式:1,伴读模式:3
/// startPage:打开书籍的时的起始页
_ellaSaasFlutterPlugin.openBook({
required bool isTry,
required String bookCode,
int? bookPlayMode = 0,
String? startPage = '1',
}) ;
copied to clipboard
deleteBook
删除图书
final _ellaSaasFlutterPlugin = EllaSaasFlutter();
final result = await _ellaSaasFlutterPlugin.deleteBook("bookCode");
copied to clipboard
addBookEventHandler
添加阅读器事件监听
final ReadBookFlutter _readBookFlutterPlugin = ReadBookFlutter();
_readBookFlutterPlugin.addBookEventHandler(
// 阅读进度,翻页的时候回调
onProgressChanged: (Map<String, dynamic>? message) async {
int currentPage = message?[Constants.currentPage];
int totalPage = message?[Constants.totalPage];
},
// 伴读模式下,伴读资源准备完成后回调
onTipsEnable: (Map<String, dynamic>? message) async {
bool isEnable = message?[Constants.isEnable];
},
// 阅读器准备完成的回调,这是可以操作阅读器了
onControllerReady: (Map<String, dynamic>? message) async {
var bookPlayMode = await _readBookFlutterPlugin.getBookPlayMode();
},
// 伴读的内容是否已经展开的回调
onTipsShow: (Map<String, dynamic>? message) async {
bool isShow = message?[Constants.isShow];
},
// 试读结束的回调
onTryEnd: (Map<String, dynamic>? message) async {
showTryEndDialog();
},
// 书籍启动并且json解析成功,下一步就要显示书籍画面(如有自定义progress动画展示,可在此进行关闭)
onReaderSuccess: (Map<String, dynamic>? message) async {
},
);
copied to clipboard
getBookPlayMode
获取书籍的播放模式
final ReadBookFlutter _readBookFlutterPlugin = ReadBookFlutter();
// 获取书籍的播放模式,0:精读模式,1:泛读模式,3:伴读模式
var bookPlayMode = await _readBookFlutterPlugin.getBookPlayMode();
copied to clipboard
exit
退出阅读界面,调用这个方法会自动释放阅读器页面占用的资源
final ReadBookFlutter _readBookFlutterPlugin = ReadBookFlutter();
_readBookFlutterPlugin.exit();
copied to clipboard
showTips
打开伴读资源
final ReadBookFlutter _readBookFlutterPlugin = ReadBookFlutter();
_readBookFlutterPlugin.showTips();
copied to clipboard
pageUp
上一页
final ReadBookFlutter _readBookFlutterPlugin = ReadBookFlutter();
_readBookFlutterPlugin.pageUp();
copied to clipboard
pageDown
下一页
final ReadBookFlutter _readBookFlutterPlugin = ReadBookFlutter();
_readBookFlutterPlugin.pageDown();
copied to clipboard
pause
暂停播放
final ReadBookFlutter _readBookFlutterPlugin = ReadBookFlutter();
_readBookFlutterPlugin.pause();
copied to clipboard
resume
继续播放
final ReadBookFlutter _readBookFlutterPlugin = ReadBookFlutter();
_readBookFlutterPlugin.resume();
copied to clipboard
refreshReader
刷新阅读,由试读模式转正式阅读,调用次方法
final ReadBookFlutter _readBookFlutterPlugin = ReadBookFlutter();
_readBookFlutterPlugin.refreshReader();
copied to clipboard
setBookPlayMode
在阅读界面设置书籍的播放模式
final ReadBookFlutter _readBookFlutterPlugin = ReadBookFlutter();
// 0:精读模式,1:泛读模式,3:伴读模式
_readBookFlutterPlugin.setBookPlayMode(0);
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.