cuidai_plugin 2.6.0 cuidai_plugin: ^2.6.0 copied to clipboard
A Cuidai flutter plugin.
import 'dart:developer';
import 'package:cuidai_plugin/cuidai_plugin.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _formKey = GlobalKey<FormState>();
final _routeController = TextEditingController();
var _textReturn = "nada";
@override
void initState() {
super.initState();
// Init the Cuidai SDK
CuidaiPlugin.initSDK(appName: "vitat");
// CuidaiPlugin.setUserProperties(
// {"ExternalId": "sudhfssfsfsfsfshud", "Test": "sudhshud"});
CuidaiPlugin.setUserProperty("ExternalId",
value: "bd3e905b-80e6-4521-a2c1-f62e2091cf99");
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Builder(
builder: (context) => Scaffold(
appBar: AppBar(
title: const Text('Cuidai Plugin example app'),
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 32.0),
child: Center(
child: Column(
children: [
Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TextFormField(
controller: _routeController,
decoration: const InputDecoration(
hintText: 'Enter the route',
),
validator: (value) {
if (value?.isEmpty ?? true) {
return 'Please enter the route';
}
return null;
},
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: ElevatedButton(
onPressed: () {
if (_formKey.currentState?.validate() ?? false) {
//Open Cuidai screen
var param = {
"VitatToken":
"eyJhbGciOiJSUzI1NiIsImtpZCI6Ijg4ZGYxMzgwM2I3NDM2NjExYWQ0ODE0NmE4ZGExYjA3MTg2ZmQxZTkiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vZGV2LWhlYWx0aC1wbGF0Zm9ybSIsImF1ZCI6ImRldi1oZWFsdGgtcGxhdGZvcm0iLCJhdXRoX3RpbWUiOjE2MjQwNDg0NjIsInVzZXJfaWQiOiJiZDNlOTA1Yi04MGU2LTQ1MjEtYTJjMS1mNjJlMjA5MWNmOTkiLCJzdWIiOiJiZDNlOTA1Yi04MGU2LTQ1MjEtYTJjMS1mNjJlMjA5MWNmOTkiLCJpYXQiOjE2MjQwNDg0NjIsImV4cCI6MTYyNDA1MjA2MiwicGhvbmVfbnVtYmVyIjoiKzU1MTE5OTk5OTkxMjkiLCJmaXJlYmFzZSI6eyJpZGVudGl0aWVzIjp7InBob25lIjpbIis1NTExOTk5OTk5MTI5Il19LCJzaWduX2luX3Byb3ZpZGVyIjoiY3VzdG9tIn19.eSGyO_r4MhG1LkoHkTXxzhPlaCMyiapa8w_hfR3yCjqRkK_9sqfpzjfAUKgLvnvvgot1v2Eoiq1-1OI6sgmiQbjUsE7ZjR0FO1hbsTSBiNEiftTwGYWaO0qiRWncCe2St3hU9DPpoBZd6EuL0X4Q0fR4cCXNwRtHMp2JBUKyAQxM-tbj_IcSDGmaHXC7ICyRyaKz1HOF3oGWuk6diukpD8zA3OK6UDOW6lGY47Uf8za1WM2MrmCurd09evi83j_5QYW4zJX__n9MygkERmDYCc62NAK9Bw5WXXk-NF4ePRek9wLO-c6uc2wFb0xO60URzK6Myp35y0LydQNqSfea-g",
"DeviceId": "1234",
"name": "Booker",
// "isFromFlutterDiary":"true"
};
log("route!");
CuidaiPlugin.route(
deepLink: _routeController.text,
context: context,
params: param,
communication: CuidaiEventCommunication(onRoute: (response) {
log("Response: ${response}");
setState(() {
_textReturn = "\nrota: [${response}]";
});
}, onEvent: (_, __){}));
}
},
child: Text('Route'),
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: ElevatedButton(
onPressed: () {
CuidaiPlugin.route(deepLink: "programs.discover");
},
child: Text('Programs discover'),
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: ElevatedButton(
onPressed: () {
startCommunication();
},
child: Text('Start Communicarion'),
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: ElevatedButton(
onPressed: () {
stopCommunication();
},
child: Text('Stop Communication'),
),
),
Text("Retorno do SDK"),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: Column(
children: [Text("$_textReturn")],
),
),
],
),
)
],
),
),
),
),
),
);
}
String getTimeNow() {
var now = DateTime.now();
return "${now.hour}:${now.minute}:${now.second}.${now.millisecond}";
}
void startCommunication() {
CuidaiPlugin.setUserProperty("ExternalId", value: "123455dsgseg");
setState(() {
_textReturn += "\n[${getTimeNow()}] aguardando...";
});
CuidaiPlugin.startEventCommunication(CuidaiEventCommunication(
onRoute: (route) {
setState(() {
_textReturn += "\n[${getTimeNow()}] Rota => $route";
});
},
onEvent: (event, params) {}));
log("Comunicação Aberta!");
}
void stopCommunication() {
setState(() {
_textReturn = "\n[${getTimeNow()}] comunicaçao encerrada!";
});
CuidaiPlugin.stopEventCommunication();
log("Comunicação FECHADA!");
}
}