flutter_acpuserprofile 1.0.0 copy "flutter_acpuserprofile: ^1.0.0" to clipboard
flutter_acpuserprofile: ^1.0.0 copied to clipboard

discontinuedreplaced by: flutter_aepuserprofile
outdated

Adobe Experience Platform User Profile support for Flutter apps.

example/lib/main.dart

import 'dart:developer';

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

import 'package:flutter/services.dart';
import 'package:flutter_acpuserprofile/flutter_acpuserprofile.dart';

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

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

class _MyAppState extends State<MyApp> {
  String _extensionVersion = 'Unknown';
  String _userAttr = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String extensionVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      extensionVersion = await FlutterACPUserProfile.extensionVersion;
    } on PlatformException {
      extensionVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _extensionVersion = extensionVersion;
    });
  }

  Future<void> getUserAttrs() async {
    String result = "";

    try {
      result = await FlutterACPUserProfile.getUserAttributes(["attrNameTest", "mapKey"]);
    } on PlatformException {
      log("Failed to get the user attributes");
    }

    if (!mounted) return;
    setState(() {
      _userAttr = result;
    });
  }

  // UTIL
  RichText getRichText(String label, String value) {
    return new RichText(
      text: new TextSpan(
        // Note: Styles for TextSpans must be explicitly defined.
        // Child text spans will inherit styles from parent
        style: new TextStyle(
          fontSize: 14.0,
          color: Colors.black,
        ),
        children: <TextSpan>[
          new TextSpan(
              text: label, style: new TextStyle(fontWeight: FontWeight.bold)),
          new TextSpan(text: value),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: ListView(shrinkWrap: true, children: <Widget>[
            getRichText('ACPUserProfile extension version: ',
                '$_extensionVersion\n'),
            getRichText('User attributes = ', '$_userAttr\n'),
            RaisedButton(
              child: Text("FlutterACPUserrofile.getUserAttributes"),
              onPressed: () => getUserAttrs()
            ),
            RaisedButton(
              child: Text("FlutterACPUserrofile.removeUserAttribute"),
              onPressed: () =>
                  FlutterACPUserProfile.removeUserAttribute("attrNameTest"),
            ),
            RaisedButton(
              child: Text("FlutterACPUserrofile.removeUserAttributes"),
              onPressed: () =>
                  FlutterACPUserProfile.removeUserAttributes(["attrNameTest", "mapKey"]),
            ),
            RaisedButton(
              child: Text("FlutterACPUserrofile.updateUserAttribute"),
              onPressed: () =>
                  FlutterACPUserProfile.updateUserAttribute("attrNameTest", "attrValueTest"),
            ),
            RaisedButton(
              child: Text("FlutterACPUserrofile.updateUserAttributes"),
              onPressed: () =>
                  FlutterACPUserProfile.updateUserAttributes({"mapKey": "mapValue", "mapKey1": "mapValue1"}),
            ),
          ]),
        )
      ),
    );
  }
}
0
likes
0
pub points
82%
popularity

Publisher

verified publisheradobe.com

Adobe Experience Platform User Profile support for Flutter apps.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, flutter_acpcore

More

Packages that depend on flutter_acpuserprofile