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

[pending analysis]

Nudge Core V2

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:nudgecore_v2/nudgecore_v2.dart';

var apikeyStag =
    "CS8Hfvg7p6If7cVIf4xCr0/Z5RBbx0JjKScuP8HE277XXW+B+aNzgkRsaggrvNKesW427d4cd01WzQHLlHU0lw==";
var apikeyProd =
    "hD1ZnyzKA3ukf7kCRFSlqVp2ktrRhkWj+AcDV6yn4xtilDmOmAslDe4YJdpd5n6m+Dxvw47U3MsJVP3UW9NuLw==";

void main() {
  // NudgeGlobalCallback.eventBus.onEvent('StoryCtaClicked')?.listen((data) {
  //   print('Link : $data');
  //   // Handle the event data here
  // });
  // NudgeGlobalCallback.eventBus.onEvent('QuizOpen')?.listen((data) {
  //   print('Received Callback data for Event Quiz Open : $data');
  //   // Handle the event data here
  // });
  // NudgeGlobalCallback.eventBus.onEvent('StoryClosed')?.listen((data) {
  //   print("it is closed");
  // });
  WidgetsFlutterBinding.ensureInitialized();

  runApp(MyApp());
}

Nudge nudge = Nudge(
  apiKey: apikeyStag,
  debugMode: true,
);

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  _MyAppState createState() => _MyAppState();

// @override
// void onEvent(NudgeCallback event) {
//    if(event is NudgeStoriesCallback){
//      print(event.action);
//    }
//
// }
}

class _MyAppState extends State<MyApp> {
  MyApp() {
    // NudgeGlobalCallback.eventBus.onEvent('StoryClosed')?.listen((data) {
    //   print("it is closed");
    // });
  }

  void initState() {
    super.initState();
    //NudgeGCallbackManager.registerListener(widget);
  }

  // final NudgeTrackerObserver _trackerObserver = NudgeTrackerObserver();
  int _selectedIndex = 0;

  final List<Widget> _widgetOptions = <Widget>[
    ScreenOne(),
    ScreenTwo(),
    ScreenThree(),
    ScreenFour(),
  ];

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    //nudge.initSession(uid:"abc");
    // nudge.userIdentifier(
    //   externalId: "DemoUser",
    // );

    //print("called build");
    // nudgev2.nudgeIdentifier();
    // var libs = NudgeVersionRegistry.getRegisteredLibraries();
    // print(libs);

    // return Localizations.override(
    //   context: context,
    //   locale: const Locale('en'),
    //   child:
    // );
    // return MaterialApp(
    //     home: );

    // NudgeGlobalCallback.eventBus.onEvent('userInit')?.listen((data) {
    //   print('Received event data2: $data');
    //   // Handle the event data here
    // });

    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
        useMaterial3: true,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text('Your App Title'),
        ),
        body: Center(
          child: _widgetOptions.elementAt(_selectedIndex),
        ), // Render the HomeScreen as the body of the Scaffold
        bottomNavigationBar: CustomBottomNavigationBar(
          onItemSelected: _onItemTapped, // Passing the callback
        ),
      ),
      routes: {
        "/home": (context) => ScreenOne(),
        // Equivalent to "/"
        "/home/screentwo": (context) => ScreenTwo(),
        // Define other routes here if needed
        "/home/screenthree": (context) => ScreenThree(),
        "/home/screenfour": (context) => ScreenFour(),
      },
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();

// @override
// void onEvent(NudgeCallback event) {
//   if(event is NudgeStoriesCallback){
//     print("2nd ${event.action}");
//   }
// }
}
// Future<void> _initializeUserIdentifier() async {
//   // Add a delay before executing the nudge.userIdentifier method
//   await Future.delayed(Duration(seconds: 5)); // Set the desired delay duration
//   nudge.userIdentifier(
//     externalId: "tarunesh",
//   );
// }

