refactor:plausible
parent
37cd9272e7
commit
0656a92dc7
|
|
@ -1,5 +1,3 @@
|
||||||
// ignore_for_file: prefer_const_constructors
|
|
||||||
|
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
@ -8,12 +6,10 @@ import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
|
|
||||||
import 'objectbox.dart';
|
import 'objectbox.dart';
|
||||||
import 'package:wakelock/wakelock.dart';
|
import 'package:wakelock/wakelock.dart';
|
||||||
|
|
||||||
import 'package:event_bus_plus/event_bus_plus.dart';
|
import 'package:event_bus_plus/event_bus_plus.dart';
|
||||||
|
|
||||||
import 'package:mobdr/service/logger_util.dart';
|
import 'package:mobdr/service/logger_util.dart';
|
||||||
import 'package:mobdr/config/constant.dart';
|
import 'package:mobdr/config/constant.dart';
|
||||||
import 'package:mobdr/core/routes/plausible_tracker.dart';
|
|
||||||
import 'package:mobdr/cubit/language/language_cubit.dart';
|
import 'package:mobdr/cubit/language/language_cubit.dart';
|
||||||
import 'package:mobdr/cubit/language/app_localizations.dart';
|
import 'package:mobdr/cubit/language/app_localizations.dart';
|
||||||
import 'package:mobdr/cubit/language/initial_language.dart';
|
import 'package:mobdr/cubit/language/initial_language.dart';
|
||||||
|
|
@ -26,7 +22,6 @@ import 'package:mobdr/db/db_log.dart';
|
||||||
|
|
||||||
/// Provides access to the ObjectBox Store throughout the app.
|
/// Provides access to the ObjectBox Store throughout the app.
|
||||||
late ObjectBox objectbox;
|
late ObjectBox objectbox;
|
||||||
late PlausibleTracker plausible;
|
|
||||||
|
|
||||||
final EventBus eventBus = EventBus();
|
final EventBus eventBus = EventBus();
|
||||||
|
|
||||||
|
|
@ -96,19 +91,29 @@ class MyCustomScrollBehavior extends MaterialScrollBehavior {
|
||||||
class MyApp extends StatelessWidget with WidgetsBindingObserver {
|
class MyApp extends StatelessWidget with WidgetsBindingObserver {
|
||||||
@override
|
@override
|
||||||
void didChangeAppLifecycleState(AppLifecycleState state) async {
|
void didChangeAppLifecycleState(AppLifecycleState state) async {
|
||||||
if (state == AppLifecycleState.resumed) {
|
if (state == AppLifecycleState.paused) {
|
||||||
LoggerUtil.logNStackInfo("The application is in foreground");
|
LoggerUtil.logNStackInfo("The application is paused");
|
||||||
|
} else if (state == AppLifecycleState.resumed) {
|
||||||
|
LoggerUtil.logNStackInfo("The application is resumed");
|
||||||
|
|
||||||
// check if plausible is UP
|
// check if plausible is UP
|
||||||
plausible.enabled = await plausible.hello();
|
await PlausibleUtil.hello();
|
||||||
|
|
||||||
plausible.event(
|
PlausibleUtil.addEvent(
|
||||||
name: 'access',
|
name: 'access',
|
||||||
page: 'access',
|
page: 'access',
|
||||||
referrer: 'referrerPage',
|
referrer: 'referrerPage',
|
||||||
props: {
|
props: {
|
||||||
'name': SharedPrefs().login,
|
'name': SharedPrefs().login,
|
||||||
});
|
});
|
||||||
|
} else if (state == AppLifecycleState.inactive) {
|
||||||
|
LoggerUtil.logNStackInfo("The application is inactive");
|
||||||
|
} else if (state == AppLifecycleState.detached) {
|
||||||
|
LoggerUtil.logNStackInfo("The application is detached");
|
||||||
|
eventBus.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state == AppLifecycleState.resumed) {
|
||||||
} else if (state == AppLifecycleState.inactive) {
|
} else if (state == AppLifecycleState.inactive) {
|
||||||
LoggerUtil.logNStackInfo("The application runs in the background");
|
LoggerUtil.logNStackInfo("The application runs in the background");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,10 @@ class PlausibleUtil {
|
||||||
plausible!.enabled = await plausible!.hello();
|
plausible!.enabled = await plausible!.hello();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<void> hello() async {
|
||||||
|
plausible!.enabled = await plausible!.hello();
|
||||||
|
}
|
||||||
|
|
||||||
static void addEvent({
|
static void addEvent({
|
||||||
required String name,
|
required String name,
|
||||||
required String page,
|
required String page,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue