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