braze_plugin 0.0.1 copy "braze_plugin: ^0.0.1" to clipboard
braze_plugin: ^0.0.1 copied to clipboard

outdated

Braze plugin for Flutter.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:braze_plugin/braze_plugin.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: BrazeFunctions(),
    );
  }
}

class BrazeFunctions extends StatefulWidget {
  @override
  BrazeFunctionsState createState() => new BrazeFunctionsState();
}

class BrazeFunctionsState extends State<BrazeFunctions> {
  String _userId = "";
  BrazePlugin _braze = new BrazePlugin();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Braze Sample'),
      ),
      body: _buildListView(),
    );
  }

  Widget _buildListView() {
    return Builder(
      builder: (BuildContext context) {
        return ListView(
          shrinkWrap: true,
          padding: const EdgeInsets.all(20.0),
          children: <Widget>[
            Center(
              child: Text("User Id: $_userId"),
            ),
            FlatButton(
              child: const Text('CHANGE USER'),
              onPressed: () {
                String userId = "flutterUser";
                _braze.changeUser(userId);
                Scaffold.of(context).showSnackBar(new SnackBar(
                  content: new Text("Changed User to: " + userId),
                ));
                this.setState(() {
                  _userId = userId;
                });
              },
            ),
            FlatButton(
              child: const Text(
                  'LOG EVENTS AND PURCHASES'),
              onPressed: () {
                var props = {"k1": "v1", "k2" : 2, "k3" : 3.5, "k4" :
                false};
                _braze.logCustomEvent("eventName");
                _braze.logCustomEventWithProperties("eventNameProps",
                    props);
                _braze.logPurchase("productId", "USD", 3.50, 2);
                _braze.logPurchaseWithProperties("productIdProps", "USD", 2.50,
                    4, props);
                Scaffold.of(context).showSnackBar(new SnackBar(
                  content: new Text("Logged events and purchases"),
                ));
              },
            ),
            FlatButton(
              child: const Text(
                  'SET ATTRIBUTES'),
              onPressed: () {
                _braze.addToCustomAttributeArray("arrayAttribute", "a");
                _braze.addToCustomAttributeArray("arrayAttribute", "c");
                _braze.setStringCustomUserAttribute("stringAttribute",
                    "stringValue");
                _braze.setStringCustomUserAttribute("stringAttribute2",
                    "stringValue");
                _braze.setDoubleCustomUserAttribute("doubleAttribute", 1.5);
                _braze.setIntCustomUserAttribute("intAttribute", 1);
                _braze.setBoolCustomUserAttribute("boolAttribute", false);
                _braze.setDateCustomUserAttribute("dateAttribute",
                    new DateTime.now());
                _braze.setLocationCustomAttribute("work", 40.7128, 74.0060);
                _braze.setPushNotificationSubscriptionType(
                    SubscriptionType.opted_in);
                _braze.setEmailNotificationSubscriptionType(
                    SubscriptionType.opted_in);
                _braze.setAttributionData("network1", "campaign1", "adgroup1",
                    "creative1");
                _braze.setFirstName("firstName");
                _braze.setLastName("lastName");
                _braze.setDateOfBirth(1990, 4, 13);
                _braze.setEmail("email@email.com");
                _braze.setGender("f");
                _braze.setLanguage("es");
                _braze.setCountry("JP");
                _braze.setHomeCity("homeCity");
                _braze.setPhoneNumber("123456789");
                _braze.setAvatarImageUrl("https://raw.githubusercontent.com/"
                    "Appboy/appboy-react-sdk/master/braze-logo.png");
                Scaffold.of(context).showSnackBar(new SnackBar(
                  content: new Text("Logged attributes"),
                ));
              },
            ),
            FlatButton(
              child: const Text(
                  'UNSET/INC ATTRIBUTES'),
              onPressed: () {
                _braze.removeFromCustomAttributeArray("arrayAttribute", "a");
                _braze.unsetCustomUserAttribute("stringAttribute2");
                _braze.incrementCustomUserAttribute("intAttribute", 2);
                Scaffold.of(context).showSnackBar(new SnackBar(
                  content: new Text("Unset/increment attributes"),
                ));
              },
            ),
            FlatButton(
              child: const Text(
                  'REQUEST DATA FLUSH'),
              onPressed: () {
                _braze.requestImmediateDataFlush();
                Scaffold.of(context).showSnackBar(new SnackBar(
                  content: new Text("Requested Data Flush"),
                ));
              },
            ),
            FlatButton(
              child: const Text(
                  'WIPE DATA'),
              onPressed: () {
                _braze.wipeData();
              },
            ),
            FlatButton(
              child: const Text(
                  'ENABLE SDK'),
              onPressed: () {
                _braze.enableSDK();
              },
            ),
            FlatButton(
              child: const Text(
                  'DISABLE SDK'),
              onPressed: () {
                _braze.disableSDK();
              },
            ),
          ],
        );
      },
    );
  }
}
30
likes
0
pub points
94%
popularity

Publisher

verified publisherbraze.com

Braze plugin for Flutter.

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on braze_plugin