补充提交处理BUG
This commit is contained in:
parent
8209b12459
commit
e34234da09
|
|
@ -0,0 +1,109 @@
|
|||
@echo off
|
||||
SETLOCAL EnableDelayedExpansion
|
||||
|
||||
:: 设置 UTF-8 代码页以支持中文显示
|
||||
chcp 65001 > nul
|
||||
|
||||
:: 获取项目根目录
|
||||
for %%I in ("%~dp0.") do set "PROJECT_DIR=%%~fI"
|
||||
|
||||
:: 1. 强制终止所有Java进程(Gradle相关)
|
||||
echo Terminating processes...
|
||||
taskkill /f /im java.exe 2>nul
|
||||
taskkill /f /im gradlew.exe 2>nul
|
||||
timeout /t 2 /nobreak >nul
|
||||
|
||||
:: 修复后的Flutter构建脚本
|
||||
echo Running flutter clean...
|
||||
call flutter clean
|
||||
if !ERRORLEVEL! neq 0 (
|
||||
echo flutter clean failed with error: !ERRORLEVEL!
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:: 3. 强制删除构建目录(带重试机制)
|
||||
echo Removing residual files
|
||||
call :ForceDelete "build"
|
||||
call :ForceDelete ".dart_tool"
|
||||
call :ForceDelete "pubspec.lock"
|
||||
|
||||
echo Running flutter pub get...
|
||||
call flutter pub get
|
||||
if !ERRORLEVEL! neq 0 (
|
||||
echo flutter pub get failed with error: !ERRORLEVEL!
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo Running build_runner...
|
||||
call flutter packages pub run build_runner build --delete-conflicting-outputs
|
||||
if !ERRORLEVEL! neq 0 (
|
||||
echo build_runner failed with error: !ERRORLEVEL!
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo Building release APK...
|
||||
call flutter build apk --release
|
||||
if !ERRORLEVEL! neq 0 (
|
||||
echo APK build failed with error: !ERRORLEVEL!
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:: 新增:打开APK所在文件夹
|
||||
echo Opening APK directory
|
||||
if exist "build\app\outputs\flutter-apk\" (
|
||||
explorer "build\app\outputs\flutter-apk\"
|
||||
) else (
|
||||
echo APK directory does not exist
|
||||
)
|
||||
|
||||
echo.
|
||||
echo All steps completed successfully!
|
||||
echo APK file generated at: %PROJECT_DIR%\build\app\outputs\flutter-apk\
|
||||
echo.
|
||||
timeout /t 3 /nobreak >nul
|
||||
exit /b 0
|
||||
|
||||
:: 函数区 -------------------------------------------------
|
||||
:ForceDelete
|
||||
setlocal
|
||||
set "target=%~1"
|
||||
set "max_retries=3"
|
||||
set "retry_delay=1"
|
||||
|
||||
:: 检查目标是否存在
|
||||
if not exist "%target%" (
|
||||
endlocal
|
||||
goto :eof
|
||||
)
|
||||
|
||||
:: 尝试多次删除
|
||||
for /l %%i in (1,1,%max_retries%) do (
|
||||
echo Attempting to delete %target% (try %%i of %max_retries%)
|
||||
|
||||
:: 先尝试删除文件
|
||||
del /f /q /s "%target%\*" 2>nul
|
||||
:: 再尝试删除目录
|
||||
rmdir /s /q "%target%" 2>nul
|
||||
|
||||
:: 检查是否删除成功
|
||||
if not exist "%target%" (
|
||||
echo Successfully deleted %target%
|
||||
endlocal
|
||||
goto :eof
|
||||
)
|
||||
|
||||
:: 如果未成功,等待后重试
|
||||
if %%i lss %max_retries% (
|
||||
timeout /t %retry_delay% /nobreak >nul
|
||||
set /a retry_delay*=2 :: 指数退避策略
|
||||
)
|
||||
)
|
||||
|
||||
:: 如果所有尝试都失败
|
||||
echo Warning: Could not completely delete %target%, some files may be in use
|
||||
endlocal
|
||||
goto :eof
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
/// 全局监听应用是否进入后台 或者 前台
|
||||
class AppStateController extends GetxController with WidgetsBindingObserver {
|
||||
// 响应式变量,存储当前生命周期状态
|
||||
final appLifecycleState = AppLifecycleState.resumed.obs;
|
||||
|
||||
// 便捷方法:判断应用是否在前台
|
||||
bool get isAppInForeground => appLifecycleState.value == AppLifecycleState.resumed;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
WidgetsBinding.instance.addObserver(this); // 注册生命周期监听
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
WidgetsBinding.instance.removeObserver(this); // 移除监听
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
appLifecycleState.value = state; // 更新状态
|
||||
// if (isAppInForeground) {
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// Get.find<UpgradeLogic>().initiateVersionCheck(Get.context!);
|
||||
// });
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
@ -12,18 +12,13 @@ class PermissionDescribePage extends StatefulWidget {
|
|||
final String describe;
|
||||
final List<Permission> permissions;
|
||||
|
||||
const PermissionDescribePage(
|
||||
{required this.title,
|
||||
required this.describe,
|
||||
required this.permissions,
|
||||
super.key});
|
||||
const PermissionDescribePage({required this.title, required this.describe, required this.permissions, super.key});
|
||||
|
||||
@override
|
||||
State<PermissionDescribePage> createState() => _PermissionDescribePageState();
|
||||
}
|
||||
|
||||
class _PermissionDescribePageState extends State<PermissionDescribePage>
|
||||
with WidgetsBindingObserver {
|
||||
class _PermissionDescribePageState extends State<PermissionDescribePage> with WidgetsBindingObserver {
|
||||
Timer? _timerPermission;
|
||||
bool theOpenAppSettings = false;
|
||||
int theExecutionFrequency = 0;
|
||||
|
|
@ -40,7 +35,7 @@ class _PermissionDescribePageState extends State<PermissionDescribePage>
|
|||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
print("-didChangeAppLifecycleState-" + state.toString());
|
||||
print("-didChangeAppLifecycleState-$state");
|
||||
switch (state) {
|
||||
case AppLifecycleState.inactive: // 处于这种状态的应用程序应该假设它们可能在任何时候暂停。
|
||||
break;
|
||||
|
|
@ -97,7 +92,7 @@ class _PermissionDescribePageState extends State<PermissionDescribePage>
|
|||
);
|
||||
}
|
||||
permissions.add(p);
|
||||
} else if (await status.isPermanentlyDenied) {
|
||||
} else if (status.isPermanentlyDenied) {
|
||||
permanentRefusal.add(p);
|
||||
}
|
||||
}
|
||||
|
|
@ -137,8 +132,7 @@ class _PermissionDescribePageState extends State<PermissionDescribePage>
|
|||
|
||||
/// 权限发起请求
|
||||
/// @param List<Permission> permissions 权限集合
|
||||
Future<List<Permission>> getStoragePermission(
|
||||
BuildContext context, List<Permission> permissions,
|
||||
Future<List<Permission>> getStoragePermission(BuildContext context, List<Permission> permissions,
|
||||
[int executionFrequency = 0]) async {
|
||||
Map<Permission, PermissionStatus> statusRes = await permissions.request();
|
||||
|
||||
|
|
@ -180,8 +174,7 @@ class _PermissionDescribePageState extends State<PermissionDescribePage>
|
|||
executionFrequency++;
|
||||
}
|
||||
if (executionFrequency <= 1) {
|
||||
var res =
|
||||
await getStoragePermission(context, [key], executionFrequency);
|
||||
var res = await getStoragePermission(context, [key], executionFrequency);
|
||||
permanentRefusal.addAll(res);
|
||||
} else {
|
||||
permanentRefusal.add(key);
|
||||
|
|
@ -215,7 +208,7 @@ class _PermissionDescribePageState extends State<PermissionDescribePage>
|
|||
color: Colors.black.withOpacity(0.5), // 阴影颜色
|
||||
spreadRadius: 2, // 水平和垂直方向上扩展范围
|
||||
blurRadius: 4, // 模糊半径
|
||||
offset: Offset(0, 3), // X 和 Y 的偏移量
|
||||
offset: const Offset(0, 3), // X 和 Y 的偏移量
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
@ -239,7 +232,7 @@ class PermissionDescribeUtil {
|
|||
|
||||
PermissionDescribeUtil._internal();
|
||||
|
||||
static get instance => _instance ??= PermissionDescribeUtil._internal();
|
||||
static PermissionDescribeUtil get instance => _instance ??= PermissionDescribeUtil._internal();
|
||||
|
||||
/// 发起权限请求
|
||||
Future<void> toLaunchPermissionRequest(
|
||||
|
|
@ -257,7 +250,7 @@ class PermissionDescribeUtil {
|
|||
}
|
||||
}
|
||||
if (isGranted) {
|
||||
Navigator.of(Get.context ?? context).push(PageRouteBuilder(
|
||||
await Navigator.of(Get.context ?? context).push(PageRouteBuilder(
|
||||
opaque: false,
|
||||
pageBuilder: (context, animation, secondaryAnimation) {
|
||||
return PermissionDescribePage(
|
||||
|
|
|
|||
Loading…
Reference in New Issue