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 efe7c8be
authored
2026-06-27 21:30:39 +0800
by
tanghuan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
App版本号改为从 pubspec.yaml 中读取
1 parent
17d6557f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
1 deletions
lib/config/constant.dart
lib/main.dart
pubspec.yaml
lib/config/constant.dart
View file @
efe7c8b
...
@@ -50,7 +50,11 @@ class Constant {
...
@@ -50,7 +50,11 @@ class Constant {
/// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///
///
/// app 版本号规则
/// app 版本号规则
static
const
String
appVersion
=
EnvConfig
.
version
;
///
/// 实际取值来源于 pubspec.yaml 的 version 字段,
/// 在 main.dart 中通过 package_info_plus 读取后赋值;
/// EnvConfig.version 仅作为读取失败时的兜底默认值。
static
String
appVersion
=
EnvConfig
.
version
;
/// 当前的H5业务包的版本
/// 当前的H5业务包的版本
/// 从 key=h5VersionKey 的缓存中获取,获取不到时值时,说明是第一次打开APP,则从基础业务包中读取的。
/// 从 key=h5VersionKey 的缓存中获取,获取不到时值时,说明是第一次打开APP,则从基础业务包中读取的。
...
...
lib/main.dart
View file @
efe7c8b
...
@@ -8,6 +8,7 @@ import 'package:appframe/ui/widgets/ios_edge_swipe_detector.dart';
...
@@ -8,6 +8,7 @@ import 'package:appframe/ui/widgets/ios_edge_swipe_detector.dart';
import
'package:archive/archive.dart'
;
import
'package:archive/archive.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/services.dart'
;
import
'package:package_info_plus/package_info_plus.dart'
;
import
'package:shared_preferences/shared_preferences.dart'
;
import
'package:shared_preferences/shared_preferences.dart'
;
import
'app.dart'
;
import
'app.dart'
;
...
@@ -16,12 +17,28 @@ void main() async {
...
@@ -16,12 +17,28 @@ void main() async {
WidgetsFlutterBinding
.
ensureInitialized
();
WidgetsFlutterBinding
.
ensureInitialized
();
await
setupLocator
();
await
setupLocator
();
await
_initAppVersion
();
await
_initH5Version
();
await
_initH5Version
();
await
_initIOSGesture
();
await
_initIOSGesture
();
runApp
(
const
App
());
runApp
(
const
App
());
}
}
/// 从 pubspec.yaml 中读取并初始化 APP 版本号
///
/// pubspec.yaml 中的 version 字段作为全局唯一数据源,
/// 避免与构建参数、硬编码出现不一致。
Future
<
void
>
_initAppVersion
()
async
{
try
{
final
info
=
await
PackageInfo
.
fromPlatform
();
if
(
info
.
version
.
isNotEmpty
)
{
Constant
.
appVersion
=
info
.
version
;
}
}
catch
(
e
)
{
debugPrint
(
'读取 APP 版本号失败,使用默认值:
$e
'
);
}
}
Future
<
void
>
_initH5Version
()
async
{
Future
<
void
>
_initH5Version
()
async
{
// 1 读取保存的H5版本
// 1 读取保存的H5版本
var
h5Version
=
getIt
.
get
<
SharedPreferences
>().
getString
(
Constant
.
h5VersionKey
);
var
h5Version
=
getIt
.
get
<
SharedPreferences
>().
getString
(
Constant
.
h5VersionKey
);
...
...
pubspec.yaml
View file @
efe7c8b
...
@@ -18,6 +18,7 @@ dependencies:
...
@@ -18,6 +18,7 @@ dependencies:
archive
:
^4.0.7
archive
:
^4.0.7
connectivity_plus
:
^7.0.0
connectivity_plus
:
^7.0.0
device_info_plus
:
^11.5.0
device_info_plus
:
^11.5.0
package_info_plus
:
^8.3.1
dio
:
^5.9.0
dio
:
^5.9.0
equatable
:
^2.0.7
equatable
:
^2.0.7
get_it
:
^8.2.0
get_it
:
^8.2.0
...
...
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