On this page
Add CUX to your Flutter app to collect navigation, interactions and available screenshots. Connect the widgets and navigation used by your app, then verify a test journey on Android and iOS.
Package covered: cux_analytics_sdk 0.0.27.
Requirements
The published package declares Dart ^3.4.3. Choose a Flutter version that satisfies this constraint and resolves the package's dependencies. The package's declared Flutter minimum alone is not enough to establish compatibility with its current dependencies.
Use a CUX mobile project and its token from Settings > Project. Verify native build requirements for your resolved dependencies on Android and iOS. This Flutter package is not an update to native Android SDK 1.2.0.
Install the package
Add the pinned version to your pubspec.yaml:
dependencies:
cux_analytics_sdk: 0.0.27
Run flutter pub get. On Android, check that the app's manifest permits internet access:
<uses-permission android:name="android.permission.INTERNET" />
Initialize the SDK
Initialize where a valid BuildContext has MediaQuery available. Wrap your app content with AnalyticsWidget and connect navigation.
This pattern keeps the initialization call out of repeated builds:
import 'package:flutter/material.dart';
import 'package:cux_analytics_sdk/analytics_sdk.dart';
import 'package:cux_analytics_sdk/analytics_widget.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
builder: (context, child) => AnalyticsRoot(child: child!),
home: const Scaffold(body: Center(child: Text('Home'))),
navigatorObservers: [
CuxAnalytics.createNavigationObserver(
rootWidget: this,
navigatorTag: 'main',
),
],
);
}
}
class AnalyticsRoot extends StatefulWidget {
const AnalyticsRoot({super.key, required this.child});
final Widget child;
@override
State<AnalyticsRoot> createState() => _AnalyticsRootState();
}
class _AnalyticsRootState extends State<AnalyticsRoot> {
bool initialized = false;
@override
void didChangeDependencies() {
super.didChangeDependencies();
if (!initialized) {
CuxAnalytics.init(
context,
'YOUR_MOBILE_PROJECT_TOKEN',
needConfirmToStart: true,
);
initialized = true;
}
}
@override
Widget build(BuildContext context) {
return AnalyticsWidget(child: widget.child);
}
}
Merge this into your existing app and builder rather than adding a second MaterialApp. Keep your existing observers and wrappers. The example waits for your app's consent handling to resume collection.
The navigation observer's rootWidget is a named argument in 0.0.27. Do not copy an older positional-argument example.
Choose your next step
| Task | Guide |
|---|---|
| Connect Navigator or router navigation and name destinations | Track and name Flutter screens |
| Identify accounts and record completed outcomes | Identify users and track Flutter custom events |
| Handle consent and hide sensitive widgets | Control Flutter collection and mask content |
| Diagnose build or recording problems | Troubleshoot your Flutter integration |
Verify your integration
Build and run the app on your target Android and iOS devices. Check the initial screen, navigation, interactions and available screenshots. Include custom/router-based screens and multiple navigators if your app uses them.
Test masking, consent withdrawal and any identity/events you added. A wrapper widget alone does not guarantee a complete recording of every layout or gesture.
For missing data, provide the package version, Flutter/Dart versions, resolved dependencies, device and reproduction steps to CUX. Do not share tokens or customer data.
Connect router-based navigation
Connect the listener to your existing router app. Follow the detailed guide.
Name a destination explicitly
Give a destination a stable, recognizable name. Follow the detailed guide.
Control data collection
Resume or stop collection from your consent handling. Follow the detailed guide.
Hide sensitive content
Mask sensitive widgets before capture. Follow the detailed guide.
Identify users
Use a stable internal identifier after login. Follow the detailed guide.
Track custom events
Send an event when your app confirms an outcome. Follow the detailed guide.