anadea_flutter_loggy 1.7.0 copy "anadea_flutter_loggy: ^1.7.0" to clipboard
anadea_flutter_loggy: ^1.7.0 copied to clipboard

Anadea flutter loggy package. An package extension for the loggy package with various integrations such as dio, routing and flutter_bloc.

example/lib/main.dart

import 'package:anadea_flutter_loggy/anadea_flutter_loggy.dart';
import 'package:dio/dio.dart' hide LogInterceptor;
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_loggy/flutter_loggy.dart';
import 'package:loggy/loggy.dart';

import 'bloc/example_bloc.dart';

void main() {
  Loggy.initLoggy(
    logPrinter: StreamPrinter(const PrettyPrinter()),
  );

  Bloc.observer = LogBlocObserver();

  runApp(const ExampleApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorObservers: [LogNavigatorObserver()],
      home: BlocProvider(
        create: (context) => ExampleBloc(),
        child: DemoPage(),
      ),
      builder: (context, child) => Inspector(
        customRecordBuilders: {
          TestLogModel: (context, record) => Text(record.object.toString())
        },
        isShow: true,
        actions: [
          IconButton(
            onPressed: () => ScaffoldMessenger.of(context).showSnackBar(
              const SnackBar(content: Text("Custom action pressed")),
            ),
            icon: const Icon(Icons.favorite),
          )
        ],
        child: child!,
      ),
    );
  }
}

class DemoPage extends StatelessWidget {
  DemoPage({
    Key? key,
  }) : super(key: key);

  final dio = Dio()..interceptors.add(LogInterceptor());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Text(
              "Loggy demo",
              style: Theme.of(context).textTheme.titleLarge,
            ),
            const SizedBox(height: 10),
            ElevatedButton(
              onPressed: () {
                logInfo('message');
              },
              child: const Text("log message"),
            ),
            const SizedBox(height: 10),
            ElevatedButton(
              onPressed: () {
                logWarning("warning message");
              },
              child: const Text("log warning"),
            ),
            const SizedBox(height: 10),
            ElevatedButton(
              onPressed: () {
                logDebug("debug message");
              },
              child: const Text("log debug"),
            ),
            const SizedBox(height: 10),
            ElevatedButton(
              onPressed: () {
                logError("error message");
              },
              child: const Text("log error"),
            ),
            const SizedBox(height: 10),
            ElevatedButton(
              onPressed: () {
                logError(TestLogModel('content'));
              },
              child: const Text("log speciffic type"),
            ),
            const SizedBox(height: 10),
            ElevatedButton(
              onPressed: () {
                dio.get(
                  'http://www.7timer.info/bin/api.pl?lon=113.17&lat=23.09&product=astro&output=json',
                );
                dio.get(
                  'http://www.7timer.info/bn/api.pl?lon=113.17&lat=23.09&product=astro&output=json',
                );
              },
              child: const Text("test dio logs"),
            ),
            const SizedBox(height: 10),
            ElevatedButton(
              onPressed: () {
                BlocProvider.of<ExampleBloc>(context)
                    .add(const GetExampleData());
              },
              child: const Text("test bloc logs"),
            ),
            const SizedBox(height: 10),
            ElevatedButton(
              onPressed: () {
                Future.delayed(const Duration(seconds: 2)).then(
                  (value) => Navigator.of(context).push(
                    MaterialPageRoute(
                      builder: (context) => const SecondTestScreen(),
                    ),
                  ),
                );
              },
              child: const Text("open second screen with delay"),
            ),
          ],
        ),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: const Center(
        child: Text('Second screen'),
      ),
    );
  }
}

class TestLogModel {
  TestLogModel(this.content);

  final String content;
}
4
likes
120
points
309
downloads

Documentation

API reference

Publisher

verified publisheranadeainc.com

Weekly Downloads

Anadea flutter loggy package. An package extension for the loggy package with various integrations such as dio, routing and flutter_bloc.

Repository

License

BSD-3-Clause (license)

Dependencies

dio, flutter, flutter_bloc, flutter_loggy, loggy, package_info_plus

More

Packages that depend on anadea_flutter_loggy