app_logger 0.0.4 copy "app_logger: ^0.0.4" to clipboard
app_logger: ^0.0.4 copied to clipboard

Log all Http request and Navigation.

example/lib/main.dart

import 'package:app_logger/app_logger.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:http/http.dart' as http;

void main() {
  AppLogger.init(
    baseUrl: 'https://example.com',
    httpLog: true,
    navigationLog: true,
    appId: 'example',
    appRunner: () => runApp(const MyApp()),
  );
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  initState() {
    super.initState();
    AppLogger.instance.configuration.setUser(
      AppLoggerUser(id: '123123213123', username: 'Mustafa'),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('App Logger'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            ElevatedButton(onPressed: getRequest, child: const Text('Http Log')),
            ElevatedButton(onPressed: navigationLog, child: const Text('Navigation Log')),
          ],
        ),
      ),
    );
  }

  void navigationLog() {
    /*NavigationLogger.instance.log(
      const RouteSettings(
        name: 'AppLoggerDetailScreen',
        arguments: {'userName': 'Mto', 'userId': 1},
      ),
    );*/
  }

  Future<void> getRequest() async {
    final uri = Uri.https('jsonplaceholder.typicode.com', 'todos/1');
    final res = await http.get(
      uri,
      headers: {"content-type": "application/json"},
    );
    HttpLogger.instance.log(
      url: uri.toString(),
      statusCode: res.statusCode,
      header: {},
      requestBody: {},
      responseBody: res.body,
    );
  }
}
3
likes
130
points
49
downloads

Publisher

verified publishermustafaturkmen.dev

Weekly Downloads

Log all Http request and Navigation.

Documentation

API reference

License

MIT (license)

Dependencies

background_json_parser, battery_plus, device_info_plus, dio, flutter, package_info_plus

More

Packages that depend on app_logger