fix(app): scope user analytics listener to authenticated shells
This commit is contained in:
@@ -18,6 +18,7 @@ import 'package:payments/payments.dart';
|
|||||||
import 'package:profile/profile.dart';
|
import 'package:profile/profile.dart';
|
||||||
import 'package:settings/settings.dart';
|
import 'package:settings/settings.dart';
|
||||||
import 'package:sf_app_platform/core/config/app_mode.dart';
|
import 'package:sf_app_platform/core/config/app_mode.dart';
|
||||||
|
import 'package:sf_app_platform/widgets/user_identity_listener.dart';
|
||||||
import 'package:splash/splash.dart';
|
import 'package:splash/splash.dart';
|
||||||
|
|
||||||
final GlobalKey<NavigatorState> rootNavigatorKey = GlobalKey<NavigatorState>();
|
final GlobalKey<NavigatorState> rootNavigatorKey = GlobalKey<NavigatorState>();
|
||||||
@@ -75,7 +76,9 @@ void configureAppRouter() {
|
|||||||
),
|
),
|
||||||
StatefulShellRoute.indexedStack(
|
StatefulShellRoute.indexedStack(
|
||||||
builder: (context, state, navShell) {
|
builder: (context, state, navShell) {
|
||||||
return LegacyDashboardBuilder().build(context, navShell);
|
return UserIdentityListener(
|
||||||
|
child: LegacyDashboardBuilder().build(context, navShell),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
branches: [
|
branches: [
|
||||||
StatefulShellBranch(
|
StatefulShellBranch(
|
||||||
@@ -400,7 +403,9 @@ void configureAppRouter() {
|
|||||||
),
|
),
|
||||||
StatefulShellRoute.indexedStack(
|
StatefulShellRoute.indexedStack(
|
||||||
builder: (context, state, navShell) {
|
builder: (context, state, navShell) {
|
||||||
return DashboardBuilder().build(context, navShell);
|
return UserIdentityListener(
|
||||||
|
child: DashboardBuilder().build(context, navShell),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
branches: [
|
branches: [
|
||||||
StatefulShellBranch(
|
StatefulShellBranch(
|
||||||
|
|||||||
@@ -118,19 +118,6 @@ class SaveFamilyAppState extends ConsumerState<SaveFamilyApp>
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
SizeUtils.init(context: context);
|
SizeUtils.init(context: context);
|
||||||
|
|
||||||
ref.listen<AsyncValue<UserEntity>>(userInfoProvider, (previous, next) {
|
|
||||||
next.whenData((user) {
|
|
||||||
UserInfoTrackingListener(ref.read(sfTrackingProvider)).onUserChanged(
|
|
||||||
userId: user.id,
|
|
||||||
role: user.role,
|
|
||||||
language: user.language,
|
|
||||||
createdAtMillis: user.createdAt,
|
|
||||||
hasPhone: user.phone.isNotEmpty,
|
|
||||||
hasApiKey: user.hasApiKey,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return AppUpdateGate(
|
return AppUpdateGate(
|
||||||
child: MaterialApp.router(
|
child: MaterialApp.router(
|
||||||
title: 'SaveFamily',
|
title: 'SaveFamily',
|
||||||
|
|||||||
28
apps/mobile_app/lib/widgets/user_identity_listener.dart
Normal file
28
apps/mobile_app/lib/widgets/user_identity_listener.dart
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:sf_shared/sf_shared.dart';
|
||||||
|
import 'package:sf_tracking/sf_tracking.dart';
|
||||||
|
|
||||||
|
class UserIdentityListener extends ConsumerWidget {
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
const UserIdentityListener({super.key, required this.child});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
ref.listen<AsyncValue<UserEntity>>(userInfoProvider, (_, next) {
|
||||||
|
next.whenData((user) {
|
||||||
|
UserInfoTrackingListener(ref.read(sfTrackingProvider)).onUserChanged(
|
||||||
|
userId: user.id,
|
||||||
|
role: user.role,
|
||||||
|
language: user.language,
|
||||||
|
createdAtMillis: user.createdAt,
|
||||||
|
hasPhone: user.phone.isNotEmpty,
|
||||||
|
hasApiKey: user.hasApiKey,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user