class _MyHomePageState extends State<MyHomePage>
    with SingleTickerProviderStateMixin {
  TabController? _tabController;

  final List<Widget> _widgetOptions = [
    // Your different screens/widgets for each tab
    ScreenOne(),
    ScreenTwo(),
    ScreenThree(),
    ScreenFour(),
  ];

  @override
  void initState() {
    super.initState();
    // _initializeUserIdentifier();
    //NudgeGCallbackManager.registerListener(widget);
    _tabController = TabController(length: 4, vsync: this);
  }

  @override
  void dispose() {
    _tabController?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Tab Navigation Demo'),
        bottom: TabBar(
          controller: _tabController,
          tabs: [
            Tab(
                icon: Icon(Icons.home),
                text: 'Home',
                key: NudgeWidgetTracker.register("HomeTab")),
            Tab(
                icon: Icon(Icons.business),
                text: 'Business',
                key: NudgeWidgetTracker.register("Business")),
            Tab(
                icon: Icon(Icons.school),
                text: 'School',
                key: NudgeWidgetTracker.register("School")),
            Tab(icon: Icon(Icons.settings), text: 'Settings'),
          ],
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        children: _widgetOptions,
      ),
    );
  }
}

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();

// @override
// void onEvent(NudgeCallback event) {
//  if(event is NudgeStoriesCallback){
//    print("2nd"+event.action);
//  }
//  if(event is NudgeQuizCallback){
//
//  }
// }
}

class _HomeScreenState extends State<HomeScreen> {
  int _selectedIndex = 0;

  final List<Widget> _widgetOptions = <Widget>[
    ScreenOne(),
    ScreenTwo(),
    ScreenThree(),
    ScreenFour(),
  ];

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  void initState() {
    super.initState();
    // nudge.userIdentifier(
    //       externalId: "DemoUser",
    //     );

    //NudgeGCallbackManager.registerListener(widget);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Bottom Navigation Demo'),
      ),
      body: Center(
        child: _widgetOptions.elementAt(_selectedIndex),
      ),
      bottomNavigationBar: CustomBottomNavigationBar(
        onItemSelected: _onItemTapped, // Passing the callback
      ),
      // bottomNavigationBar: BottomNavigationBar(
      //   items: const <BottomNavigationBarItem>[
      //     BottomNavigationBarItem(
      //       icon: Icon(Icons.home),
      //       label: 'Home',
      //     ),
      //     BottomNavigationBarItem(
      //       icon: Icon(Icons.business),
      //       label: 'Business',
      //     ),
      //     BottomNavigationBarItem(
      //       icon: Icon(Icons.school),
      //       label: 'School',
      //     ),
      //     BottomNavigationBarItem(
      //       icon: Icon(Icons.settings),
      //       label: 'Settings',
      //     ),
      //   ],
      //   currentIndex: _selectedIndex,
      //   onTap: _onItemTapped,
      //   backgroundColor: Colors.blue, // Change the background color
      //   selectedItemColor: Colors.white, // Change the selected item color
      //   unselectedItemColor: Colors.grey, // Change the unselected item color
      //   type: BottomNavigationBarType.fixed, // This ensures the background color fills the bar
      // ),
      // This positions the FAB at the center of the bottom app bar.
      // Choose another location if it suits your design better.
    );
  }
}

class CustomBottomNavigationBar extends StatefulWidget {
  final Function(int) onItemSelected;

  CustomBottomNavigationBar({required this.onItemSelected}) : super();

  @override
  _CustomBottomNavigationBarState createState() =>
      _CustomBottomNavigationBarState();
}

class _CustomBottomNavigationBarState extends State<CustomBottomNavigationBar> {
  int _selectedIndex = 0;

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
    widget.onItemSelected(index); // Call the callback with the new index
  }

  @override
  Widget build(BuildContext context) {
    return BottomAppBar(
      color: Colors.blue,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
          _buildNavItem(Icons.home, 'Home', 0),
          _buildNavItem(Icons.business, 'Business', 1),
          _buildNavItem(Icons.school, 'School', 2),
          _buildNavItem(Icons.settings, 'Settings', 3),
        ],
      ),
    );
  }

  Widget _buildNavItem(IconData icon, String label, int index) {
    return GestureDetector(
      onTap: () => _onItemTapped(index),
      child: Container(
        padding: EdgeInsets.symmetric(vertical: 5, horizontal: 16),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Icon(icon,
                color: _selectedIndex == index ? Colors.white : Colors.grey),
            Text(label,
                style: TextStyle(
                    color:
                        _selectedIndex == index ? Colors.white : Colors.grey)),
          ],
        ),
        key: NudgeWidgetTracker.register(label), // Assign the GlobalKey here
      ),
    );
  }
}

