dependencies {
implementation 'com.cloud4wi:c4w-wifi-sdk:1.7.0' // Replace with actual version
}import Cloud4WiSDKWiFiimport Flutter
import UIKit
import Cloud4WiSDKWiFi
public class FlutterCloud4wiSdkPlugin: NSObject, FlutterPlugin {
public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "flutter_cloud4wi_sdk", binaryMessenger: registrar.messenger())
let instance = FlutterCloud4wiSdkPlugin()
registrar.addMethodCallDelegate(instance, channel: channel)
}
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
switch call.method {
case "createCustomer":
guard let args = call.arguments as? [String: Any],
let customer = args["customer"] as? [String: Any],
let deduplicateAttribute = args["deduplicateAttribute"] as? String else {
result(FlutterError(code: "INVALID_ARGUMENT", message: "Invalid arguments", details: nil))
return
}
createCustomer(customer: customer, deduplicateAttribute: deduplicateAttribute, result: result)
default:
result(FlutterMethodNotImplemented)
}
}
private func createCustomer(customer: [String: Any], deduplicateAttribute: String, result: @escaping FlutterResult) {
let customerSDK = Customer()
customerSDK?.firstName = customer["firstName"] as? String
customerSDK?.lastName = customer["lastName"] as? String
customerSDK?.email = customer["email"] as? String
customerSDK?.policies = customer["policies"] as? [String: Any] // Verifica il tipo corretto
Cloud4WiSDKWiFi.init().createCustomer(customerSDK, deduplicate: deduplicateAttribute) { (customerResponse) in
if let customerResponse = customerResponse {
let responseDictionary: [String: Any] = [
"status": customerResponse.status as Any,
"generated": customerResponse.generated as Any,
"id": customerResponse.id as Any,
"organizationId": customerResponse.organizationId as Any,
"locationId": customerResponse.locationId as Any,
"hotspotId": customerResponse.hotspotId as Any,
"username": customerResponse.username as Any,
"password": customerResponse.password as Any,
"mailSent": customerResponse.mailSent as Any
]
result(responseDictionary)
} else {
result(FlutterError(code: "INVALID_ARGUMENT", message: "No customer response found", details: nil))
}
} onError: { (error) in
if let error = error as NSError? {
result(FlutterError(code: String(error.code), message: error.localizedDescription, details: nil))
}
}
}
}
import com.cloud4wi.sdk.Cloud4WiSDKWiFi
COMING SOON!
import 'package:flutter_cloud4wi_sdk/flutter_cloud4wi_sdk.dart';
...
Customer customer = Customer(
username: 'johndoe',
password: 'securepassword123',
firstName: 'John',
lastName: 'Doe',
phoneNumber: '1234567890',
email: '[email protected]',
gender: 'Male',
birthDate: '1990-01-01',
language: 'en',
country: 'USA',
zipCode: '12345',
companyName: 'Example Company',
civilStatus: 'Single',
phoneVerified: true,
emailVerified: true,
ppd: false,
profiling: true,
custom: {},
policies: {},
document: CustomerDocument(
documentType: 'Passport',
documentNumber: '123456789',
),
lock: false,
extId: 'external_id_001',
extProp1: 'extProp1_value',
extProp2: 'extProp2_value',
);
String deduplicateAttribute = 'email';
try {
CustomerCreateResponse response =
await FlutterCloud4wiSdk.createCustomer(
customer,
'email',
);
print("Customer created successfully: ${response.id}");
} catch (error) {
print("Error creating customer: $error");
}
...flutter create --template=plugin --platforms=android,ios flutter_cloud4wi_sdkcd flutter_cloud4wi_sdkPod::Spec.new do |s|
...
s.dependency 'c4w-wifi-sdk', '~> 1.7.0' # Replace with actual version
endrepositories {
...
maven {
url = 'https://artifacts.cloud4wi.com/release'
}
}
// lib/flutter_cloud4wi_sdk.dart
import 'dart:async';
import 'package:flutter/services.dart';
class Customer {
String username;
String password;
String firstName;
String lastName;
String phoneNumber;
String email;
String gender;
String birthDate;
String language;
String country;
String zipCode;
String companyName;
String civilStatus;
bool phoneVerified;
bool emailVerified;
bool ppd;
bool profiling;
Map<String, String> custom;
Map<String, bool> policies;
CustomerDocument document;
bool lock;
String extId;
String extProp1;
String extProp2;
Customer({
required this.username,
required this.password,
required this.firstName,
required this.lastName,
required this.phoneNumber,
required this.email,
required this.gender,
required this.birthDate,
required this.language,
required this.country,
required this.zipCode,
required this.companyName,
required this.civilStatus,
required this.phoneVerified,
required this.emailVerified,
required this.ppd,
required this.profiling,
required this.custom,
required this.policies,
required this.document,
required this.lock,
required this.extId,
required this.extProp1,
required this.extProp2,
});
Map<String, dynamic> toMap() {
return {
'username': username,
'password': password,
'firstName': firstName,
'lastName': lastName,
'phoneNumber': phoneNumber,
'email': email,
'gender': gender,
'birthDate': birthDate,
'language': language,
'country': country,
'zipCode': zipCode,
'companyName': companyName,
'civilStatus': civilStatus,
'phoneVerified': phoneVerified,
'emailVerified': emailVerified,
'ppd': ppd,
'profiling': profiling,
'custom': custom,
'policies': policies,
'document': document.toMap(), // assuming CustomerDocument has toMap()
'lock': lock,
'extId': extId,
'extProp1': extProp1,
'extProp2': extProp2,
};
}
}
class CustomerDocument {
String documentType;
String documentNumber;
CustomerDocument({
required this.documentType,
required this.documentNumber,
});
Map<String, dynamic> toMap() {
return {
'documentType': documentType,
'documentNumber': documentNumber,
};
}
}
class CustomerCreateResponse {
String status;
String generated;
String id;
String organizationId;
String locationId;
String hotspotId;
String username;
String password;
int mailSent;
CustomerCreateResponse({
required this.status,
required this.generated,
required this.id,
required this.organizationId,
required this.locationId,
required this.hotspotId,
required this.username,
required this.password,
required this.mailSent,
});
}
class FlutterCloud4wiSdk {
static const MethodChannel _channel = MethodChannel('flutter_cloud4wi_sdk');
static Future<CustomerCreateResponse> createCustomer(
Customer customer,
String deduplicateAttribute,
) async {
try {
final response = await _channel.invokeMethod('createCustomer', {
'customer': customer.toMap(),
'deduplicateAttribute': deduplicateAttribute,
});
// Handle the response here if needed
return CustomerCreateResponse(
status: response['status'],
generated: response['generated'],
id: response['id'],
organizationId: response['organizationId'],
locationId: response['locationId'],
hotspotId: response['hotspotId'],
username: response['username'],
password: response['password'],
mailSent: response['mailSent'],
);
} catch (e) {
throw Exception('Failed to create customer: $e');
}
}
}dependencies:
flutter:
sdk: flutter
flutter_cloud4wi_sdk:
path: ../flutter_cloud4wi_sdk # Adjust the path accordinglyflutter pub get