c4w_wifi_sdk_flutter 1.0.0 copy "c4w_wifi_sdk_flutter: ^1.0.0" to clipboard
c4w_wifi_sdk_flutter: ^1.0.0 copied to clipboard

Cloud4Wi WiFi SDK for Flutter

example/lib/main.dart

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 {
      await _c4wWifiSdkFlutterPlugin.setAPIAuthParams("ck-7b869f67-44be-4394-9439-42991de09b48", "YMDCQKTWDZDYLACLSLKNTAQFJNVHFBBS");
      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: '[email protected]',
          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";
        });
      }
    } catch (error) {
      setState(()  {
        _statusRegistration ="Error set Auth: $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)),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
140
points
16
downloads

Publisher

unverified uploader

Weekly Downloads

Cloud4Wi WiFi SDK for Flutter

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on c4w_wifi_sdk_flutter

Packages that implement c4w_wifi_sdk_flutter