Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Approach for Firebase Analytic in this setup? #5

Open
FredvanRijswijk opened this issue Feb 13, 2020 · 3 comments
Open

Approach for Firebase Analytic in this setup? #5

FredvanRijswijk opened this issue Feb 13, 2020 · 3 comments
Labels
question Further information is requested

Comments

@FredvanRijswijk
Copy link

What is you advice for implement firebase_analytics in this setup?

@bizz84
Copy link
Owner

bizz84 commented Feb 13, 2020

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?

@bizz84 bizz84 added the question Further information is requested label Feb 13, 2020
@FredvanRijswijk
Copy link
Author

FredvanRijswijk commented Feb 14, 2020

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],

@bizz84
Copy link
Owner

bizz84 commented Feb 15, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants