mobile_foundrylogin

A new Flutter package project.

Getting Started

This project is a starting point for a Dart package, a library module containing code that can be shared easily across multiple Flutter or Dart projects.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

#Example For Login

PROJECT SETUP

1.) Add dependencies in ‘pubspec.yaml’ file.

dependencies: flutter: sdk: flutter shared_preferences: ^2.0.7 uuid: ^3.0.5 mobile_foundrylogin:

2.) Run ‘flutter pub get’ to install dependencies

3.) Run ‘flutter run –no-sound-null-safety’ to run your project

SIGN UP

Call function signUpFoundry() import from 'package:mobile_foundrylogin/signup.dart';

 Response response = await signUpFoundry(FoundrySignUpUrl, {
     'account': {
       "parent_id": "ded826f0-9305-11ec-b4c1-69010c9ff73e",
       "password_policy": '.',
     },
     "user": {
       "enable_attribute_edit": 1,
       "password_type": 1,
       "host": "2clane7ubc.execute-api.eu-central-1.amazonaws.com",
       "api_user_only": 0,
       "country": country.text,
       "email": email.text.trim(),
       "first_name": firstName.text,
       "last_name": lastName.text,
       "password": password.text.trim(),
       "postal_code": postalCode.text,
       "role": 'User',
       "username": email.text.trim(),
       "address1": addr1.text,
       "address2": addr2.text,
       "city": city.text,
       "state": state.text,
       "phone": phone.text,
       "mobile_phone": mobPhone.text
     },
   });

LOGIN

Call function LoginFoundry() import from 'package:mobile_foundrylogin/login.dart';


 var response = await loginFoundry(
<RootAccountID>,
      <CustomEndPointUrl>,
email.text,
password.text,
<NotificationToken>);

FORGOT PASSWORD

Call forgotPasswordSendEmail()

import from 'package:mobile_foundrylogin/user_management.dart';

 Response response = await forgotPasswordSendEmail(
       <FoundryEndPoint>,
       email.text,
       <RootAccountID>);

This will send an email to the registered account and user can reset password from there

SUPPORT CHAT

Create a mqtt device passing iot-endpoint and randomly generated clientId

import 'package:mobile_foundrylogin/support_chat.dart';

 AWSIotDevice device = AWSIotDevice(
   endpoint: 'a3bhfdb1q9qwke-ats.iot.eu-central-1.amazonaws.com',
   clientId: 'client-1234567890',
 );

To start a chat


 var response = await startSupportChat(
      "6c1837f0-9ad9-11ec-a537-5518f38a4e21",   //ChatTypeId
"payment query");					  //message Type

Steps to follow for implementing chat - Load Chat history Add listener for receiving messages Connect the mqtt device Subscribe the mqtt topic Publish message on mqtt topic

1.) Load chat history

 var messageHistory = await chatHistory();

This will return a list of messages that were previously done between user and support chat agent.

2.) Add listener


 Future<void> initAsyncState() async {
   await for (var msg in device.messages) {
       setState(() {
         messageThread.add(json.decode(msg.asStr));
       });
   }
 }

3.) Connect mqtt device


 await device.connect();

4.) Subscribe to topic


 device.subscribe(
       'com.thinglogix.chat/conversation/'
  + chatDeviceId.toString() + '/#');

5.) Publish a message


  topicControl.text = 'com.thinglogix.chat/conversation/' +
                       chatDeviceId.toString() + '/' + Uuid().v4();

 Response res = await device.publishMessage(
                       msgControl.text, 	//message to be published
 				"Open",          		//Chat Status Open|Close
                       topic: topicControl.text,  	   //mqtt topic
                       messageType: 'payment query',  //message type
                       device: device);               //mqtt device

End Support Chat


 ()async {
    topicControl.text =
    'com.thinglogix.chat/conversation/' +
    chatDeviceId.toString() +
    '/' +
    Uuid().v4();


   device.publishMessage(
    "This chat is Closed by User.", "Close",
    topic: topicControl.text,
    messageType: 'payment query',
    device: device);
  },

 Future<void> initAsyncState() async {
   await for (var msg in device.messages) {
//condition to be added in listener to end the chat
     if (json.decode(msg.asStr)['chat_state'] == 'Close') {
       String response =
           await endSupportChat("6c1837f0-9ad9-11ec-a537-5518f38a4e21");
     }
   }
 }

RESET PASSWORD


import 'package:mobile_foundrylogin/user_management.dart';

 Response response = await resetPassword(
       <RootAccountId>,
  password.text);  //new password

PROFILE

1.) Load User Profile


import 'package:mobile_foundrylogin/user_management.dart';

 Response response = await getUserProfile();

2.) Edit Profile


import 'package:mobile_foundrylogin/user_management.dart';

 Response response = await setUserProfile({
	//User fields to be updated
     "first_name": firstName.text,
     "last_name": lastName.text,
     "username": username.text,
     "phone": phone.text,
     "mobile_phone": mobPhone.text,
     "email": email.text,
     "address1": addr1.text,
     "address2": addr2.text,
     "city": city.text,
     "state": state.text,
     "country": country.text,
     "postal_code": postalCode.text,



     //Passed from the Loaded profile data
     "account_id": jsonData['account_id'],
     "id": jsonData['id'],
     "root_account_id": jsonData['root_account_id'],
   });

RATING

Call ratingPublish()


 import 'package:mobile_foundrylogin/rating.dart';

 ()async{
         ratingPublish(ratingController.text,  //rating
                       commentController.text, //comment
 				context);			 //flutter context
         },

Libraries

mobile_foundrylogin
privateApi
rating
signup
support_chat
user_management