aware 0.1.9
aware: ^0.1.9 copied to clipboard

Hyper personalization engine SDK for Flutter

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:aware/aware.dart';

void main() => runApp(ExampleApp());

class ExampleApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyApp(),
    );
  }
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String registeredToken = '';
  String unregisterSucceed = '';
  String isRegistered = '';
  String isServiceEnabled = '';
  bool serviceEnable = false;
  String profile = '';
  String clientSecret = '';

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

  Widget _buildTestZone({String title = '', Widget button}) {
    return Column(
      children: <Widget>[
        Text(title),
        button,
      ],
    );
  }

  Widget _buildTextButton({String title, VoidCallback onPressed}) {
    return MaterialButton(
      color: Colors.blue,
      child: Text(
        title,
        style: const TextStyle(color: Colors.white),
      ),
      onPressed: onPressed,
    );
  }

  void _reset() {
    setState(() {
      registeredToken = '';
      unregisterSucceed = '';
      isRegistered = '';
      isServiceEnabled = '';
      serviceEnable = false;
      profile = '';
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Plugin example app'),
        actions: <Widget>[
          FlatButton(
            child: const Text(
              'Reset',
              style: TextStyle(color: Colors.white),
            ),
            onPressed: () {
              _reset();
            },
          ),
        ],
      ),
      body: ListView(
        children: <Widget>[
          _buildTestZone(
            title: registeredToken,
            button: _buildTextButton(
              title: 'Register',
              onPressed: () async {
                final token = await Aware.register();

                setState(() {
                  registeredToken = token;
                });
              },
            ),
          ),
          const Divider(color: Colors.black),
          _buildTestZone(
            title: 'Unregister succeed?: $unregisterSucceed',
            button: _buildTextButton(
              title: 'Unregister',
              onPressed: () async {
                try {
                  final unregistered = await Aware.unregister();
                  setState(() {
                    unregisterSucceed = unregistered.toString();
                  });
                } catch (e) {
                  setState(() {
                    unregisterSucceed = e.toString();
                  });
                }
              },
            ),
          ),
          const Divider(color: Colors.black),
          _buildTestZone(
            title: 'isRegistered?: $isRegistered',
            button: _buildTextButton(
              title: 'isRegistered',
              onPressed: () async {
                try {
                  final isRegistered = await Aware.isRegistered();
                  setState(() {
                    this.isRegistered = isRegistered.toString();
                  });
                } catch (e) {
                  setState(() {
                    isRegistered = e.toString();
                  });
                }
              },
            ),
          ),
          const Divider(color: Colors.black),
          _buildTestZone(
            button: _buildTextButton(
              title: 'Collect',
              onPressed: () async {
                await Aware.collect([CollectorType.location, CollectorType.wifi, CollectorType.bluetooth]);
              },
            ),
          ),
          const Divider(color: Colors.black),
          _buildTestZone(
            title: 'isServiceEnabled?: $isServiceEnabled',
            button: _buildTextButton(
              title: 'isServiceEnabled',
              onPressed: () async {
                try {
                  final isServiceEnabled = await Aware.isServiceEnabled();
                  setState(() {
                    this.isServiceEnabled = isServiceEnabled.toString();
                  });
                } catch (e) {
                  setState(() {
                    isServiceEnabled = e.toString();
                  });
                }
              },
            ),
          ),
          const Divider(color: Colors.black),
          _buildTestZone(
            title: 'setServiceEnabled',
            button: Switch(
              value: serviceEnable,
              onChanged: (bool value) async {
                await Aware.setServiceEnabled(value);
                setState(() {
                  serviceEnable = value;
                });
              },
            ),
          ),
          const Divider(color: Colors.black),
          _buildTestZone(
            title: 'profile?: $profile',
            button: _buildTextButton(
              title: 'Get profile',
              onPressed: () async {
                try {
                  final profile = await Aware.getProfile();
                  setState(() {
                    this.profile = profile;
                  });
                } catch (e) {
                  setState(() {
                    profile = e.toString();
                  });
                }
              },
            ),
          ),
          const Divider(color: Colors.black),
          _buildTestZone(
            title: 'clientSecret?: $clientSecret',
            button: _buildTextButton(
              title: 'Get clientSecret',
              onPressed: () async {
                try {
                  final clientSecret = await Aware.getClientSecret();
                  setState(() {
                    this.clientSecret = clientSecret;
                  });
                } catch (e) {
                  setState(() {
                    clientSecret = e.toString();
                  });
                }
              },
            ),
          ),
          const Divider(color: Colors.black),
        ],
      ),
    );
  }
}
0
likes
65
pub points
0%
popularity

Publisher

Unknown

Hyper personalization engine SDK for Flutter

Homepage

Documentation

API reference

License

BSD (LICENSE)

Dependencies

flutter

More

Packages that depend on aware