app-starlock/lib/mine/about/debug/debug_tool.dart

73 lines
2.2 KiB
Dart
Raw Normal View History

2024-04-11 18:26:28 +08:00
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
2024-04-11 18:26:28 +08:00
import 'package:get/get.dart';
import 'package:star_lock/app_settings/app_colors.dart';
import 'package:star_lock/mine/about/debug/debug_console.dart';
2024-04-11 18:26:28 +08:00
class DeBug {
static void log(String message, {String? tag}) {
DebugConsole.info(message);
Get.log(message);
}
static bool open = false;
static bool openInfo = false;
static late OverlayEntry overlayEntry;
2024-04-11 18:26:28 +08:00
static void showFloatWidget() {
final Rx<Offset> offset = const Offset(20, 100).obs; // 初始位置
overlayEntry = OverlayEntry(builder: (BuildContext context) {
2024-04-11 18:26:28 +08:00
return Obx(() => Positioned(
left: offset.value.dx,
top: offset.value.dy,
child: GestureDetector(
onPanUpdate: (DragUpdateDetails details) {
2024-04-11 18:26:28 +08:00
offset.value += details.delta;
},
child: FloatingActionButton(
backgroundColor: AppColors.mainColor,
shape: ContinuousRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20.r)),
side: BorderSide(color: Colors.white, width: 2.w),
),
child: const Icon(
Icons.bug_report,
color: Colors.white,
),
2024-04-11 18:26:28 +08:00
onPressed: () {
if (openInfo) {
Get.back();
return;
}
if (open) {
open = false;
Get.back();
} else {
open = true;
Get.to(WillPopScope(
onWillPop: () async {
open = false;
return true;
},
child: DebugConsole(
controller: DebugConsole.instance,
actions: <PopupMenuItem<void>>[],
2024-04-11 18:26:28 +08:00
expandStackTrace: false,
savePath: null,
),
));
}
},
),
)));
});
Get.key.currentState?.overlay?.insert(overlayEntry);
}
static void closeFloatWidget() {
overlayEntry.remove();
}
2024-04-11 18:26:28 +08:00
DeBug();
}