acl_scoring 0.0.1 copy "acl_scoring: ^0.0.1" to clipboard
acl_scoring: ^0.0.1 copied to clipboard

A Flutter plugin which provide ACL functioning by Unified Intelligence. Which help you collect device's data and calculate indicators.

example/lib/main.dart

import 'dart:async';
import 'dart:developer';
import 'dart:io';

import 'package:acl_scoring/acl_scoring.dart';
import 'package:acl_scoring/schemas/acl_scoring_config.dart';
import 'package:acl_scoring/utils/firebase_messaging_utils.dart';
import 'package:acl_scoring/utils/permission_utils.dart';
import 'package:acl_scoring_example/firebase_options.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

@pragma('vm:entry-point')
Future<void> aclFCMOnReceiveHandler(RemoteMessage message) async {
  log("aclFCMOnReceiveHandler ${message.toString()}");

  FirebaseMessagingUtils.handleFCMMessage(message.data);
}

class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
  String _platformVersion = 'Unknown';
  String _deviceId = 'Unknown';
  bool _isAllowAppUsage = false;
  bool _isAllowNotificationListener = false;

  final _aclScoringPlugin = AclScoring();

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    bool allowAppUsage = false;
    bool allowNotificationListener = false;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      // init firebase
      await Firebase.initializeApp(
        options: DefaultFirebaseOptions.currentPlatform,
      );
      await FirebaseMessaging.instance.requestPermission(provisional: true);
      // set the background messaging handler
      FirebaseMessaging.onBackgroundMessage(aclFCMOnReceiveHandler);
      FirebaseMessaging.onMessage.listen(aclFCMOnReceiveHandler);

      // final test = await FirebaseMessaging.instance.getToken();
      // log("ytest $test");
      // FirebaseMessaging.instance.onTokenRefresh.listen((fcmToken) {
      //   print("FCM token: $fcmToken");
      // });

      platformVersion =
          await _aclScoringPlugin.getPlatformVersion() ??
          'Unknown platform version';

      allowAppUsage = await PermissionUtils.isAppUsageAllowed();
      allowNotificationListener =
          await PermissionUtils.isBindNotificationListenerAllowed();

      // To init SDK plugin
      if (Platform.isIOS) {
        await _aclScoringPlugin.initialize(
          ACLScoringConfig(
            partnerId: '',
            apiEndpoint: '',
            apiKey: '',
            apiSecret: '',
          ),
        );
      } else {
        await _aclScoringPlugin.initialize(
          ACLScoringConfig(
            partnerId: '',
            apiEndpoint: '',
            apiKey: '',
            apiSecret: '',
          ),
        );
      }

      _deviceId = await _aclScoringPlugin.registerDevice() ?? 'unknow';
      await _aclScoringPlugin.startMonitoring();
    } 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;
      _isAllowAppUsage = allowAppUsage;
      _isAllowNotificationListener = allowNotificationListener;
    });
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) async {
    if (state == AppLifecycleState.resumed) {
      bool allowAppUsage = await PermissionUtils.isAppUsageAllowed();
      bool allowNotificationListener =
          await PermissionUtils.isBindNotificationListenerAllowed();

      setState(() {
        _isAllowAppUsage = allowAppUsage;
        _isAllowNotificationListener = allowNotificationListener;
      });
    }
    super.didChangeAppLifecycleState(state);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Plugin example app')),
        body: Center(
          child: Column(
            children: [
              Text(_deviceId),
              Text('Running on: $_platformVersion\n'),
              ElevatedButton(
                onPressed: _handleAllowAppUsageClick,
                child: Text(
                  _isAllowAppUsage == true
                      ? 'Allowed app usage access'
                      : 'Press to allow app usage access!',
                ),
              ),
              ElevatedButton(
                onPressed: _handleAllowNotificationListenerClick,
                child: Text(
                  _isAllowNotificationListener == true
                      ? 'Allowed notification listener access'
                      : 'Press to allow notification listener access!',
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  void _handleAllowAppUsageClick() async {
    final isAlreadyAllow = await PermissionUtils.isAppUsageAllowed();
    if (isAlreadyAllow == false) {
      await PermissionUtils.openAppUsageSetting();
    }
  }

  void _handleAllowNotificationListenerClick() async {
    final isAlreadyAllow =
        await PermissionUtils.isBindNotificationListenerAllowed();
    if (isAlreadyAllow == false) {
      await PermissionUtils.openBindNotificationSetting();
    }
  }
}
0
likes
150
points
127
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin which provide ACL functioning by Unified Intelligence. Which help you collect device's data and calculate indicators.

Homepage

Documentation

API reference

License

GPL-3.0 (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on acl_scoring

Packages that implement acl_scoring