starter_architecture_flutter_firebase
starter_architecture_flutter_firebase copied to clipboard
Approach for Firebase Analytic in this setup?
What is you advice for implement firebase_analytics in this setup?
One possible way of doing this to create a FirbaseAnalyticsService
with all your domain-specific analytics APIs.
This can be injected inside the MultiProvider
at the root of the widget tree.
And it can be passed as a constructor argument to all view models that need it.
View models are a good place to put analytics calls, as they are easy to test.
Makes sense?
Yes make sense, I now had it this way, but in problems with the Tabbar items....
authServiceBuilder: (_) => FirebaseAuthService(),
databaseBuilder: (_, uid) => FirestoreDatabase(uid: uid),
));
class MyApp extends StatelessWidget {
const MyApp({Key key, this.authServiceBuilder, this.databaseBuilder})
: super(key: key);
// Expose builders for 3rd party services at the root of the widget tree
// This is useful when mocking services while testing
final FirebaseAuthService Function(BuildContext context) authServiceBuilder;
final FirestoreDatabase Function(BuildContext context, String uid)
databaseBuilder;
static FirebaseAnalytics analytics = FirebaseAnalytics();
static FirebaseAnalyticsObserver observer =
FirebaseAnalyticsObserver(analytics: analytics);
@override
Widget build(BuildContext context) {
// MultiProvider for top-level services that don't depend on any runtime values (e.g. uid)
return MultiProvider(
providers: [
Provider<FirebaseAnalytics>.value(value: analytics),
Provider<FirebaseAnalyticsObserver>.value(value: observer),
Provider<FirebaseAuthService>(
create: authServiceBuilder,
),
],
child: AuthWidgetBuilder(
databaseBuilder: databaseBuilder,
builder: (BuildContext context, AsyncSnapshot<User> userSnapshot) {
return MaterialApp(
theme: ThemeData(primarySwatch: Colors.green),
debugShowCheckedModeBanner: false,
home: AuthWidget(userSnapshot: userSnapshot),
onGenerateRoute: Router.onGenerateRoute,
);
},
),
);
}
}
this is a null
navigatorObservers: <NavigatorObserver>[observer],
You should be able to add your observer:
final observer = Provider.of<FirebaseAnalyticsObserver>(context);
to your BottomNavigationBar
's navigationObservers
.
Not sure what is null
in your code.