dev_logger_ui 1.0.0-dev.5 copy "dev_logger_ui: ^1.0.0-dev.5" to clipboard
dev_logger_ui: ^1.0.0-dev.5 copied to clipboard

Display API requests, responses, errors, and mocked APIs(response/url) in the UI. Log all of them to the console, and also display exceptions in the UI.

Features #

  • Display API request/response using Dio on the interface or log to the console.
  • Mock response or URL when calling API.
  • Display errors on the interface for easier debugging.

Installation #

  • Install the compatible version of the library: Type in the terminal:
flutter pub add dev_logger_ui

or add to the pubspec.yaml file in the section:

dependencies:
  flutter:
    sdk: flutter
  dev_logger_ui: latest_version
  • Add interceptor to Dio:
  Dio dio = Dio();
  dio.interceptors.add(LogApiInterceptor());
  • Initialization:

Initialize API log:

// create navigatorKey
GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
MaterialApp(
    navigatorKey: navigatorKey,
    //...
)
DevLoggerUI.instance.init(
      navigatorKey: navigatorKey,
      isAutoStart: true,
      isLogCurl: true,
      openTypes: [OpenType.button, OpenType.longPress, OpenType.shake],
      saveManager: SaveManager(),
      sendText: ({required body, required email, required title}) async {
        return "Email: $email\nTitle: $title\nBody: $body";
      },
      valueFromResponse: ValueFromResponse(
        checkApiSuccess: (response, {url}) {
          if (response is Map) {
            return response['status'] == true && response['code'] == 200;
          }
          return false;
        },
        getErrorCode: (response, {url}) {
          if (response is Map) {
            final errorCode = response["errorCode"];
            if (errorCode == null) return null;
            return MapEntry("errorCode", errorCode);
          }
          return null;
        },
        getErrorMessage: (response, {url}) {
          if (response is Map) {
            final message = response['message'];
            if (message == null) return null;
            return message.toString();
          }
          return null;
        },
      ),
      waitTurnOnTime: 5000,
    );

If you want to log exceptions to the interface:

runZonedGuarded(
    () {
      WidgetsFlutterBinding.ensureInitialized();
      DevLoggerUI.instance.listenFlutterError(FlutterError.onError);
      runApp(const MyApp());
    },
    (error, stack) {
      DevLoggerUI.instance.addNormalError(error, stack);
      Completer().completeError(error, stack);
    },
  );
  • Main ways to open the log screen: There are 3 ways based on openType when initializing the library:
DevLoggerUI.instance.init(openTypes: [OpenType.button, OpenType.longPress, OpenType.shake]);
  1. OpenType.button: Show Log button - Double click the button to open the log interface. To enable this feature, you need to add:
    MaterialApp(
        navigatorKey: navigatorKey,
        title: 'Flutter Demo',
        builder: DevLoggerUI.builder(),
        //...
    );

If you use another library that also uses builder like EasyLoading, use as below:

    MaterialApp(
        navigatorKey: navigatorKey,
        title: 'Flutter Demo',
        builder: DevLoggerUI.builder(builder: EasyLoading.init()),
        //...
    );
  1. OpenType.longPress: Long press anywhere to open the log interface.
  2. OpenType.shake: Shake the phone to open the log interface.
0
likes
160
points
97
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Display API requests, responses, errors, and mocked APIs(response/url) in the UI. Log all of them to the console, and also display exceptions in the UI.

Homepage

License

BSD-3-Clause (license)

Dependencies

collection, cupertino_icons, dio, flutter, flutter_localizations, flutter_udid, http, http_parser, intl, json_annotation, keyboard_dismisser, lazy_data_viewer, mailer, mime, path_provider, provider, shake

More

Packages that depend on dev_logger_ui