mbautomation 2.1.3 copy "mbautomation: ^2.1.3" to clipboard
mbautomation: ^2.1.3 copied to clipboard

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(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

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

    _configurePushNotifications();

    super.initState();
  }

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

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

    MBMessages.requestToken();

    Map<String, dynamic>? launchNotification =
        await MBMessages.launchNotification();
    debugPrint(launchNotification?.toString());
  }

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

  void _sendEvent() {
    MBAutomation.sendEvent('EVENT_NAME');
  }
}
6
likes
150
points
50
downloads

Publisher

verified publishermburger.cloud

Weekly Downloads

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

Documentation

API reference

License

MIT (license)

Dependencies

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

More

Packages that depend on mbautomation