nudgecore_v2 6.0.1 copy "nudgecore_v2: ^6.0.1" to clipboard
nudgecore_v2: ^6.0.1 copied to clipboard

Official NudgeCore V2 Flutter plugin for the NudgeNow platform.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:go_router/go_router.dart';

// import 'package:nudge_flt_ios/chat.dart';
// import 'package:nudge_flt_ios/chat_home.dart';

import 'package:nudgecore_v2_example/test.dart';
import 'package:nudgecore_v2/nudgecore_v2.dart';

// late Nudge nudge;

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // await Future.delayed(Duration(milliseconds: 500));

  // nudge = Nudge(
  //   apiKey:
  //       // "RgkVNlpy3MOhn+ufphZ9g3PqiUkwDgsYcpGMz6X2Bz+kBVQjGvthHyn18ROBLu60ZnMlbJF6aLar7vAx0mUreA==",
  //       // "4Vu7hKPPifpksq0nIDTsaQRHChDXCh+vDyBYC9oNgQV+5irUnZlkUevfSZrueXG5zQhNi4K1HKZ1t2sMplX7sg==",
  //       "hD1ZnyzKA3ukf7kCRFSlqVp2ktrRhkWj+AcDV6yn4xtilDmOmAslDe4YJdpd5n6m+Dxvw47U3MsJVP3UW9NuLw==",
  //   // "",
  //   // "RgkVNlpy3MOhn+ufphZ9g3PqiUkwDgsYcpGMz6X2Bz+kBVQjGvthHyn18ROBLu60ZnMlbJF6aLar7vAx0mUreA==",
  //   // "N7Vh+f9lqvRblsY8m5RpiHoUKk9qtAhMl+/ojr3SZs9pOVm/nBM0VNro/8UkwFtlYGP/x6WnmaxVZJfMi3RZ9A==",
  //   // "lb8+xKosbtIuP0RMfIP6AE2mOnQrwUUDTjCTERjrUR+OiKB/X1ml8Lfl1w/ld/ro9P/Z1xFCBVUHMzKr/pwPIw==",
  //   // US Prod
  //   debugMode: true,
  //   region: Region.IN,
  //   // registerAuthKeyCallback: (key) async {
  //   //   print("Static key callback triggered, key: $key");
  //   //   // wait for 2 secs
  //   //   // await Future.delayed(const Duration(seconds: 2));
  //   //   // send refresh token
  //   //   return "reqres-free-v1";
  //   // },
  // );

  Nudge(
    // disableNudge: false,
    apiKey:
        // "RgkVNlpy3MOhn+ufphZ9g3PqiUkwDgsYcpGMz6X2Bz+kBVQjGvthHyn18ROBLu60ZnMlbJF6aLar7vAx0mUreA==",
        // "4Vu7hKPPifpksq0nIDTsaQRHChDXCh+vDyBYC9oNgQV+5irUnZlkUevfSZrueXG5zQhNi4K1HKZ1t2sMplX7sg==",
        "hD1ZnyzKA3ukf7kCRFSlqVp2ktrRhkWj+AcDV6yn4xtilDmOmAslDe4YJdpd5n6m+Dxvw47U3MsJVP3UW9NuLw==",
    // "",
    // "RgkVNlpy3MOhn+ufphZ9g3PqiUkwDgsYcpGMz6X2Bz+kBVQjGvthHyn18ROBLu60ZnMlbJF6aLar7vAx0mUreA==",
    // "N7Vh+f9lqvRblsY8m5RpiHoUKk9qtAhMl+/ojr3SZs9pOVm/nBM0VNro/8UkwFtlYGP/x6WnmaxVZJfMi3RZ9A==",
    // "lb8+xKosbtIuP0RMfIP6AE2mOnQrwUUDTjCTERjrUR+OiKB/X1ml8Lfl1w/ld/ro9P/Z1xFCBVUHMzKr/pwPIw==",
    // "UiOMcNyDxJwfIZE2WZL7qzreUhH35SqtRN4r/MTx3cU5bjl1zVqlk7a6A4D3Je2ury/n0pqODWRjfLgL6zM1IA==",
    // US Prod
    debugMode: true,
    region: Region.IN,
    // registerAuthKeyCallback: (key) async {
    //   print("Static key callback triggered, key: $key");
    //   // wait for 2 secs
    //   // await Future.delayed(const Duration(seconds: 2));
    //   // send refresh token
    //   return "reqres-free-v1";
    // },
  );

  Nudge.getInstance().config(navigatorKey: clientNavigatorKey);
if(  Nudge._instance != null){
  
}
  runApp(const MainApp());
}

@pragma('vm:entry-point')
void entrypointB() {
  const MethodChannel("debug_channel").invokeMethod("entrypointB_started");

  runApp(
    const MaterialApp(
      home: Scaffold(body: Center(child: Text("Running from entrypointB"))),
    ),
  );
}

final NudgeTrackerObserver _nudgeTrackerObserver = NudgeTrackerObserver();

final GlobalKey<NavigatorState> clientNavigatorKey = GlobalKey<NavigatorState>(
  debugLabel: "parent",
);

const channel = MethodChannel('rcg_flutter');

