Skip to content

Commit 447085b

Browse files
committed
Replace print with debugPrint and improve logging
Replaced print statements with debugPrint in tests for better Flutter logging practices. In js_runtime_notifier.dart, replaced print statements with structured logging via terminalStateProvider, providing more consistent and contextual log handling. Minor code style improvements were also made.
1 parent e787ec3 commit 447085b

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

lib/apitoolgen/request_consolidator.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ class APIDashRequestDescription {
5050
if (bodyJSON != null) {
5151
getTyp(input, [i = 0]) {
5252
String indent = "\t";
53-
for (int j = 0; j < i; j++) indent += "\t";
53+
for (int j = 0; j < i; j++) {
54+
indent += "\t";
55+
}
5456
if (input.runtimeType.toString().toLowerCase().contains('map')) {
5557
String typd = '{';
5658
for (final z in input.keys) {

lib/providers/js_runtime_notifier.dart

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ignore_for_file: avoid_print
21
import 'dart:convert';
32
import 'package:apidash_core/apidash_core.dart';
43
import 'package:flutter/services.dart';
@@ -307,8 +306,16 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
307306
updateEnv?.call(originalEnvironmentModel, newValues);
308307
} else {
309308
if (scriptResult.updatedEnvironment.isNotEmpty) {
310-
print(
311-
'Warning: Pre-request script updated environment variables, but no active environment was selected to save them to.');
309+
final term = ref.read(terminalStateProvider.notifier);
310+
final msg =
311+
'Pre-request script updated environment variables, but no active environment was selected to save them to.';
312+
state = state.copyWith(lastError: msg);
313+
term.logJs(
314+
level: 'warn',
315+
args: [msg],
316+
context: 'preRequest',
317+
contextRequestId: requestModel.id,
318+
);
312319
return requestModel;
313320
}
314321
return newRequestModel;
@@ -359,8 +366,16 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
359366
updateEnv?.call(originalEnvironmentModel, newValues);
360367
} else {
361368
if (scriptResult.updatedEnvironment.isNotEmpty) {
362-
print(
363-
'Warning: Post-response script updated environment variables, but no active environment was selected to save them to.');
369+
final term = ref.read(terminalStateProvider.notifier);
370+
final msg =
371+
'Post-response script updated environment variables, but no active environment was selected to save them to.';
372+
state = state.copyWith(lastError: msg);
373+
term.logJs(
374+
level: 'warn',
375+
args: [msg],
376+
context: 'postResponse',
377+
contextRequestId: requestModel.id,
378+
);
364379
}
365380
return requestModel;
366381
}
@@ -375,8 +390,8 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
375390
}
376391

377392
void _handleConsole(String level, dynamic args) {
393+
final term = ref.read(terminalStateProvider.notifier);
378394
try {
379-
final term = ref.read(terminalStateProvider.notifier);
380395
List<String> argList = const <String>[];
381396
if (args is List) {
382397
argList = args.map((e) => e.toString()).toList();
@@ -398,13 +413,16 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
398413
term.logJs(
399414
level: level, args: argList, contextRequestId: _currentRequestId);
400415
} catch (e) {
401-
print('[JS ${level.toUpperCase()} HANDLER ERROR]: $args, Error: $e');
416+
term.logSystem(
417+
category: 'provider',
418+
message:
419+
'[JS ${level.toUpperCase()} HANDLER ERROR]: $args, Error: $e');
402420
}
403421
}
404422

405423
void _handleFatal(dynamic args) {
424+
final term = ref.read(terminalStateProvider.notifier);
406425
try {
407-
final term = ref.read(terminalStateProvider.notifier);
408426
if (args is Map<String, dynamic>) {
409427
final message = args['message']?.toString() ?? 'Unknown fatal error';
410428
final error = args['error']?.toString();
@@ -424,7 +442,9 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
424442
contextRequestId: _currentRequestId);
425443
}
426444
} catch (e) {
427-
print('[JS FATAL ERROR decoding error]: $args, Error: $e');
445+
term.logSystem(
446+
category: 'provider',
447+
message: '[JS FATAL ERROR decoding error]: $args, Error: $e');
428448
}
429449
}
430450
}

test/screens/common_widgets/auth/oauth2_fields_test.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -746,17 +746,18 @@ void main() {
746746

747747
// First verify we can find String popup menus
748748
final stringPopupMenus = find.byType(ADPopupMenu<String>);
749-
print('Found ${stringPopupMenus.evaluate().length} String popup menus');
749+
debugPrint(
750+
'Found ${stringPopupMenus.evaluate().length} String popup menus');
750751

751-
if (stringPopupMenus.evaluate().length > 0) {
752+
if (stringPopupMenus.evaluate().isNotEmpty) {
752753
// Find the code challenge method dropdown
753754
final codeChallengeDropdown = stringPopupMenus.first;
754755
await tester.tap(codeChallengeDropdown);
755756
await tester.pumpAndSettle();
756757

757758
// Try to find and tap plaintext option
758759
final plaintextOption = find.text('Plaintext');
759-
if (plaintextOption.evaluate().length > 0) {
760+
if (plaintextOption.evaluate().isNotEmpty) {
760761
await tester.tap(plaintextOption.first);
761762
await tester.pumpAndSettle();
762763

@@ -852,19 +853,19 @@ void main() {
852853

853854
// Debug: Print all text widgets to see what's available
854855
final allText = find.byType(Text);
855-
print('Found ${allText.evaluate().length} Text widgets');
856+
debugPrint('Found ${allText.evaluate().length} Text widgets');
856857

857858
// Try to find any button-like widget
858859
final allButtons = find.byType(ADTextButton);
859-
print('Found ${allButtons.evaluate().length} ADTextButton widgets');
860+
debugPrint('Found ${allButtons.evaluate().length} ADTextButton widgets');
860861

861862
// Look for the specific text content
862863
final clearText = find.text('Clear OAuth2 Session');
863-
print(
864+
debugPrint(
864865
'Found ${clearText.evaluate().length} widgets with Clear OAuth2 Session text');
865866

866867
// If we can find the clear button text, tap it
867-
if (clearText.evaluate().length > 0) {
868+
if (clearText.evaluate().isNotEmpty) {
868869
await tester.tap(clearText.first);
869870
await tester.pumpAndSettle();
870871
}
@@ -1296,10 +1297,10 @@ void main() {
12961297

12971298
// Debug: Look for all buttons and text widgets
12981299
final allButtons = find.byType(ADTextButton);
1299-
print('Found ${allButtons.evaluate().length} ADTextButton widgets');
1300+
debugPrint('Found ${allButtons.evaluate().length} ADTextButton widgets');
13001301

13011302
final allText = find.byType(Text);
1302-
print('Found ${allText.evaluate().length} Text widgets');
1303+
debugPrint('Found ${allText.evaluate().length} Text widgets');
13031304

13041305
// Try finding the button widget itself
13051306
if (allButtons.evaluate().isNotEmpty) {

0 commit comments

Comments
 (0)