style: fix lint issues

This commit is contained in:
YuanXuan 2026-01-20 17:01:05 +08:00
parent af369c7622
commit bcca8432f9
5 changed files with 34 additions and 31 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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),
),

View File

@ -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(
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);
}

View File

@ -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(