Skip to main content
Version: 1.0.0

Installation

This document will guide you through the installation of the Nudge SDK in your Flutter application

The nudgecore_v2 package is the core of the Nudge Flutter ecosystem. It tracks events, users, and app screens, and handles reporting to measure campaign performance. This package communicates with various plugins, which extend its functionality but cannot operate without it. nudgecore_v2 is a required dependency for every plugin.

Find the latest version of nudgecore_v2 here.

Installing the package

Add nudgecore_v2 to your pubspec.yaml file:

dependencies:
nudgecore_v2: ^latest_version

Run the following command to fetch the package:

flutter pub get

Initialization

Import the nudgecore_v2 package in your Dart file:

import 'package:nudgecore_v2/core/Nudge.dart';

Create an instance of the Nudge class with your API_KEY:

Nudge nudge = Nudge(
apiKey: "API_KEY",
debugMode: true);
warning

Call Nudge() inside the runApp() method of your flutter application

note

You need a nudge account to get your API_KEY. See how to create one here.

Usage

Using NudgeProvider

Wrap your MaterialApp with the NudgeProvider to enable integration with Nudge.

Parameters for NudgeProvider

  • nudgeInstance (required): Pass the Nudge instance you initialized above.
  • plugins: Pass the plugins you want to use here.
  • navigatorKey (required): Pass your navigator key, or use NudgeProviderState.navigatorKey.
  • child (required): Pass your main MaterialApp widget here.

Using Your Own Navigator Key
If you have your own navigator key, pass it to both the NudgeProvider and MaterialApp:



return NudgeProvider(
nudgeInstance: nudge,
plugins: [],
navigatorKey: <YOUR_NAVIGATOR_KEY>,
child: MaterialApp(
navigatorKey: <YOUR_NAVIGATOR_KEY>,
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Home(),
),
);

Using NudgeProviderState Navigator Key
If you don't have your own navigator key, you can use the one provided by NudgeProviderState:

import 'package:nudgecore_v2/core/nudge_provider.dart';

return NudgeProvider(
nudgeInstance: nudge,
plugins: [],
navigatorKey: NudgeProviderState.navigatorKey,
child: MaterialApp(
navigatorKey: NudgeProviderState.navigatorKey,
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Home(),
),
);

warning

Ensure the same navigator key is passed to both NudgeProvider and MaterialApp