-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.dart
60 lines (52 loc) · 1.45 KB
/
debug.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//import 'dart:async';
import 'dart:developer' as dev show log;
import 'package:flutter/foundation.dart' show kDebugMode;
// import 'package:flutter_ble_lib/flutter_ble_lib.dart';
import 'package:logging/logging.dart' show Level;
//import 'package:espmui/main.dart';
import 'package:flutter/material.dart';
class DebugBorder extends StatelessWidget {
final Widget child;
final Color color;
final double width;
const DebugBorder({
super.key,
required this.child,
this.color = Colors.yellow,
this.width = 1,
});
@override
Widget build(BuildContext context) {
if (!kDebugMode) return Container(child: child);
return Container(
decoration: BoxDecoration(
border: Border.all(
color: color,
width: width,
)),
child: child,
);
}
}
mixin Debug {
String get debugTag => !kDebugMode ? "$runtimeType(${identityHashCode(this)})" : "";
static void log(String s, {Level level = Level.FINE}) {
if (!kDebugMode) return;
var match = RegExp(r'^#(\d+) +(.+) +(.+)').firstMatch(StackTrace.current.toString().split("\n")[2]);
dev.log(
"$s ${match?[3]}",
//name: debugTag,
name: match?[2]?.replaceAll(".<anonymous closure>", ".A") ?? "",
level: level.value,
);
}
void logD(String s) {
log("[D] $s", level: Level.SHOUT);
}
void logE(String s) {
log("[E] $s", level: Level.SEVERE);
}
void logI(String s) {
log("[I] $s", level: Level.INFO);
}
}