style: fix lint issues
This commit is contained in:
parent
af369c7622
commit
bcca8432f9
|
|
@ -20,7 +20,8 @@ class YxNetInspectorDioInterceptor extends Interceptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onResponse(Response response, ResponseInterceptorHandler handler) {
|
void onResponse(
|
||||||
|
Response<dynamic> response, ResponseInterceptorHandler handler,) {
|
||||||
// 记录响应
|
// 记录响应
|
||||||
try {
|
try {
|
||||||
// 计算请求耗时(如果可能)
|
// 计算请求耗时(如果可能)
|
||||||
|
|
@ -36,7 +37,7 @@ class YxNetInspectorDioInterceptor extends Interceptor {
|
||||||
// 这里没有准确的耗时,因为 logRequest 记录了开始时间。
|
// 这里没有准确的耗时,因为 logRequest 记录了开始时间。
|
||||||
// Controller 会根据 ID 自动计算耗时:Duration = Now - StartTime
|
// Controller 会根据 ID 自动计算耗时:Duration = Now - StartTime
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} on Object catch (_) {
|
||||||
// 忽略日志记录错误,避免影响业务
|
// 忽略日志记录错误,避免影响业务
|
||||||
}
|
}
|
||||||
handler.next(response);
|
handler.next(response);
|
||||||
|
|
@ -53,7 +54,7 @@ class YxNetInspectorDioInterceptor extends Interceptor {
|
||||||
error: err.message ?? err.toString(),
|
error: err.message ?? err.toString(),
|
||||||
statusCode: err.response?.statusCode,
|
statusCode: err.response?.statusCode,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} on Object catch (_) {
|
||||||
// 忽略日志记录错误
|
// 忽略日志记录错误
|
||||||
}
|
}
|
||||||
handler.next(err);
|
handler.next(err);
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ class NetworkLogEntry {
|
||||||
final buffer = StringBuffer('curl -X $method "$url"');
|
final buffer = StringBuffer('curl -X $method "$url"');
|
||||||
headers?.forEach((key, value) {
|
headers?.forEach((key, value) {
|
||||||
// 转义双引号以兼容所有平台
|
// 转义双引号以兼容所有平台
|
||||||
final escapedValue = value.toString().replaceAll('"', '\\"');
|
final escapedValue = value.toString().replaceAll('"', r'\"');
|
||||||
buffer.write(' -H "$key: $escapedValue"');
|
buffer.write(' -H "$key: $escapedValue"');
|
||||||
});
|
});
|
||||||
if (requestData != null) {
|
if (requestData != null) {
|
||||||
|
|
@ -144,12 +144,12 @@ class NetworkLogEntry {
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
body = jsonEncode(requestData);
|
body = jsonEncode(requestData);
|
||||||
} catch (_) {
|
} on Object catch (_) {
|
||||||
body = requestData.toString();
|
body = requestData.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 转义双引号和反斜杠
|
// 转义双引号和反斜杠
|
||||||
final escapedBody = body.replaceAll('\\', '\\\\').replaceAll('"', '\\"');
|
final escapedBody = body.replaceAll(r'\', r'\\').replaceAll('"', r'\"');
|
||||||
buffer.write(' -d "$escapedBody"');
|
buffer.write(' -d "$escapedBody"');
|
||||||
}
|
}
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ class _PasswordDialogState extends State<PasswordDialog> {
|
||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(16),
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: Colors.black.withOpacity(0.1),
|
color: Colors.black.withValues(alpha: 0.1),
|
||||||
blurRadius: 20,
|
blurRadius: 20,
|
||||||
offset: const Offset(0, 10),
|
offset: const Offset(0, 10),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ void main() {
|
||||||
setUp(() {
|
setUp(() {
|
||||||
controller = YxNetInspectorController.instance;
|
controller = YxNetInspectorController.instance;
|
||||||
// Initialize controller with logging enabled (debug mode)
|
// Initialize controller with logging enabled (debug mode)
|
||||||
controller.initialize(const YxNetInspectorConfig(showInDebugMode: true));
|
controller.initialize(const YxNetInspectorConfig());
|
||||||
|
|
||||||
dio = Dio();
|
dio = Dio();
|
||||||
// Add our inspector interceptor FIRST
|
// Add our inspector interceptor FIRST
|
||||||
|
|
@ -23,14 +23,16 @@ void main() {
|
||||||
final initialLogCount = controller.logs.length;
|
final initialLogCount = controller.logs.length;
|
||||||
|
|
||||||
// Add a mock interceptor to return success response immediately
|
// Add a mock interceptor to return success response immediately
|
||||||
dio.interceptors.add(InterceptorsWrapper(
|
dio.interceptors.add(
|
||||||
|
InterceptorsWrapper(
|
||||||
onRequest: (options, handler) {
|
onRequest: (options, handler) {
|
||||||
// Allow request to proceed (so our inspector sees it)
|
// Allow request to proceed (so our inspector sees it)
|
||||||
handler.next(options);
|
handler.next(options);
|
||||||
},
|
},
|
||||||
onError: (e, handler) => handler.next(e),
|
onError: (e, handler) => handler.next(e),
|
||||||
onResponse: (e, handler) => handler.next(e),
|
onResponse: (e, handler) => handler.next(e),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
|
|
||||||
// Mock Adapter to avoid real network
|
// Mock Adapter to avoid real network
|
||||||
dio.httpClientAdapter = _MockAdapter((options) {
|
dio.httpClientAdapter = _MockAdapter((options) {
|
||||||
|
|
@ -43,7 +45,7 @@ void main() {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
await dio.get('https://example.com/api/test');
|
await dio.get<dynamic>('https://example.com/api/test');
|
||||||
|
|
||||||
expect(controller.logs.length, greaterThan(initialLogCount));
|
expect(controller.logs.length, greaterThan(initialLogCount));
|
||||||
final latestLog = controller.logs.first;
|
final latestLog = controller.logs.first;
|
||||||
|
|
@ -66,8 +68,9 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await dio.post('https://example.com/api/fail', data: {'foo': 'bar'});
|
await dio.post<dynamic>('https://example.com/api/fail',
|
||||||
} catch (e) {
|
data: {'foo': 'bar'},);
|
||||||
|
} on Object catch (_) {
|
||||||
// Expected
|
// Expected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,13 +85,15 @@ void main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MockAdapter implements HttpClientAdapter {
|
class _MockAdapter implements HttpClientAdapter {
|
||||||
|
_MockAdapter(this._mockResponse);
|
||||||
final ResponseBody Function(RequestOptions options) _mockResponse;
|
final ResponseBody Function(RequestOptions options) _mockResponse;
|
||||||
|
|
||||||
_MockAdapter(this._mockResponse);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<ResponseBody> fetch(RequestOptions options,
|
Future<ResponseBody> fetch(
|
||||||
Stream<List<int>>? requestStream, Future<void>? cancelFuture) async {
|
RequestOptions options,
|
||||||
|
Stream<List<int>>? requestStream,
|
||||||
|
Future<void>? cancelFuture,
|
||||||
|
) async {
|
||||||
return _mockResponse(options);
|
return _mockResponse(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ void main() {
|
||||||
|
|
||||||
testWidgets('Panel should be unlocked by default (no password)',
|
testWidgets('Panel should be unlocked by default (no password)',
|
||||||
(WidgetTester tester) async {
|
(WidgetTester tester) async {
|
||||||
controller.initialize(const YxNetInspectorConfig(showInDebugMode: true));
|
controller.initialize(const YxNetInspectorConfig());
|
||||||
|
|
||||||
expect(controller.isUnlocked, isTrue);
|
expect(controller.isUnlocked, isTrue);
|
||||||
|
|
||||||
|
|
@ -40,9 +40,8 @@ void main() {
|
||||||
testWidgets('Panel should be locked if password is set',
|
testWidgets('Panel should be locked if password is set',
|
||||||
(WidgetTester tester) async {
|
(WidgetTester tester) async {
|
||||||
controller.initialize(const YxNetInspectorConfig(
|
controller.initialize(const YxNetInspectorConfig(
|
||||||
showInDebugMode: true,
|
|
||||||
password: '123',
|
password: '123',
|
||||||
));
|
),);
|
||||||
|
|
||||||
expect(controller.isUnlocked, isFalse);
|
expect(controller.isUnlocked, isFalse);
|
||||||
|
|
||||||
|
|
@ -61,15 +60,14 @@ void main() {
|
||||||
expect(find.byType(PasswordDialog), findsOneWidget);
|
expect(find.byType(PasswordDialog), findsOneWidget);
|
||||||
expect(find.text('安全访问'), findsOneWidget);
|
expect(find.text('安全访问'), findsOneWidget);
|
||||||
expect(
|
expect(
|
||||||
find.byIcon(Icons.close), findsNothing); // Should hide panel content
|
find.byIcon(Icons.close), findsNothing,); // Should hide panel content
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('Entering correct password should unlock panel',
|
testWidgets('Entering correct password should unlock panel',
|
||||||
(WidgetTester tester) async {
|
(WidgetTester tester) async {
|
||||||
controller.initialize(const YxNetInspectorConfig(
|
controller.initialize(const YxNetInspectorConfig(
|
||||||
showInDebugMode: true,
|
|
||||||
password: '123',
|
password: '123',
|
||||||
));
|
),);
|
||||||
|
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
MaterialApp(
|
MaterialApp(
|
||||||
|
|
@ -97,9 +95,8 @@ void main() {
|
||||||
testWidgets('Entering wrong password should show error',
|
testWidgets('Entering wrong password should show error',
|
||||||
(WidgetTester tester) async {
|
(WidgetTester tester) async {
|
||||||
controller.initialize(const YxNetInspectorConfig(
|
controller.initialize(const YxNetInspectorConfig(
|
||||||
showInDebugMode: true,
|
|
||||||
password: '123',
|
password: '123',
|
||||||
));
|
),);
|
||||||
|
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
MaterialApp(
|
MaterialApp(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue