folivora_logger 0.0.1 copy "folivora_logger: ^0.0.1" to clipboard
folivora_logger: ^0.0.1 copied to clipboard

A useful logger.

example/lib/main.dart

import 'package:folivora_logger/folivora_logger.dart';

// ignore: depend_on_referenced_packages
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
import 'package:twostrings_palette/twostrings_palette.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Two Strings Package Test App',
      theme: ThemeData(
        primarySwatch:
            MaterialColor(TwoStringsColor.primaryMaterialColor.colorHex, TwoStringsColor.primaryMaterialColor.swatch),
      ),
      home: const MyHomePage(title: 'Two Strings 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> {
  Uri _generateUri() {
    return Uri(scheme: "https", host: "api.agify.io", path: null, queryParameters: null, query: "name=dhkim");
  }

  Future<http.Response> _httpRequest({required http.Request request}) async {
    final streamedResponse = await request.send();
    return await http.Response.fromStream(streamedResponse);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Package example app'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () async {
            FvLogger("Default Logger");
            FvLogger("You can use this for even Object ${_TestObjectPrint()}");
            FvLogger.warning("Warning");
            FvLogger.info("Info");
            FvLogger.debug("Debugging");
            FvLogger.log("log1\nlog2\nlog3\nlog4\nlog5");
            FvLogger.build("build start\nbuilding...\nbuilding...\nbuilding...\nbuild done");
            FvFunLogger.heart("I Love You.");
            FvFunLogger.poop("Shit Code");

            FvLogger.exception(_FvException("Exception Message"));
            FvLogger.error(FvError.example());

            http.Request request = http.Request("GET", _generateUri());
            request.headers.addAll({'Content-Type': 'application/json'});

            FvLogger.httpRequest(httpRequest: request);
            http.Response response = await _httpRequest(request: request);
            FvLogger.httpResponse(httpResponse: response);
            FvLogger.httpResponse(httpResponse: response, printHeaders: true);
          },
          child: const Text("Test"),
        ),
      ),
    );
  }
}

class _TestObjectPrint {
  final String str = "Instance";
  final int integer = 3;
}

class _FvException implements Exception {
  _FvException(this.message);

  final String? message;

  @override
  String toString() {
    return "FvException: $message";
  }
}

class FvError implements Error {
  final String? type;
  final String? message;
  final String? title;
  final String? detail;

  FvError({this.type, this.message, this.title, this.detail});

  @override
  String toString() {
    return "$type\n$message\n$title\n$detail";
  }

  @override
  StackTrace? get stackTrace => throw UnimplementedError();

  factory FvError.example({String? type, String? message, String? title, String? detail}) = _Example;
}

class _Example extends FvError {
  _Example({String? type, String? message, String? title, String? detail})
      : super(
            type: type ?? "TEST_ERROR",
            message: message ?? 'Error occurred',
            title: title ?? 'Error Title',
            detail: detail ?? 'Error Message');
}