contlo_plugin 1.0.0-beta
contlo_plugin: ^1.0.0-beta copied to clipboard
The Contlo Flutter SDK for mobile Customer Engagement with Autonomous AI Marketing
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:contlo_plugin/contlo_plugin.dart';
import 'package:permission_handler/permission_handler.dart';
import 'user_screen.dart';
import 'dummy_event_screen.dart';
import 'event_screen.dart';
final API_KEY = "e33f4af9ea34b73f18c0fe46d02ed1a2";
void main() {
runApp(const MyApp());
requestNotificationPermission();
}
Future<void> requestNotificationPermission() async {
// Request the camera permission
final status = await Permission.notification.request();
if (status.isGranted) {
} else if (status.isDenied) {
} else if (status.isPermanentlyDenied) {
openAppSettings();
}
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage()
);
}
}
class HomePage extends StatelessWidget {
String _platformVersion = 'Unknown';
final _contloPlugin = ContloPlugin();
HomePage() {
init();
}
void init() async {
String? dd = await ContloPlugin.init(API_KEY) as String?;
print("initialized contlo: $dd");
// Add your code here for the third button
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion =
await ContloPlugin.getPlatformVersion() ?? 'Unknown platform version';
} on PlatformException {
platformVersion = '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.
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Contlo Plugin'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center, // Align buttons vertically in the center
children: <Widget>[
ElevatedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => UserScreen()));
},
child: Text('Send User Detail'),
),
// ElevatedButton(
// onPressed: () {
// Navigator.push(context, MaterialPageRoute(builder: (context) => EventScreen()));
// },
// child: Text('Send Event'),
// ),
ElevatedButton(
onPressed: () async {
String? dd = await ContloPlugin.sendAdvertisingId(true);
print("Advertising ID: $dd");
// Add your code here for the third button
},
child: Text('Send Advertising ID'),
),
ElevatedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => DummyEventScreen()));
},
child: Text('Dummy Events'),
),
],
),
),
),
);
}
}