-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
113 lines (101 loc) · 3.03 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
import 'package:flutter/material.dart';
import 'package:loglytics/loglytics.dart';
import 'analytics/counter_analytics.dart';
import 'implementations/analytics_implementation.dart';
import 'implementations/crash_reports_implementation.dart';
void main() {
Loglytics.setUp(
analyticsInterface: AnalyticsImplementation(Object()),
crashReportsInterface: CrashReportsImplementation(Object()),
analytics: (analyticsFactory) {
analyticsFactory.registerAnalytic(() => CounterAnalytics());
},
);
runApp(MyApp());
}
class MyApp extends StatelessWidget with Loglytics {
MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
log.warning('Starting app..');
return MaterialApp(
title: 'Loglytics Demo',
theme: ThemeData(
primarySwatch: Colors.red,
),
home: MyHomePage(title: 'Loglytics Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
late final Log log = Log(location: runtimeType.toString());
late final Loglytics<CounterAnalytics> loglytics =
Loglytics.create<CounterAnalytics>(location: runtimeType.toString());
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage>
with Loglytics<CounterAnalytics> {
int _counter = 0;
@override
void initState() {
widget.log.info('Test the individual logger one two three');
widget.loglytics.log.info('Test the individual loglytics one two three');
widget.loglytics.analytics.service.changed(subject: 'nothing');
widget.loglytics.analytics.service
.userProperty(property: 'this', value: 'is_so_cool');
analytics.viewPage();
super.initState();
}
void _incrementCounter() {
log.info('Pressing increment button..');
analytics.service.tapped(subject: 'button');
setState(
() {
_counter++;
log.info('The counter: $_counter');
analytics.service.incremented(
subject: analytics.counterButton,
parameters: {
'time': DateTime.now(),
},
);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: GestureDetector(
child: Text(widget.title),
onTap: () {
log.info('What a weird thing to do..');
analytics.service.tapped(subject: 'header');
},
),
),
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,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}