final GoRouter _router = GoRouter(
  navigatorKey: clientNavigatorKey,
  observers: [_nudgeTrackerObserver],
  routes: [
    GoRoute(path: '/', builder: (context, state) => const TestPage()),
    // GoRoute(path: '/chat', builder: (context, state) => const ChatHomePage()),
    // GoRoute(path: '/chat-page', builder: (context, state) => const ChatPage()),
    GoRoute(path: '/ios', builder: (context, state) => const IosScreen()),
    GoRoute(path: '/main', builder: (context, state) => const MainScreen()),
    GoRoute(
      path: '/challenge',
      builder: (context, state) => Scaffold(
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text(
              'Challenge',
              style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 20),
            const Text(
              'This is the challenge page.',
              style: TextStyle(fontSize: 18),
            ),
            ElevatedButton(
              onPressed: () {
                context.go('/');
              },
              child: const Text('Go Back'),
            ),
          ],
        ),
      ),
    ),
    GoRoute(
      path: '/demo',
      builder: (context, state) => Scaffold(
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text(
              'Demo',
              style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 20),
            const Text(
              'This is the demo page.',
              style: TextStyle(fontSize: 18),
            ),
            ElevatedButton(
              onPressed: () {
                context.go('/');
              },
              child: const Text('Go Back'),
            ),
          ],
        ),
      ),
    ),
  ],
);

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    // entrypointB();
    // return MaterialApp(
    //   color: Colors.white,
    //   debugShowCheckedModeBanner: false,
    //   navigatorKey: Nudge.nudgeNavigatorKey,
    //   routes: {
    //     '/': (context) => const TestPage(),
    //     '/ios': (context) => const IosScreen(),
    //   },
    // );
    return MaterialApp.router(
      debugShowCheckedModeBanner: false,
      routerConfig: _router,
      // builder: (context, child) {
      //   // const mediaQuery = MediaQueryData(
      //   //   textScaleFactor: 1.0,
      //   // );
      //   return MediaQuery(data: MediaQueryData(), child: child!);
      // },
    );
  }
}

class MainScreen extends StatelessWidget {
  const MainScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Nudge Core V2')),
      bottomNavigationBar: BottomNavigationBar(
        items: const [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
          BottomNavigationBarItem(icon: Icon(Icons.apple), label: 'iOS'),
        ],
        onTap: (index) {
          if (index == 0) {
            Navigator.pushNamed(context, '/');
          } else {
            Navigator.pushNamed(context, '/ios');
          }
        },
      ),
      body: SingleChildScrollView(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          mainAxisSize: MainAxisSize.max,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            ElevatedButton(
              key: NudgeWidgetTracker.register("search_field"),
              onPressed: () {
                Nudge.getInstance().userIdentifier(
                  externalId: "test_android_1_in",
                );
              },
              child: const Text('Identify User'),
            ),
            // SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                Nudge.getInstance().track(event: "test_event");
              },
              child: const Text('Track Banner'),
            ),
            // SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                Nudge.getInstance().track(event: "test_event_2");
              },
              child: const Text('Track Nudges'),
            ),
            const SizedBox(height: 20),
            const NudgeAppComponent(id: "create_banner"),
            const SizedBox(height: 20),
            const NudgeStories(id: "nudge_stories"),
            ElevatedButton(
              onPressed: () {
                // Nudge.getInstance().registerRefreshTokenCallback(() async {
                //   print("Refresh token callback triggered");
                //   // wait for 2 secs
                //   await Future.delayed(Duration(seconds: 2));
                //   // send refresh token
                //   return "new_refresh_token";
                // });

                // Nudge.getInstance().registerApi((key) async {
                //   print("Static key callback triggered, key: $key");
                //   // wait for 2 secs
                //   // await Future.delayed(const Duration(seconds: 2));
                //   // send refresh token
                //   return "reqres-free-v1";
                // });
              },
              child: const Text('Refresh Token'),
            ),
            const SizedBox(height: 600),
          ],
        ),
      ),
    );
  }
}

class IosScreen extends StatelessWidget {
  const IosScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('iOS Screen')),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.max,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          ElevatedButton(
            onPressed: () {
              // Nudge.getInstance().userIdentifier(externalId: "test_ios_1");
              Nudge.getInstance().track(event: "challenges_page_open");
            },
            child: const Text('Challenges Page Open'),
          ),
          const SizedBox(height: 20),
          const NudgeAppComponent(id: "create_banner"),
          const SizedBox(height: 20),
          ElevatedButton(
            onPressed: () {
              Nudge.getInstance().track(event: "home_page_open");
            },
            child: const Text('Track Home Page Open'),
          ),
          const SizedBox(height: 20),
          ElevatedButton(
            onPressed: () {
              // Nudge.getInstance().registerRefreshTokenCallback(() async {
              //   print("Refresh token callback triggered");
              //   // wait for 2 secs
              //   await Future.delayed(Duration(seconds: 2));
              //   // send refresh token
              //   return "new_refresh_token";
              // });

              // Nudge.getInstance().registerApi((key) async {
              //   print("Static key callback triggered, key: $key");
              //   // wait for 2 secs
              //   // await Future.delayed(const Duration(seconds: 2));
              //   // send refresh token
              //   return "reqres-free-v1";
              // });
            },
            child: const Text('Refresh Token'),
          ),
        ],
      ),
    );
  }
}
2
likes
100
points
2.38k
downloads

Publisher

unverified uploader

Weekly Downloads

Official NudgeCore V2 Flutter plugin for the NudgeNow platform.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, path, path_provider, plugin_platform_interface, rxdart, shared_preferences, sqflite, url_launcher

More

Packages that depend on nudgecore_v2

Packages that implement nudgecore_v2