class CircleItem extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 10.0),
      width: 150.0,
      height: 150.0,
      decoration: BoxDecoration(
        color: Colors.blue,
        shape: BoxShape.circle,
      ),
    );
  }
}

class ScreenOne extends StatelessWidget {
  // Widget dialog(
  //     {required String content,
  //       required onTap,
  //       String yesText = "Yes",
  //       String noText = "No",
  //       Color yesColor = Colors.blue,
  //       Color noColor = Colors.red}) {
  //   //final colorTheme = Theme.of(Get.context!);
  //   return
  //     AlertDialog(
  //       content: SizedBox(
  //         height: 70,
  //         child: Text(
  //           content,
  //           maxLines: 3,
  //           textAlign: TextAlign.center,
  //           // fontsize: 16,
  //           // width: 250,
  //           // color: colorTheme.textTheme.bodySmall!.color!,
  //         ),
  //       ),
  //       actions: [
  //         Row(
  //           mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  //           children: [
  //             MaterialButton(
  //                 onPressed: onTap,
  //                 shape: RoundedRectangleBorder(
  //                     borderRadius: BorderRadius.circular(25)),
  //                 color: yesColor,
  //                 child: Padding(
  //                   padding: const EdgeInsets.symmetric(
  //                       vertical: 10, horizontal: 10),
  //                   child: Text(
  //                     "Yes",
  //                     // textAlignment: TextAlign.center,
  //                     // fontsize: 16,
  //                     // textColor: AppColor.white
  //                   ),
  //                 )),
  //             MaterialButton(
  //                 onPressed: () {
  //                   Get.back();
  //                 },
  //                 shape: RoundedRectangleBorder(
  //                     borderRadius: BorderRadius.circular(25)),
  //                 color: noColor,
  //                 child: Padding(
  //                   padding: const EdgeInsets.symmetric(
  //                       vertical: 10, horizontal: 10),
  //                   child: Text(
  //                     "no",
  //                   ),
  //                 )),
  //           ],
  //         )
  //       ],
  //     );
  // }
  // void _showExitConfirmationDialog(BuildContext context) {
  //   showDialog(
  //     context: context,
  //     builder: (BuildContext context) {
  //       return AlertDialog(
  //         title: Text('Exit App'),
  //         content: Text('Do you want to quit the app?'),
  //         actions: <Widget>[
  //           TextButton(
  //             child: Text('No'),
  //             onPressed: () {
  //               Get.back; // Dismiss the dialog
  //             },
  //           ),
  //           TextButton(
  //             child: Text('Yes'),
  //             onPressed: () {
  //               // Close the app
  //               // For iOS, this behavior is against the human interface guidelines,
  //               // so consider alternatives for iOS.
  //               SystemNavigator.pop(); // Works for Android
  //             },
  //           ),
  //         ],
  //       );
  //     },
  //   );
  // }
  @override
  Widget build(BuildContext acontext) {
    // NudgeGCallbackManager.registerListener(this);
    // nudge.userIdentifier(
    //   externalId: "DemoUser",
    // );
    // NudgeGlobalCallback.eventBus.onEvent('eventA')?.listen((data) {
    //   print('Received event data1: $data');
    //   // Handle the event data here
    // });
    return Scaffold(
        floatingActionButton: FloatingActionButton(
          key: NudgeWidgetTracker.register("fab_btn"),
          onPressed: () {
            // Action to be performed when FAB is pressed
            // You can navigate to another screen, open a dialog, etc.
          },
          child: Icon(Icons.add), // Icon inside FAB
          // You can customize your FAB further here
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
        body: SingleChildScrollView(
          // Wrap your Column with SingleChildScrollView
          child: SizedBox(
            width: double.infinity,
            child: Column(
              children: <Widget>[
                // const NudgeStories(),
                ElevatedButton(
                  key: NudgeWidgetTracker.register("Quiz"),
                  onPressed: () {
                    // Nudge.getInstance().track(event: "stories_open1");
                    // Map<String, dynamic>? props = {};
                    // props["tier"] = "Gold";
                    // props["location"] = "India";
                    // props["subcribe"] = "No";
                    Nudge.getInstance().track(event: "hey_stories");
                    //Nudge.getInstance().updateUserProps(name: "mshubhasai",properties:props );
                  },
                  child: Text('Track Stories'),
                ),
                ElevatedButton(
                  key: NudgeWidgetTracker.register("Quiz1"),
                  onPressed: () {
                    //Nudge(apiKey: "",debugMode: false,getDeviceInfo: false,getLifecycleInfo: false).nudgeDeepLinkNavigator("/home/screentwo");
                    //Nudge.getInstance().track(event: "show_story");
                    // nudge.userIdentifier(
                    //   externalId: "tarunesh",
                    // );
                    // _showExitConfirmationDialog(acontext);
                    //Get.dialog(dialog(content: "content", onTap:() {exit(0);}));
                    // nudge.userIdentifier(
                    //   externalId: "DemoUser",
                    // );
                    Nudge.getInstance().userIdentifier(
                      externalId: "DemoUser",
                    );

                    // Nudge.getInstance().track(event: "quiz_open1");
                  },
                  child: Text('identifier'),
                ),
                ElevatedButton(
                  key: NudgeWidgetTracker.register("Stories"),
                  onPressed: () {
                    //Nudge(apiKey: "",debugMode: false,getDeviceInfo: false,getLifecycleInfo: false).nudgeDeepLinkNavigator("/home/screentwo");

                    // _showExitConfirmationDialog(acontext);
                    //Get.dialog(dialog(content: "content", onTap:() {exit(0);}));
                    Nudge.getInstance().userSignOut();
                  },
                  child: Text('Reset User'),
                ),
                // NudgeStories(handleCustomDeepLink: true,trayItemHeight: 150,trayItemWidth: 150,children: [
                //   for (int i = 0; i < 5; i++) CircleItem(),
                // ],trayVerticalAlignment: TrayAlignment.center,),
                Container(
                  key: NudgeWidgetTracker.register("ScreenOneContainer"),
                  height: MediaQuery.of(acontext).size.height / 2,
                  width: MediaQuery.of(acontext).size.width / 2,
                ),
                ...List.generate(50, (index) {
                  // Using the spread operator (...) to include the list of Text widgets
                  return Text('Greeting Home ${index + 1}',
                      key: NudgeWidgetTracker.register(
                          'Greeting Home ${index + 1}'));
                }),
              ],
            ),
          ),
        ));
  }

// @override
// void onEvent(NudgeCallback event) {
//   if(event is NudgeStoriesCallback){
//     print("here"+event.action);
//   }
// }
}

class ScreenTwo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: SingleChildScrollView(
      // Wrap your Column with SingleChildScrollView
      child: SizedBox(
        width: double.infinity,
        child: Column(
          children: <Widget>[
            ElevatedButton(
              onPressed: () {
                //nudge.track(type: 'hey_nudges101');
              },
              child: Text('Track Nudge'),
            ),
            ...List.generate(50, (index) {
              // Using the spread operator (...) to include the list of Text widgets
              return Text('Greeting Business ${index + 1}',
                  key: NudgeWidgetTracker.register(
                      'Greeting Business ${index + 1}'));
            }),
          ],
        ),
      ),
    ));
  }
}

class ScreenThree extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return const Scaffold(body: Text('School Screen'));
  }
}

class ScreenFour extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Text('Settings Screen'),
    );
  }
}
1
likes
0
points
1.39k
downloads

Publisher

unverified uploader

Weekly Downloads

Nudge Core V2

Homepage

License

(pending) (license)

Dependencies

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

More

Packages that depend on nudgecore_v2