turbolytics 1.1.0
turbolytics: ^1.1.0 copied to clipboard
An efficient, user-friendly way to implement logs, analytics and crash reports into your projects.
import 'package:flutter/material.dart';
import 'package:turbolytics/turbolytics.dart';
import 'analytics/counter_analytics.dart';
import 'implementations/analytics_implementation.dart';
import 'implementations/crash_reports_implementation.dart';
void main() {
Turbolytics.setUp(
analyticsInterface: AnalyticsImplementation(Object()),
crashReportsInterface: CrashReportsImplementation(Object()),
analytics: (analyticsFactory) {
analyticsFactory.registerAnalytic(() => CounterAnalytics());
},
);
runApp(MyApp());
}
class MyApp extends StatelessWidget with Turbolytics {
MyApp({super.key});
@override
Widget build(BuildContext context) {
log.warning('Starting app..');
return MaterialApp(
title: 'Turbolytics Demo',
theme: ThemeData(primarySwatch: Colors.red),
home: MyHomePage(title: 'Turbolytics Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({super.key, required this.title});
final String title;
late final TLog log = TLog(location: runtimeType.toString());
late final Turbolytics<CounterAnalytics> turbolytics =
Turbolytics.create<CounterAnalytics>(location: runtimeType.toString());
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage>
with Turbolytics<CounterAnalytics> {
int _counter = 0;
@override
void initState() {
widget.log.info('Test the individual logger one two three');
widget.turbolytics.log.info(
'Test the individual turbolytics one two three',
);
widget.turbolytics.analytics.service.changed(subject: 'nothing');
widget.turbolytics.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),
),
);
}
}