sfmc_plugin 1.0.3 sfmc_plugin: ^1.0.3 copied to clipboard
Salesforce Marketing Cloud (SFMC) - MobilePush SDK for Flutter. Implement the MobilePush SDK for your iOS and Android applications in Flutter.
import 'package:flutter/material.dart';
import 'package:sfmc_plugin/sfmc_plugin.dart';
import 'package:sfmc_prototype/screens/components/contact_key_component.dart';
import 'package:sfmc_prototype/screens/components/display_links_component.dart';
void main() async {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
final String title = "SFMC - Mobile Push";
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool? initStatus;
late TextEditingController tagController = TextEditingController();
void onInit() async {
var isInitialized = await SfmcPlugin().initialize(
appId: '<YOUR_APP_ID>',
accessToken: '<YOUR_ACCESS_TOKEN>',
mid: '<YOUR_MID>',
sfmcURL: '<YOUR_SFMC_URL>',
senderId: '<YOUR_FIREBASE_CLOUD_MESSAGING_SENDER_ID>',
locationEnabled: false,
inboxEnabled: false,
analyticsEnabled: true,
delayRegistration: true);
setState(() {
initStatus = isInitialized;
});
}
@override
void initState() {
onInit();
super.initState();
}
@override
Widget build(BuildContext context) {
bool initSucceeded = (initStatus != null && initStatus == true);
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: ListView(
children: [
const SizedBox(
height: 30,
),
initStatusDisplay(initStatus),
const SizedBox(
height: 15,
),
DisplayLinksComponent(),
if (initSucceeded) const ContactKeyComponent(),
],
),
);
}
Widget initStatusDisplay(bool? isInitSuccessful) {
String text = 'Trying to initialize ...';
bool isLoading = isInitSuccessful == null;
if (!isLoading) {
if (isInitSuccessful) {
text = "The cloud messaging system has been initialized !";
} else {
text = "There was an error during initializing the cloud system !";
}
}
return SizedBox(
child: Column(
children: [
if (isLoading)
const SizedBox(
height: 20, width: 20, child: CircularProgressIndicator()),
Text(
text,
textAlign: TextAlign.center,
),
],
),
);
}
Widget buildSectionContainer({required Widget child}) {
return Container(
margin: const EdgeInsets.symmetric(horizontal: 15, vertical: 5),
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(width: 0.5)),
child: child,
);
}
}