forked from jhomlala/catcher
-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathfile_example.dart
91 lines (80 loc) · 2.21 KB
/
file_example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import 'dart:io';
import 'package:catcher_2/catcher_2.dart';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
void main() async {
final catcher2 = Catcher2(rootWidget: const MyApp(), ensureInitialized: true);
Directory? externalDir;
if (Platform.isAndroid || Platform.isIOS) {
externalDir = await getExternalStorageDirectory();
}
if (Platform.isMacOS) {
externalDir = await getApplicationDocumentsDirectory();
}
var path = '';
if (externalDir != null) {
path = '${externalDir.path}/log.txt';
}
// ignore: avoid_print
print('PATH: $path');
final debugOptions = Catcher2Options(
DialogReportMode(),
[FileHandler(File(path), printLogs: true)],
);
final releaseOptions =
Catcher2Options(DialogReportMode(), [FileHandler(File(path))]);
catcher2.updateConfig(
debugConfig: debugOptions,
releaseConfig: releaseOptions,
);
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) => MaterialApp(
navigatorKey: Catcher2.navigatorKey,
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: const ChildWidget(),
),
);
}
class ChildWidget extends StatelessWidget {
const ChildWidget({super.key});
@override
Widget build(BuildContext context) => Column(
children: [
TextButton(
onPressed: checkPermissions,
child: const Text('Check permission'),
),
TextButton(
onPressed: generateError,
child: const Text('Generate error'),
),
],
);
Future<void> checkPermissions() async {
final status = await Permission.storage.status;
// ignore: avoid_print
print('Status: $status');
if (!status.isGranted) {
// ignore: avoid_print
print('Requested');
}
}
Future<void> generateError() async {
throw Exception('Test exception');
}
}