Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ethan
/
appframe
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit 2fd34d99
authored
2026-04-28 23:34:00 +0800
by
tanghuan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1.APP唤醒时,检测APP的版本号;2.设置界面增加打开下载界面的按钮。
1 parent
bd06b441
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
247 additions
and
17 deletions
lib/bloc/web_cubit.dart
lib/ui/pages/setting/setting_page.dart
lib/ui/pages/web_page.dart
lib/bloc/web_cubit.dart
View file @
2fd34d9
...
@@ -18,10 +18,10 @@ import 'package:equatable/equatable.dart';
...
@@ -18,10 +18,10 @@ import 'package:equatable/equatable.dart';
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
import
'package:fluttertoast/fluttertoast.dart'
;
import
'package:fluttertoast/fluttertoast.dart'
;
import
'package:fluwx/fluwx.dart'
;
import
'package:path_provider/path_provider.dart'
;
import
'package:path_provider/path_provider.dart'
;
import
'package:permission_handler/permission_handler.dart'
;
import
'package:permission_handler/permission_handler.dart'
;
import
'package:shared_preferences/shared_preferences.dart'
;
import
'package:shared_preferences/shared_preferences.dart'
;
import
'package:url_launcher/url_launcher.dart'
;
import
'package:uuid/uuid.dart'
;
import
'package:uuid/uuid.dart'
;
import
'package:volume_controller/volume_controller.dart'
;
import
'package:volume_controller/volume_controller.dart'
;
import
'package:webview_flutter/webview_flutter.dart'
;
import
'package:webview_flutter/webview_flutter.dart'
;
...
@@ -34,6 +34,7 @@ class WebState extends Equatable {
...
@@ -34,6 +34,7 @@ class WebState extends Equatable {
final
bool
loaded
;
final
bool
loaded
;
final
bool
isUpgrading
;
final
bool
isUpgrading
;
final
bool
suggestUpgrade
;
final
bool
suggestUpgrade
;
final
bool
suggestAppUpgrade
;
final
String
title
;
final
String
title
;
final
int
titleColor
;
final
int
titleColor
;
...
@@ -75,6 +76,7 @@ class WebState extends Equatable {
...
@@ -75,6 +76,7 @@ class WebState extends Equatable {
this
.
loaded
=
false
,
this
.
loaded
=
false
,
this
.
isUpgrading
=
false
,
this
.
isUpgrading
=
false
,
this
.
suggestUpgrade
=
false
,
this
.
suggestUpgrade
=
false
,
this
.
suggestAppUpgrade
=
false
,
this
.
title
=
''
,
this
.
title
=
''
,
this
.
titleColor
=
0xFFFFFFFF
,
this
.
titleColor
=
0xFFFFFFFF
,
this
.
bgColor
=
0xFF7691FA
,
this
.
bgColor
=
0xFF7691FA
,
...
@@ -102,6 +104,7 @@ class WebState extends Equatable {
...
@@ -102,6 +104,7 @@ class WebState extends Equatable {
bool
?
loaded
,
bool
?
loaded
,
bool
?
isUpgrading
,
bool
?
isUpgrading
,
bool
?
suggestUpgrade
,
bool
?
suggestUpgrade
,
bool
?
suggestAppUpgrade
,
String
?
title
,
String
?
title
,
int
?
titleColor
,
int
?
titleColor
,
int
?
bgColor
,
int
?
bgColor
,
...
@@ -129,6 +132,7 @@ class WebState extends Equatable {
...
@@ -129,6 +132,7 @@ class WebState extends Equatable {
loaded:
loaded
??
this
.
loaded
,
loaded:
loaded
??
this
.
loaded
,
isUpgrading:
isUpgrading
??
this
.
isUpgrading
,
isUpgrading:
isUpgrading
??
this
.
isUpgrading
,
suggestUpgrade:
suggestUpgrade
??
this
.
suggestUpgrade
,
suggestUpgrade:
suggestUpgrade
??
this
.
suggestUpgrade
,
suggestAppUpgrade:
suggestAppUpgrade
??
this
.
suggestAppUpgrade
,
title:
title
??
this
.
title
,
title:
title
??
this
.
title
,
titleColor:
titleColor
??
this
.
titleColor
,
titleColor:
titleColor
??
this
.
titleColor
,
bgColor:
bgColor
??
this
.
bgColor
,
bgColor:
bgColor
??
this
.
bgColor
,
...
@@ -158,6 +162,7 @@ class WebState extends Equatable {
...
@@ -158,6 +162,7 @@ class WebState extends Equatable {
loaded
,
loaded
,
isUpgrading
,
isUpgrading
,
suggestUpgrade
,
suggestUpgrade
,
suggestAppUpgrade
,
title
,
title
,
titleColor
,
titleColor
,
bgColor
,
bgColor
,
...
@@ -278,10 +283,18 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
...
@@ -278,10 +283,18 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
String
version
=
response
.
data
[
'version'
]
as
String
;
String
version
=
response
.
data
[
'version'
]
as
String
;
String
force
=
response
.
data
[
'force'
]
as
String
;
String
force
=
response
.
data
[
'force'
]
as
String
;
String
zip
=
response
.
data
[
'zip'
]
as
String
;
String
zip
=
response
.
data
[
'zip'
]
as
String
;
String
appversionCheck
=
response
.
data
[
'appversionCheck'
]
as
String
?
??
'0'
;
String
appversionAndroid
=
response
.
data
[
'appversionAndroid'
]
as
String
?
??
''
;
String
appversionIos
=
response
.
data
[
'appversionIos'
]
as
String
?
??
''
;
return
{
return
{
'version'
:
version
,
'version'
:
version
,
'force'
:
force
,
'force'
:
force
,
'zip'
:
'
$zip$version
.zip'
,
'zip'
:
'
$zip$version
.zip'
,
'appversionCheck'
:
appversionCheck
,
'appversionAndroid'
:
appversionAndroid
,
'appversionIos'
:
appversionIos
,
};
};
}
finally
{
}
finally
{
dio
.
close
(
force:
true
);
dio
.
close
(
force:
true
);
...
@@ -609,34 +622,198 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
...
@@ -609,34 +622,198 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
///
///
/// 升级提示
/// 升级提示
///
///
void
suggestUpgrade
(
BuildContext
ctx
)
{
Future
<
void
>
suggestUpgrade
(
BuildContext
context
)
async
{
showDialog
(
// showDialog(
context:
ctx
,
// context: ctx,
// barrierDismissible: false,
// builder: (BuildContext context) {
// return AlertDialog(
// title: Text('温馨提示'),
// content: Text('资源已更新为最新版本,是否现在进行加载?'),
// actions: <Widget>[
// TextButton(
// child: Text('取消'),
// onPressed: () {
// Navigator.of(context).pop();
// emit(state.copyWith(suggestUpgrade: false));
// },
// ),
// TextButton(
// child: Text('确定'),
// onPressed: () {
// Navigator.of(context).pop();
// emit(state.copyWith(suggestUpgrade: false));
// router.go('/reload');
// },
// ),
// ],
// );
// },
// );
final
result
=
await
showDialog
(
context:
context
,
barrierDismissible:
false
,
barrierDismissible:
false
,
builder:
(
BuildContext
context
)
{
builder:
(
BuildContext
context
)
{
return
AlertDialog
(
return
AlertDialog
(
title:
Text
(
'温馨提示'
),
shape:
RoundedRectangleBorder
(
content:
Text
(
'资源已更新为最新版本,是否现在进行加载?'
),
borderRadius:
BorderRadius
.
all
(
actions:
<
Widget
>[
Radius
.
circular
(
5
),
TextButton
(
),
child:
Text
(
'取消'
),
),
title:
Text
(
'资源包更新'
,
style:
TextStyle
(
fontSize:
17
,
color:
Color
(
0xFF000000
),
// fontWeight: FontWeight.bold,
),
textAlign:
TextAlign
.
center
,
),
content:
Text
.
rich
(
TextSpan
(
children:
[
TextSpan
(
text:
'资源更新包已准备就绪,是否立即加载?'
,
style:
TextStyle
(
color:
Color
(
0xFF666666
),
fontSize:
14
),
),
],
),
),
actions:
[
Table
(
children:
[
TableRow
(
children:
[
TableCell
(
child:
TextButton
(
onPressed:
()
{
onPressed:
()
{
Navigator
.
of
(
context
).
pop
();
Navigator
.
of
(
context
).
pop
();
emit
(
state
.
copyWith
(
suggestUpgrade:
false
));
},
},
style:
TextButton
.
styleFrom
(
foregroundColor:
Color
(
0xFF666666
),
textStyle:
TextStyle
(
fontSize:
17
),
padding:
EdgeInsets
.
zero
,
shape:
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
zero
,
),
),
TextButton
(
),
child:
Text
(
'确定'
),
child:
Text
(
'稍后再说'
),
),
),
TableCell
(
child:
TextButton
(
onPressed:
()
{
onPressed:
()
{
Navigator
.
of
(
context
).
pop
();
Navigator
.
of
(
context
).
pop
(
'OK'
);
},
style:
TextButton
.
styleFrom
(
foregroundColor:
Color
(
0xFF7691FA
),
textStyle:
TextStyle
(
fontSize:
17
),
minimumSize:
Size
.
fromHeight
(
40
),
padding:
EdgeInsets
.
zero
,
shape:
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
zero
,
),
),
child:
Text
(
'立即加载'
),
),
),
],
),
],
),
],
);
},
);
emit
(
state
.
copyWith
(
suggestUpgrade:
false
));
emit
(
state
.
copyWith
(
suggestUpgrade:
false
));
if
(
result
!=
null
)
{
router
.
go
(
'/reload'
);
router
.
go
(
'/reload'
);
}
}
Future
<
void
>
suggestAppUpdate
(
BuildContext
context
)
async
{
final
result
=
await
showDialog
(
context:
context
,
barrierDismissible:
false
,
builder:
(
BuildContext
context
)
{
return
AlertDialog
(
shape:
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
all
(
Radius
.
circular
(
5
),
),
),
title:
Text
(
'发现新版本'
,
style:
TextStyle
(
fontSize:
17
,
color:
Color
(
0xFF000000
),
// fontWeight: FontWeight.bold,
),
textAlign:
TextAlign
.
center
,
),
content:
Text
.
rich
(
TextSpan
(
children:
[
TextSpan
(
text:
'已有新版 APP 可供下载,建议您立即下载更新以获得更好体验。'
,
style:
TextStyle
(
color:
Color
(
0xFF666666
),
fontSize:
14
),
),
],
),
),
actions:
[
Table
(
children:
[
TableRow
(
children:
[
TableCell
(
child:
TextButton
(
onPressed:
()
{
Navigator
.
of
(
context
).
pop
();
},
style:
TextButton
.
styleFrom
(
foregroundColor:
Color
(
0xFF666666
),
textStyle:
TextStyle
(
fontSize:
17
),
padding:
EdgeInsets
.
zero
,
shape:
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
zero
,
),
),
child:
Text
(
'稍后再说'
),
),
),
TableCell
(
child:
TextButton
(
onPressed:
()
{
Navigator
.
of
(
context
).
pop
(
'OK'
);
},
},
style:
TextButton
.
styleFrom
(
foregroundColor:
Color
(
0xFF7691FA
),
textStyle:
TextStyle
(
fontSize:
17
),
minimumSize:
Size
.
fromHeight
(
40
),
padding:
EdgeInsets
.
zero
,
shape:
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
zero
,
),
),
child:
Text
(
'打开下载页面'
),
),
),
],
),
],
),
),
],
],
);
);
},
},
);
);
emit
(
state
.
copyWith
(
suggestAppUpgrade:
false
));
if
(
result
!=
null
)
{
final
uri
=
Uri
.
parse
(
'https://www.banxe.cn/apps/pro.html'
);
if
(
await
canLaunchUrl
(
uri
))
{
await
launchUrl
(
uri
,
mode:
LaunchMode
.
externalApplication
);
}
}
}
}
///
///
...
@@ -1138,6 +1315,9 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
...
@@ -1138,6 +1315,9 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
/// H5资源已下载标志(本次生命周期内)
/// H5资源已下载标志(本次生命周期内)
bool
_hasDownloadedH5
=
false
;
bool
_hasDownloadedH5
=
false
;
/// APP版本检测上次执行时间(2小时内只执行一次)
DateTime
?
_lastAppVersionCheckTime
;
///
///
/// 从后台恢复时进行版本检测
/// 从后台恢复时进行版本检测
/// 参照 _init() 方法中的版本检测逻辑
/// 参照 _init() 方法中的版本检测逻辑
...
@@ -1154,17 +1334,39 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
...
@@ -1154,17 +1334,39 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
var
versionConfig
=
await
_getVersionConfig
();
var
versionConfig
=
await
_getVersionConfig
();
var
configVersion
=
versionConfig
[
'version'
]
as
String
;
var
configVersion
=
versionConfig
[
'version'
]
as
String
;
var
downloadUrl
=
versionConfig
[
'zip'
]
as
String
;
var
downloadUrl
=
versionConfig
[
'zip'
]
as
String
;
var
appversionCheck
=
versionConfig
[
'appversionCheck'
]
as
String
;
var
appversionAndroid
=
versionConfig
[
'appversionAndroid'
]
as
String
;
var
appversionIos
=
versionConfig
[
'appversionIos'
]
as
String
;
if
(
appversionCheck
==
'1'
)
{
final
now
=
DateTime
.
now
();
if
(
_lastAppVersionCheckTime
==
null
||
now
.
difference
(
_lastAppVersionCheckTime
!).
inHours
>=
2
)
{
if
((
Platform
.
isAndroid
&&
appversionAndroid
!=
''
&&
appversionAndroid
!=
Constant
.
appVersion
)
||
(
Platform
.
isIOS
&&
appversionIos
!=
''
&&
appversionIos
!=
Constant
.
appVersion
))
{
emit
(
state
.
copyWith
(
suggestAppUpgrade:
true
));
}
_lastAppVersionCheckTime
=
now
;
}
}
if
(
Constant
.
needUpgrade
&&
curVersion
!=
configVersion
)
{
if
(
Constant
.
needUpgrade
&&
curVersion
!=
configVersion
)
{
await
_downloadH5Zip
(
configVersion
,
downloadUrl
);
// 闭包中提前捕获变量,确保回调执行时读取的是当前值
_setH5Version
(
configVersion
);
final
capturedConfigVersion
=
configVersion
;
_downloadH5Zip
(
capturedConfigVersion
,
downloadUrl
).
then
((
_
)
{
_setH5Version
(
capturedConfigVersion
);
_hasDownloadedH5
=
true
;
_hasDownloadedH5
=
true
;
emit
(
state
.
copyWith
(
suggestUpgrade:
true
));
emit
(
state
.
copyWith
(
suggestUpgrade:
true
));
}).
catchError
((
e
)
{
debugPrint
(
'后台H5资源下载失败
$e
'
);
}).
whenComplete
(()
{
_isCheckingVersionOfH5
=
false
;
});
}
else
{
// 不需要下载时,立即重置标志
_isCheckingVersionOfH5
=
false
;
}
}
}
catch
(
e
)
{
}
catch
(
e
)
{
debugPrint
(
'后台H5版本检测失败
$e
'
);
debugPrint
(
'后台H5版本检测失败
$e
'
);
}
finally
{
_isCheckingVersionOfH5
=
false
;
}
}
}
}
...
...
lib/ui/pages/setting/setting_page.dart
View file @
2fd34d9
...
@@ -6,6 +6,7 @@ import 'package:appframe/config/env_config.dart';
...
@@ -6,6 +6,7 @@ import 'package:appframe/config/env_config.dart';
import
'package:appframe/config/routes.dart'
;
import
'package:appframe/config/routes.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
import
'package:url_launcher/url_launcher.dart'
;
class
SettingPage
extends
StatelessWidget
{
class
SettingPage
extends
StatelessWidget
{
const
SettingPage
({
super
.
key
});
const
SettingPage
({
super
.
key
});
...
@@ -158,6 +159,31 @@ class SettingPage extends StatelessWidget {
...
@@ -158,6 +159,31 @@ class SettingPage extends StatelessWidget {
),
),
),
),
const
SizedBox
(
height:
8
),
const
SizedBox
(
height:
8
),
Card
(
margin:
const
EdgeInsets
.
symmetric
(
horizontal:
16
,
vertical:
2
),
shape:
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
circular
(
6
),
),
child:
Column
(
children:
[
ListTile
(
leading:
const
Icon
(
Icons
.
download
,
size:
20
),
title:
const
Text
(
'下载与更新'
,
style:
TextStyle
(
fontSize:
14
)),
onTap:
()
async
{
final
uri
=
Uri
.
parse
(
'https://www.banxe.cn/apps/pro.html'
);
if
(
await
canLaunchUrl
(
uri
))
{
await
launchUrl
(
uri
,
mode:
LaunchMode
.
externalApplication
);
}
},
contentPadding:
const
EdgeInsets
.
symmetric
(
horizontal:
16
,
vertical:
4
),
trailing:
const
Icon
(
Icons
.
arrow_forward_ios
,
size:
14
),
dense:
true
,
visualDensity:
VisualDensity
.
compact
,
),
],
),
),
const
SizedBox
(
height:
8
),
...
customerService
,
...
customerService
,
Card
(
Card
(
margin:
const
EdgeInsets
.
symmetric
(
horizontal:
16
,
vertical:
2
),
margin:
const
EdgeInsets
.
symmetric
(
horizontal:
16
,
vertical:
2
),
...
...
lib/ui/pages/web_page.dart
View file @
2fd34d9
...
@@ -148,6 +148,8 @@ class WebPage extends StatelessWidget {
...
@@ -148,6 +148,8 @@ class WebPage extends StatelessWidget {
context
.
read
<
WebCubit
>().
chooseImage
(
context
);
context
.
read
<
WebCubit
>().
chooseImage
(
context
);
}
else
if
(
state
.
chooseVideoCmdFlag
)
{
}
else
if
(
state
.
chooseVideoCmdFlag
)
{
context
.
read
<
WebCubit
>().
chooseVideo
(
context
);
context
.
read
<
WebCubit
>().
chooseVideo
(
context
);
}
else
if
(
state
.
suggestAppUpgrade
)
{
context
.
read
<
WebCubit
>().
suggestAppUpdate
(
context
);
}
}
},
},
),
),
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment