liquid_go_router 0.2.0 copy "liquid_go_router: ^0.2.0" to clipboard
liquid_go_router: ^0.2.0 copied to clipboard

GoRouter screen tracking for liquid_analytics — emit a liquid `screen` event on every route change, by route name or by matched path.

example/main.dart

// GoRouter screen tracking for liquid_analytics.
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:liquid_analytics/liquid_analytics.dart';
import 'package:liquid_go_router/liquid_go_router.dart';

late final Liquid liquid;

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  liquid = Liquid(sinks: [DebugSink()], consent: ConsentPolicy.allowAll);
  await liquid.init();

  // Option A — report GoRoute.name ("home", "product").
  final router = GoRouter(
    observers: [LiquidGoRouterObserver(liquid)],
    routes: [
      GoRoute(
        path: '/',
        name: 'home',
        builder: (context, state) => const _Page(title: 'Home'),
        routes: [
          GoRoute(
            path: 'product/:id',
            name: 'product',
            builder: (context, state) =>
                _Page(title: 'Product ${state.pathParameters['id']}'),
          ),
        ],
      ),
    ],
  );

  // Option B — report the matched path ("/product/42") instead. Use one or the
  // other; attaching both would emit two screen events per navigation.
  //
  // final binding = LiquidGoRouterBinding(liquid, router)..attach();

  runApp(MaterialApp.router(routerConfig: router));
}

class _Page extends StatelessWidget {
  const _Page({required this.title});

  final String title;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(title)),
      body: Center(
        child: ElevatedButton(
          onPressed: () => context.goNamed('product', pathParameters: {
            'id': '42',
          }),
          child: const Text('Go to product 42'),
        ),
      ),
    );
  }
}
0
likes
160
points
72
downloads

Documentation

API reference

Publisher

verified publisherketok.id

Weekly Downloads

GoRouter screen tracking for liquid_analytics — emit a liquid `screen` event on every route change, by route name or by matched path.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#analytics #flutter #go-router #navigation

License

MIT (license)

Dependencies

flutter, go_router, liquid_analytics, meta

More

Packages that depend on liquid_go_router