c4w_wifi_sdk_flutter 1.1.0 c4w_wifi_sdk_flutter: ^1.1.0 copied to clipboard
Cloud4Wi WiFi SDK empowers mobile apps with instant, automatic, and fully encrypted WiFi connection upon arrival to enabled locations, allowing app users to get a stable and fast connection for a smoo [...]
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:c4w_wifi_sdk_flutter/c4w_wifi_sdk_flutter.dart';
import 'package:c4w_wifi_sdk_flutter/models/models.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
String _statusRegistration = 'Unregistered';
final _c4wWifiSdkFlutterPlugin = C4wWifiSdkFlutter();
@override
void initState() {
super.initState();
initPlatformState();
}
// 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 _c4wWifiSdkFlutterPlugin.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.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
void startRegistration() async {
try {
List<String> policiesResponse = await _c4wWifiSdkFlutterPlugin.getListOfPolicies();
Map<String, String> policiesMap = {
for (var policy in policiesResponse) policy: 'true'
};
setState(() {
_statusRegistration ='get Policies completed';
});
Customer customer = Customer(
username: 'johndoeddx',
password: 'xsecurepassword123',
firstName: 'John',
lastName: 'Doe',
phoneNumber: '+393391234567',
email: 'joxxhcccccn.doe@example.com',
gender: 'Male',
birthDate: '1990-01-01',
language: 'en',
country: 'US',
zipCode: '12345',
companyName: 'Example Company',
civilStatus: 'Mr',
phoneVerified: true,
emailVerified: true,
ppd: false,
profiling: true,
custom: {},
policies: policiesMap,
document: CustomerDocument(
memberId: 'memberId',
number: 'number',
passportNumber: 'passportNumber',
personalId: 'personalId',
type: 'type',
),
lock: false,
extId: 'external_id_001',
extProp1: 'extProp1_value',
extProp2: 'extProp2_value',
);
String deduplicateAttribute = 'email';
try {
CustomerCreateResponse response =
await _c4wWifiSdkFlutterPlugin.createCustomer(
customer,
deduplicateAttribute,
);
setState(() {
_statusRegistration ="Customer created successfully: ${response.id}";
});
try {
await _c4wWifiSdkFlutterPlugin.createWPA2EnterpriseProfile(customer.username, customer.password);
} catch (error) {
setState(() {
_statusRegistration ="Error creating WPA: $error";
});
}
setState(() {
_statusRegistration ='WPA Created';
});
} catch (error) {
setState(() {
_statusRegistration ="Error creating customer: $error";
});
}
} catch (error) {
setState(() {
_statusRegistration ="Error get policies: $error";
});
}
}
void _onButtonPressed() async {
startRegistration();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: [
Text('Running on: $_platformVersion\n'),
const SizedBox(height: 20),
ElevatedButton(
onPressed: _onButtonPressed,
child: const Text('Register'),
),
const SizedBox(height: 30),
Text(_statusRegistration, style: const TextStyle(fontSize: 18)),
],
),
),
),
);
}
}