fix:修复 print 打印无效的问题,并将 debug 按钮出发机制更新为关于右上角点击

This commit is contained in:
anfe 2024-04-29 16:18:43 +08:00
parent b920ff066c
commit 5a492b26b5
9 changed files with 211 additions and 152 deletions

View File

@ -1,6 +1,8 @@
import 'package:flutter/foundation.dart';
import 'dart:io';
import 'package:star_lock/debug/debug_console.dart';
class AppLog {
static bool _printLog = false;
static bool _onlyError = false;
@ -17,6 +19,7 @@ class AppLog {
if(error){
msg = '----->>> $msg';
}
DebugConsole.info(msg);
print(msg);
}
}

View File

@ -201,10 +201,6 @@ class DebugConsole extends StatefulWidget {
controller ??= DebugConsole.instance;
runZoned(body,
zoneSpecification: ZoneSpecification(
print: (Zone self, ZoneDelegate parent, Zone zone, String line) {
controller!.log(line);
parent.print(zone, line);
},
handleUncaughtError: (Zone self, ZoneDelegate parent, Zone zone,
Object error, StackTrace stackTrace) {
controller!.log(error,

View File

@ -11,10 +11,11 @@ class DeBug {
static bool open = false;
static bool openInfo = false;
static late OverlayEntry overlayEntry;
static void showFloatWidget() {
Rx<Offset> offset = Offset(20, 100).obs; //
OverlayEntry overlayEntry = OverlayEntry(builder: (context) {
overlayEntry = OverlayEntry(builder: (context) {
return Obx(() => Positioned(
left: offset.value.dx,
top: offset.value.dy,
@ -54,5 +55,9 @@ class DeBug {
Get.key.currentState?.overlay?.insert(overlayEntry);
}
static void closeFloatWidget() {
overlayEntry.remove();
}
DeBug();
}

View File

@ -57,7 +57,7 @@ class F {
case Flavor.sky:
return false;
case Flavor.xhj:
return false;
return true;
default:
return false;
}

View File

@ -18,13 +18,9 @@ FutureOr<void> main() async {
//
await _initTranslation();
if(F.debug){
DebugConsole.listen(() {
runApp(const MyApp());
});
}else{
DebugConsole.listen(() {
runApp(const MyApp());
}
});
if (AppPlatform.isAndroid) {
SystemUiOverlayStyle systemUiOverlayStyle =

View File

@ -0,0 +1,39 @@
import 'dart:async';
import 'package:get/get.dart';
import 'package:star_lock/debug/debug_tool.dart';
import 'package:star_lock/tools/storage.dart';
class AboutConsole extends GetxController {
int _clickCount = 0;
Timer? _timer;
void handleTap() async {
_clickCount++;
if (_clickCount == 1) {
//
_timer = Timer(const Duration(seconds: 3), () {
// 315
_resetCounter();
});
}
if (_clickCount >= 15) {
_timer?.cancel();
_resetCounter();
bool? openDeBug = await Storage.getBool(isOpenDeBug);
if (openDeBug == true) {
DeBug.closeFloatWidget();
await Storage.setBool(isOpenDeBug, false);
} else {
DeBug.showFloatWidget();
await Storage.setBool(isOpenDeBug, true);
}
}
}
void _resetCounter() {
_clickCount = 0;
}
}

View File

@ -4,6 +4,7 @@ import 'package:get/get.dart';
import 'package:star_lock/appRouters.dart';
import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:star_lock/mine/about/about_console.dart';
import '../../app_settings/app_colors.dart';
import '../../flavors.dart';
@ -43,143 +44,160 @@ class _AboutPageState extends State<AboutPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar(
barTitle: TranslationLoader.lanKeys!.about!.tr,
haveBack: true,
backgroundColor: AppColors.mainColor),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(height: 150.h),
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Image.asset(
F.sw(
defaultCall: () => "images/icon_main_1024.png",
xhjCall: () => "images/icon_main_xhj_1024.png"),
width: 160.w,
height: 160.w),
]),
SizedBox(height: 20.h),
Text(
"${F.title} $version+$buildNumber",
style: TextStyle(fontSize: 24.sp, color: AppColors.blackColor),
),
SizedBox(height: 20.h),
Text(
F.apiPrefix,
style: TextStyle(fontSize: 24.sp, color: AppColors.blackColor),
),
SizedBox(
height: 60.h,
),
CommonItem(
leftTitel: TranslationLoader.lanKeys!.introduce!.tr,
rightTitle: "",
isHaveLine: false,
isHaveDirection: true,
action: () {
Navigator.pushNamed(context, Routers.webviewShowPage,
arguments: {
"url": XSConstantMacro.introduceURL,
"title": '介绍'.tr
});
}),
Divider(
height: 1,
color: AppColors.greyLineColor,
indent: 20.w,
endIndent: 20.w,
),
CommonItem(
leftTitel: TranslationLoader.lanKeys!.userAgreement!.tr,
rightTitle: "",
isHaveLine: false,
isHaveDirection: true,
action: () {
Get.toNamed(Routers.webviewShowPage, arguments: {
"url": XSConstantMacro.userAgreementURL,
"title": '用户协议'.tr
});
}),
Divider(
height: 1,
color: AppColors.greyLineColor,
indent: 20.w,
endIndent: 20.w,
),
CommonItem(
leftTitel: TranslationLoader.lanKeys!.privacyPolicy!.tr,
rightTitle: "",
isHaveLine: false,
isHaveDirection: true,
action: () {
Navigator.pushNamed(context, Routers.webviewShowPage,
arguments: {
"url": XSConstantMacro.privacyPolicyURL,
"title": '隐私政策'.tr
});
}),
Divider(
height: 1,
color: AppColors.greyLineColor,
indent: 20.w,
endIndent: 20.w,
),
CommonItem(
leftTitel: TranslationLoader
.lanKeys!.personalInformationCollectionList!.tr,
rightTitle: "",
isHaveLine: false,
isHaveDirection: true,
action: () {
Navigator.pushNamed(context, Routers.webviewShowPage,
arguments: {
"url": XSConstantMacro.collectionListURL,
"title": '个人信息收集清单'.tr
});
}),
Divider(
height: 1,
color: AppColors.greyLineColor,
indent: 20.w,
endIndent: 20.w,
),
CommonItem(
leftTitel: TranslationLoader
.lanKeys!.applicationPermissionDescription!.tr,
rightTitle: "",
isHaveLine: false,
isHaveDirection: true,
action: () {
Navigator.pushNamed(context, Routers.webviewShowPage,
arguments: {
"url": XSConstantMacro.appPermissionDescURL,
"title": '应用权限说明'.tr
});
}),
Divider(
height: 1,
color: AppColors.greyLineColor,
indent: 20.w,
endIndent: 20.w,
),
CommonItem(
leftTitel: TranslationLoader
.lanKeys!.thirdPartyInformationSharingList!.tr,
rightTitle: "",
isHaveLine: false,
isHaveDirection: true,
action: () {
Navigator.pushNamed(context, Routers.webviewShowPage,
arguments: {
"url": XSConstantMacro.thirdPartyInfShareListURL,
"title": '第三方信息共享清单'.tr
});
}),
],
),
);
return GetBuilder<AboutConsole>(
init: AboutConsole(),
builder: (AboutConsole logic) {
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar(
barTitle: TranslationLoader.lanKeys!.about!.tr,
haveBack: true,
backgroundColor: AppColors.mainColor),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Align(
alignment: Alignment.topRight,
child: GestureDetector(
onTap: logic.handleTap,
child: Container(
color: Colors.transparent,
width: 80.w,
height: 80.h,
),
),
),
SizedBox(height: 70.h),
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Image.asset(
F.sw(
defaultCall: () => "images/icon_main_1024.png",
xhjCall: () => "images/icon_main_xhj_1024.png"),
width: 160.w,
height: 160.w),
]),
SizedBox(height: 20.h),
Text(
"${F.title} $version+$buildNumber",
style:
TextStyle(fontSize: 24.sp, color: AppColors.blackColor),
),
SizedBox(height: 20.h),
Text(
F.apiPrefix,
style:
TextStyle(fontSize: 24.sp, color: AppColors.blackColor),
),
SizedBox(
height: 60.h,
),
CommonItem(
leftTitel: TranslationLoader.lanKeys!.introduce!.tr,
rightTitle: "",
isHaveLine: false,
isHaveDirection: true,
action: () {
Navigator.pushNamed(context, Routers.webviewShowPage,
arguments: {
"url": XSConstantMacro.introduceURL,
"title": '介绍'.tr
});
}),
Divider(
height: 1,
color: AppColors.greyLineColor,
indent: 20.w,
endIndent: 20.w,
),
CommonItem(
leftTitel: TranslationLoader.lanKeys!.userAgreement!.tr,
rightTitle: "",
isHaveLine: false,
isHaveDirection: true,
action: () {
Get.toNamed(Routers.webviewShowPage, arguments: {
"url": XSConstantMacro.userAgreementURL,
"title": '用户协议'.tr
});
}),
Divider(
height: 1,
color: AppColors.greyLineColor,
indent: 20.w,
endIndent: 20.w,
),
CommonItem(
leftTitel: TranslationLoader.lanKeys!.privacyPolicy!.tr,
rightTitle: "",
isHaveLine: false,
isHaveDirection: true,
action: () {
Navigator.pushNamed(context, Routers.webviewShowPage,
arguments: {
"url": XSConstantMacro.privacyPolicyURL,
"title": '隐私政策'.tr
});
}),
Divider(
height: 1,
color: AppColors.greyLineColor,
indent: 20.w,
endIndent: 20.w,
),
CommonItem(
leftTitel: TranslationLoader
.lanKeys!.personalInformationCollectionList!.tr,
rightTitle: "",
isHaveLine: false,
isHaveDirection: true,
action: () {
Navigator.pushNamed(context, Routers.webviewShowPage,
arguments: {
"url": XSConstantMacro.collectionListURL,
"title": '个人信息收集清单'.tr
});
}),
Divider(
height: 1,
color: AppColors.greyLineColor,
indent: 20.w,
endIndent: 20.w,
),
CommonItem(
leftTitel: TranslationLoader
.lanKeys!.applicationPermissionDescription!.tr,
rightTitle: "",
isHaveLine: false,
isHaveDirection: true,
action: () {
Navigator.pushNamed(context, Routers.webviewShowPage,
arguments: {
"url": XSConstantMacro.appPermissionDescURL,
"title": '应用权限说明'.tr
});
}),
Divider(
height: 1,
color: AppColors.greyLineColor,
indent: 20.w,
endIndent: 20.w,
),
CommonItem(
leftTitel: TranslationLoader
.lanKeys!.thirdPartyInformationSharingList!.tr,
rightTitle: "",
isHaveLine: false,
isHaveDirection: true,
action: () {
Navigator.pushNamed(context, Routers.webviewShowPage,
arguments: {
"url": XSConstantMacro.thirdPartyInfShareListURL,
"title": '第三方信息共享清单'.tr
});
}),
],
),
);
});
}
}

View File

@ -21,8 +21,9 @@ class _StarLockApplicationState extends State<StarLockApplication> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
if (F.debug) {
WidgetsBinding.instance.addPostFrameCallback((_) async {
bool? openDeBug = await Storage.getBool(isOpenDeBug);
if (openDeBug == true) {
DeBug.showFloatWidget();
}
});

View File

@ -26,6 +26,7 @@ const saveIsVip = "saveIsVip"; //是否是VIP
const saveUserLoginData = "userLoginData";
const saveLockMainListData = "lockMainListData";
const isOpenDeBug = "isOpenDeBug";// debug
class Storage {
Storage._internal();