mbautomation 0.0.1+2 copy "mbautomation: ^0.0.1+2" to clipboard
mbautomation: ^0.0.1+2 copied to clipboard

outdated

MBAutomation plugin for MBurger that lets you present push and in app messages based on the behavior of the user.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:mbautomation/mbautomation.dart';
import 'package:mburger/mburger.dart';
import 'package:mbaudience/mbaudience.dart';
import 'package:mbmessages/mbmessages.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    MBManager.shared.apiToken = 'YOUR_API_TOKEN';
    MBManager.shared.plugins = [
      MBAutomation(),
      MBAudience(),
      MBMessages(
        onButtonPressed: (button) {
          print(button);
        },
      ),
    ];

    _configurePushNotifications();

    super.initState();
  }

  Future<void> _configurePushNotifications() async {
    MBPush.pushToken = 'YOUR_PUSH_API_KEY';
    MBPush.onToken = (token) async {
      print("Token received $token");
      await MBPush.registerDevice(token).catchError(
        (error) => print(error),
      );
      await MBPush.registerToTopics(
        [
          await MBMessages.projectPushTopic(),
          await MBMessages.devicePushTopic(),
          MPTopic(code: 'Topic'),
        ],
      ).catchError(
        (error) => print(error),
      );
      print('Registered');
    };

    MBPush.configure(
      onNotificationArrival: (notification) {
        print("Notification arrived: $notification");
      },
      onNotificationTap: (notification) {
        print("Notification tapped: $notification");
      },
      androidNotificationsSettings: MPAndroidNotificationsSettings(
        channelId: 'mpush_example',
        channelName: 'mpush',
        channelDescription: 'mpush',
        icon: '@mipmap/icon_notif',
      ),
    );

    MBPush.requestToken();

    Map<String, dynamic> launchNotification = await MBPush.launchNotification();
    print(launchNotification);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorObservers: [MBAutomationNavigatorObserver()],
      home: MBMessagesBuilder(
        child: Scaffold(
          appBar: AppBar(
            title: const Text('MBAudience example app'),
          ),
          body: Center(
            child: FlatButton(
              child: Text('Send Event'),
              onPressed: () => _sendEvent(),
            ),
          ),
        ),
      ),
    );
  }

  void _sendEvent() {
    MBAutomation.sendEvent('EVENT_NAME');
  }
}
6
likes
0
pub points
34%
popularity

Publisher

verified publishermburger.cloud

MBAutomation plugin for MBurger that lets you present push and in app messages based on the behavior of the user.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, http, mbaudience, mbmessages, mburger, path, path_provider, shared_preferences, sqflite

More

Packages that depend on mbautomation