offline_logger 0.0.1
offline_logger: ^0.0.1 copied to clipboard
Offline-first logging and crash reporting SDK for Flutter apps
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:offline_logger/offline_logger.dart'; // ✅ ADD THIS
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await OfflineLogger.init(
LoggerConfig(
apiEndpoint: "https://api.example.com/logs",
enableDebugLogs: true,
),
);
OfflineLogger.runAppWithLogger(() {
runApp(const MyApp());
});
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(title: 'Offline Logger Example', home: const HomePage());
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Offline Logger Example")),
body: Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
ElevatedButton(
onPressed: () {
OfflineLogger.log("Button clicked");
},
child: const Text("Log Info"),
),
ElevatedButton(
onPressed: () {
OfflineLogger.error("Sample error");
},
child: const Text("Log Error"),
),
ElevatedButton(
onPressed: () {
try {
throw Exception("Test crash");
} catch (e, stack) {
OfflineLogger.crash(e, stack);
}
},
child: const Text("Trigger Crash"),
),
ElevatedButton(
onPressed: () async {
await OfflineLogger.flush();
},
child: const Text("Flush Logs"),
),
],
),
),
);
}
}