cuidai_plugin 1.1.9 copy "cuidai_plugin: ^1.1.9" to clipboard
cuidai_plugin: ^1.1.9 copied to clipboard

unlistedoutdated

A Cuidai flutter plugin.

example/lib/main.dart

import 'dart:convert';
import 'dart:developer';

import 'package:cuidai_plugin/cuidai_plugin.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();

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

    // Init the Cuidai SDK
    CuidaiPlugin.initSDK(appName: "vitat");
    CuidaiPlugin.setUserProperties(
        {"ExternalId": "sudhshud", "Test": "sudhshud"});
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: 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) {
                            return 'Please enter the route';
                          }
                          return null;
                        },
                      ),
                      Padding(
                        padding: const EdgeInsets.symmetric(vertical: 16.0),
                        child: ElevatedButton(
                          onPressed: () {
                            if (_formKey.currentState.validate()) {
                              //Open Cuidai screen
                              var param = {
                                "popupJson":
                                    '[{"id": 1, "type": "streak_1", "headerTitle": "Que ótimo te ver por aqui!", "headerText": "O primeiro passo foi dado, parabéns!", "title": "Parabéns", "imageUrl": "https://cuidai.blob.core.windows.net/static/contents/popups/1621017839177.png", "steps": ["1", "2", "3", "4", "5", "6", "7"], "completedIndex": 2, "buttons": [{"type": "primary", "title": "Pode deixar", "route": ""}], "text": "Cada dia você chega mais perto dos seus objetivos!"}]',
                                "VitatToken":
                                    "eyJhbGciOiJSUzI1NiIsImtpZCI6ImRjNGQwMGJjM2NiZWE4YjU0NTMzMWQxZjFjOTZmZDRlNjdjNTFlODkiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vZGV2LWhlYWx0aC1wbGF0Zm9ybSIsImF1ZCI6ImRldi1oZWFsdGgtcGxhdGZvcm0iLCJhdXRoX3RpbWUiOjE2MjM5Mzg0MDUsInVzZXJfaWQiOiJlNzc2ZjYxMC05YmZmLTRlODYtYmE1ZS05NGYxZDU1OGNkZjYiLCJzdWIiOiJlNzc2ZjYxMC05YmZmLTRlODYtYmE1ZS05NGYxZDU1OGNkZjYiLCJpYXQiOjE2MjM5Mzg0MDUsImV4cCI6MTYyMzk0MjAwNSwicGhvbmVfbnVtYmVyIjoiKzU1MTE5OTk5OTk5MTIiLCJmaXJlYmFzZSI6eyJpZGVudGl0aWVzIjp7InBob25lIjpbIis1NTExOTk5OTk5OTEyIl19LCJzaWduX2luX3Byb3ZpZGVyIjoiY3VzdG9tIn19.jGIKHBqqYU_eIJhH2CRId2pJLpsZY7jmfrpfDSGddLv3NbEfKQEiGYltZPgAR3N6NiHRqvPZqTvXGt4fIhsyMId5bYG2dmWO-BISoCJ5kefpvnTT1Wii7hREG_8iaZtlJOZgkbbbXW0Xag08xV0844JzY2a7ggasn0tXTWBZSakbtUKpQFFlnV6U-inNCcwdFnWahY-wOJCsHqZIioscJuRosU22ZRIWTwKQHChfMob4O-B-3lrCXVn_DhSel9UuG_lvXXdO18ue9Ke8n9AnQR26NZAJhyN-9KJsknhNpVPXWFBdO8jXLk1ehBxUoYbl37ueOTsJBwuj3uJ5qMBgQg",
                                "DeviceId": "123"
                              };
                              // CuidaiPlugin.route(
                              //     deepLink: "popups", params: param);
                              CuidaiPlugin.route(
                                  // deepLink: _routeController.text,
                                  deepLink: "chatbot?chatbotId=152",
                                  params: param);
                            }
                          },
                          child: Text('Route'),
                        ),
                      ),
                      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'),
                        ),
                      ),
                    ],
                  ),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }

  void startCommunication() {
    CuidaiPlugin.setUserProperty("ExternalId", value: "123455dsgseg");
    CuidaiPlugin.startCommunication(CuidaiCommunication(onRoute: (route) {
      if (route.startsWith("updateuser")) {
        var json = route.replaceFirst("updateuser/", "");
        var user = jsonDecode(json);
        log("Rota => $route");
        log("Usuário => $user");
      } else {
        log("Rota => $route");
      }
    }));
    log("Comunicação Aberta!");
  }

  void stopCommunication() {
    CuidaiPlugin.stopCommunication();
    log("Comunicação FECHADA!");
  }
}
3
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A Cuidai flutter plugin.

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on cuidai_plugin