simple_save_logger 0.0.1
simple_save_logger: ^0.0.1 copied to clipboard
A package for logging to a file. Logs are saved in the application documents directory.
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart';
import 'package:simple_save_logger/simple_save_logger.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await AppDirectory.initialize();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(home: const MyHomePage());
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
logInfo('Counter incremented: $_counter');
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text('Simple Save Logger'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('You have pushed the button this many times:'),
Text('$_counter', style: Theme.of(context).textTheme.headlineMedium),
ElevatedButton(
onPressed: () => Share.shareXFiles([
...AppDirectory.logsDirectory.listSync().whereType<File>().map((e) => XFile(e.path)),
]),
child: const Text('Share log file'),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}