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

图书馆页检测版本

上级 f68c911e
part of library;
class LibraryController extends GetxController with GetTickerProviderStateMixin{
final BuildContext context;
LibraryController(this.context);
// 分类数据
List<CategoryModel> categories = [];
// 标签数据
......@@ -49,6 +51,8 @@ class LibraryController extends GetxController with GetTickerProviderStateMixin{
late AnimationController _controller;
bool _show = false;
late UModel _getModel;
bool get show => _show;
void setShow(bool value) {
_show = !value;
......@@ -85,6 +89,10 @@ class LibraryController extends GetxController with GetTickerProviderStateMixin{
_getTabs();
// 获取广告数据
_getAds();
// 检测版本
// if(Platform.isAndroid){
// _checkUpdates();
// }
// Map<String, dynamic> data = {
// 'types': 1,
......@@ -378,6 +386,165 @@ class LibraryController extends GetxController with GetTickerProviderStateMixin{
}
}
void _checkUpdates() async {
UModel model = await MineAPI.update();
_getModel = model;
final packageInfo = await PackageInfo.fromPlatform();
int update = verifyVersion(model.version!,packageInfo.version);
if (update == 1) {
_showUpdateDialog(false);
}
}
int verifyVersion(String newVersion, String oldVersion) {
List<String> newVersionArr = newVersion.split('.');
List<String> oldVersionArr = oldVersion.split('.');
for (int i = 0; i < 3; i++) {
int newVersionNumber = int.parse(newVersionArr[i]);
int oldVersionNumber = int.parse(oldVersionArr[i]);
if (newVersionNumber < oldVersionNumber) {
return -1; // 新版本小于旧版本
} else if (newVersionNumber > oldVersionNumber) {
return 1; // 新版本大于旧版本
}
}
return 0; // 两个版本号相等
}
_showUpdateDialog(bool forcedUpgrade) {
showDialog(
context: context,
barrierDismissible: !forcedUpgrade,
builder: (BuildContext context) {
return WillPopScope(
onWillPop: () => Future.value(!forcedUpgrade),
child: AlertDialog(
insetPadding: EdgeInsets.zero, // 设置水平边距
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0.w),
),
// 去除操作按钮区域的内边距
actionsPadding: EdgeInsets.zero,
actions: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(
height: 25.5.w,
),
SizedBox(
height: 92.w,
width: 92.w,
child: Image.asset('assets/images/app_update.png'),
),
SizedBox(
height: 13.w,
),
Text(
"版本更新",
style: TextStyle(
fontSize: 14.w,
color: Colours.c3,
fontWeight: Fonts.medium),
),
Padding(
padding: EdgeInsets.only(top: 5.5.w),
child: Text(
'发现新版本V${_getModel.version}',
style: TextStyle(
fontSize: 10.w,
color: Colours.c9,
fontWeight: Fonts.medium),
),
),
SizedBox(
height: 22.w,
),
Container(
height: 1, // 设置分割线的高度
width: 216.5.w, // 设置分割线的宽度
color: Colours.cLine, // 设置分割线的颜色
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
if (!forcedUpgrade)
Padding(padding: EdgeInsets.only(right: 28.w),
child: GestureDetector(
child:
Container(
width: 85.w,
color: Colours.cFF,
alignment: Alignment.center,
child: const Text(
'稍后再说',
style: TextStyle(
color: Colours.c6,
fontSize: 15,
fontWeight: Fonts.medium),
),
),
onTap: () => Navigator.of(context).pop(),
),),
Container(
height: 39.5.w, // 设置分割线的高度
width: 1, // 设置分割线的宽度
color: Colours.cLine, // 设置分割线的颜色
),
Padding(padding: EdgeInsets.only(left: 28.w),
child: GestureDetector(
child: Container(
width: 85.w,
color: Colours.cFF,
alignment: Alignment.center,
child: const Text(
'立即更新',
style: TextStyle(
color: Colours.cAB1941,
fontSize: 15,
fontWeight: Fonts.boldSemi),
),
),
onTap: () {
_appUpdate();
if (!forcedUpgrade) {
Navigator.of(context).pop();
}
},
),
),
],
),
],
),
],
),
],
),
);
},
);
}
/// TODO: 苹果市场app地址
_appUpdate() {
UpdateModel model = UpdateModel(
_getModel.url!,
"zijing.apk",
"ic_launcher",
'https://itunes.apple.com/cn/app/抖音/id1142110895',
);
AzhonAppUpdate.update(model).then((value) => debugPrint('$value'));
}
}
\ No newline at end of file
library library;
import 'dart:convert';
import 'dart:io';
import 'package:azlistview/azlistview.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_update/azhon_app_update.dart';
import 'package:flutter_app_update/update_model.dart';
import 'package:flutter_book/apis/index.dart';
import 'package:flutter_book/theme.dart';
import 'package:flutter_book/utils/index.dart';
......@@ -12,6 +15,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:go_router/go_router.dart';
import 'package:ionicons/ionicons.dart';
import 'package:package_info_plus/package_info_plus.dart';
import '../../models/index.dart';
import '../../routes/index.dart';
......
......@@ -9,10 +9,11 @@ class LibraryPage extends StatefulWidget {
class _LibraryPageState extends State<LibraryPage> {
@override
Widget build(BuildContext context) {
return GetBuilder<LibraryController>(
init: LibraryController(),
init: LibraryController(context),
builder: (controller) => Scaffold(
appBar: AppBar(
title: const Text('图书馆'),
......@@ -131,7 +132,7 @@ class _LibraryPageState extends State<LibraryPage> {
height: 43.w,
color: Colours.cF9,
child: GetBuilder<LibraryController>(
init: LibraryController(),
init: LibraryController(context),
// id: 'label',
builder:(controller) =>ListView.builder(
scrollDirection:Axis.horizontal ,
......@@ -153,7 +154,7 @@ class _LibraryPageState extends State<LibraryPage> {
return Container(
height: 38.w,
child: GetBuilder<LibraryController>(
init: LibraryController(),
init: LibraryController(context),
builder: (controller) =>ListView.builder(
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context, int index){
......
......@@ -45,27 +45,9 @@ class _ReadOfflinePageState extends State<ReadPage> {
),
centerTitle: false,
actions: const [
// GestureDetector(
// onTap: () {
// readController.getBookDown();
// },
// child: Text(
// readController.existDownFile == true?'':'离线阅读',
// style: TextStyle(
// fontSize: 14.w, color: Colours.c3),
// ))
],
),
resizeToAvoidBottomInset: false,
// floatingActionButton: readController.show&& !readController.toolModel.selected?GestureDetector(
// onTap: (){
// readController.setShowChat(true);
// readController.setChatType(0);
// },
// child: Image.asset('assets/images/chat.png'),
// ):null,
// // floatingActionButtonAnimator: const NoAnimationFabAnimator(),
// floatingActionButtonLocation:MyFloatingActionButtonLocation(),
body: Container(
color: Colors.white,
child: Stack(
......@@ -81,11 +63,6 @@ class _ReadOfflinePageState extends State<ReadPage> {
// http的请求也不做限制
mixedContentMode:MixedContentMode.MIXED_CONTENT_ALWAYS_ALLOW
),
// initialOptions: InAppWebViewGroupOptions(
// crossPlatform: InAppWebViewOptions(
// clearCache: true
// )
// ),
contextMenu: ContextMenu(
// options: ContextMenuOptions(hideDefaultSystemContextMenuItems: true),
settings: ContextMenuSettings(
......@@ -151,12 +128,6 @@ class _ReadOfflinePageState 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年中国共产党成立后,确立了新民主主义革命的正确道路,让灾难深重的中'
// '国人民看到了新的希望、有了新的依靠。我们党探索出农村包围城市、武装夺取政权的正确革命道路,“唤起工'
// '农千百万”“夺过鞭子揍敌人”,经过土地革命战争、抗日战争、解放战争,推翻了压在中国人民头上的帝国主义、'
// '封建主义、官僚资本主义“三座大山”,建立了人民当家作主的中华人民共和国,彻底结束了近代以来中国内忧外患、积贫积弱的悲惨境地,开启了中华民族发展进步的新纪元'
// );
});
// 监听讨论回调
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论