-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.dart
207 lines (193 loc) · 5.55 KB
/
main.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:logarte/logarte.dart';
import 'package:share_plus/share_plus.dart';
final logarte = Logarte(
onShare: Share.share,
password: 'logarte',
onRocketDoubleTapped: (context) {
showDialog(
context: context,
builder: (context) {
return const AlertDialog(
title: Text(
'onRocketDoubleTapped',
),
content: Text(
'This callback is useful when you want to quickly access some pages or perform actions without leaving the currently page (toggle theme, change language and etc.).',
),
);
},
);
},
onRocketLongPressed: (context) {
showDialog(
context: context,
builder: (context) {
return const AlertDialog(
title: Text(
'onRocketLongPressed',
),
content: Text(
'This callback is useful when you want to quickly access some pages or perform actions without leaving the currently page (toggle theme, change language and etc.).',
),
);
},
);
},
);
enum Environment { dev, staging, prod }
const environment = Environment.dev;
void main() {
runApp(const App());
}
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Logarte Example',
debugShowCheckedModeBanner: false,
themeMode: ThemeMode.dark,
theme: ThemeData(
useMaterial3: true,
colorSchemeSeed: Colors.blueGrey.shade900,
),
navigatorObservers: [
LogarteNavigatorObserver(logarte),
],
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => HomePageState();
}
class HomePageState extends State<HomePage> {
late final Dio _dio;
@override
void initState() {
super.initState();
_dio = Dio()
..interceptors.add(
LogarteDioInterceptor(logarte),
);
logarte.attach(
context: context,
visible: false,
);
}
@override
void dispose() {
_dio.close();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Example'),
),
body: Column(
children: [
LogarteMagicalTap(
logarte: logarte,
child: Container(
color: Colors.blueGrey.shade100,
child: const ListTile(
enabled: true,
leading: Icon(Icons.touch_app_rounded),
title: Text('LogarteMagicalTap'),
subtitle: Text(
'Tap this widget 10 times to attach the logarte rocket button UI.',
),
),
),
),
const Divider(),
ButtonBar(
children: [
FilledButton.tonal(
onPressed: () async {
await _dio.get('https://jsonplaceholder.typicode.com/posts');
},
child: const Text('GET'),
),
FilledButton.tonal(
onPressed: () async {
await _dio.post('https://jsonplaceholder.typicode.com/posts');
},
child: const Text('POST'),
),
FilledButton.tonal(
onPressed: () async {
await _dio.put('https://jsonplaceholder.typicode.com/posts');
},
child: const Text('PUT'),
),
FilledButton.tonal(
onPressed: () async {
await _dio
.delete('https://jsonplaceholder.typicode.com/posts');
},
child: const Text('DELETE'),
),
],
),
const Divider(),
ButtonBar(
children: [
FilledButton.tonal(
onPressed: () {
logarte.database(
target: 'language',
value: 'en',
source: 'SharedPreferences',
);
},
child: const Text('Write to database'),
),
FilledButton.tonal(
onPressed: () {
showDialog(
context: context,
routeSettings: const RouteSettings(
name: '/test-dialog',
),
builder: (BuildContext context) {
return const AlertDialog(
title: Text('Dialog'),
content: Text(
'Opening of this dialog was logged to Logarte',
),
);
},
);
},
child: const Text('Open dialog'),
),
FilledButton.tonal(
onPressed: () {
try {
throw Exception('Exception');
} catch (e, s) {
logarte.error(e, stackTrace: s);
}
},
child: const Text('Exception'),
),
FilledButton.tonal(
onPressed: () {
logarte.info('Printed to console');
},
child: const Text('Plain log'),
),
],
),
],
),
);
}
}