tiny_logger 0.0.1+1
tiny_logger: ^0.0.1+1 copied to clipboard
A tiny logger tool to print different levels of log entries. Also provides a widget to show a log within a Flutter app.
import 'package:flutter/material.dart';
import 'package:tiny_logger/tiny_logger.dart';
void main() {
FlutterError.onError = (details) {
log.error(details);
FlutterError.dumpErrorToConsole(details);
};
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Tiny Logger Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool _showLog = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Tiny Logger Example'),
),
body: Stack(
children: [
Center(
child: IntrinsicWidth(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
MaterialButton(
color: Colors.blue,
onPressed: () {
log.debug('This is a debug message!');
},
child: const Text('Log Debug'),
),
MaterialButton(
color: Colors.yellow,
onPressed: () {
log.warn('This is a warning!');
},
child: const Text('Log Warning'),
),
MaterialButton(
color: Colors.red,
onPressed: () {
log.error('This is an error!');
},
child: const Text('Log Error'),
),
MaterialButton(
color: Colors.red,
onPressed: () {
throw UnimplementedError('Example error');
},
child: const Text('Throw Error'),
),
const SizedBox(height: 20),
MaterialButton(
color: Colors.red,
onPressed: () => setState(() => _showLog = true),
child: const Text('SHOW LOG'),
),
],
),
),
),
if (_showLog)
LogView(
onClose: () => setState(() => _showLog = false),
),
],
),
);
}
}