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

outdated

Next14 Proximity SDK for Flutter.

example/lib/main.dart

import 'dart:io';
import 'package:device_info/device_info.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:async';
import 'package:flutter_jointag/flutter_jointag.dart';
import 'package:permission_handler/permission_handler.dart';

void main() {
  runApp(MaterialApp(home: MyApp()));
}

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

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
    try {
      await _requirePermission(deviceInfo);
      await FlutterJointag.checkPendingPermissions;
    } catch (err) {
      print('Caught error: $err');
    }

  }

  Future _requirePermission(DeviceInfoPlugin deviceInfo) async {

    var statusL = await Permission.location.status;
    if (statusL.isUndetermined || statusL.isDenied) {
      if (Platform.isIOS) {
        PermissionStatus permissionStatus = await Permission.location.request();
        //do something if the permission is granted/not granted
      } else if (Platform.isAndroid) {
        AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
        if (androidInfo.version.sdkInt <= 29) {
          //ask location always
          PermissionStatus permissionStatus = await Permission.location.request();
          //do something if the permission is granted/not granted
        } else {
          //from android 30 ask for normal location and open the settings page
          PermissionStatus permissionStatus = await Permission.location.request();
          //do something if the permission is granted/not granted
          openAppSettings();
        }
      }
    }

    var statusN = await Permission.notification.status;
    if (statusN.isUndetermined || statusN.isDenied) {
      PermissionStatus permissionStatus = await Permission.notification.request();
      //do something if the permission is granted/not granted
    }
    
    await FlutterJointag.requestTrackingAuthorization;

  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
            child: Padding(
          padding: const EdgeInsets.all(24),
          child: ListView(children: [
            RaisedButton(
                child: Text("checkPendingPermissions"),
                onPressed: _checkPendingPermissions),
            RaisedButton(child: Text("enabledCmp"), onPressed: _enableCmp),
            RaisedButton(child: Text("getContext"), onPressed: _getContext),
            RaisedButton(
                child: Text("getInstallationId"),
                onPressed: _getInstallationId),
            RaisedButton(
                child: Text("setInstallationId"),
                onPressed: _setInstallationId),
            RaisedButton(
                child: Text("setAdvertisingDisabled"),
                onPressed: _setAdvertisingDisabled),
            RaisedButton(
                child: Text("setAdvertisingEnabled"),
                onPressed: _setAdvertisingEnabled),
            RaisedButton(child: Text("getSessionId"), onPressed: _getSessionId),
            RaisedButton(
                child: Text("setSessionId"),
                onPressed: _setSessionId),
            RaisedButton(
                child: Text("getGDPRConsent"), onPressed: _getGDPRConsent),
            RaisedButton(
                child: Text("setGDPRConsent"),
                onPressed: _setGDPRConsent),
            RaisedButton(child: Text("setBaseJobId"), onPressed: _setBaseJobId),
            RaisedButton(
                child: Text("getAdvertisingIdentifier"),
                onPressed: _getAdvertisingIdentifier),
            RaisedButton(child: Text("getApiKey"), onPressed: _getApiKey),
            RaisedButton(child: Text("getSecret"), onPressed: _getSecret),
            RaisedButton(
                child: Text("isLimitAdTrackingEnabled"),
                onPressed: _isLimitAdTrackingEnabled),
          ]),
        )),
      ),
    );
  }

  void _isLimitAdTrackingEnabled() async {
    var result;
    try {
      result = await FlutterJointag.isLimitAdTrackingEnabled;
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("isLimitAdTrackingEnabled"),
            content: Text(result.toString()),
          );
        });
  }

  void _getSessionId() async {
    var result;
    try {
      result = await FlutterJointag.getSessionId;
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("getSessionId"),
            content: Text(result),
          );
        });
  }

  void _getSecret() async {
    var result;
    try {
      result = await FlutterJointag.getSecret;
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("getSecret"),
            content: Text(result),
          );
        });
  }

  void _getGDPRConsent() async {
    var result;
    try {
      result = await FlutterJointag.getGDPRConsent;
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("getGDPRConsent"),
            content: Text(result.toString()),
          );
        });
  }

  void _getContext() async {
    var result;
    try {
      result = await FlutterJointag.getContext;
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("getContext"),
            content: Text(result),
          );
        });
  }

  void _getApiKey() async {
    var result;
    try {
      result = await FlutterJointag.getApiKey;
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("getApiKey"),
            content: Text(result),
          );
        });
  }

  void _getAdvertisingIdentifier() async {
    var result;
    try {
      result = await FlutterJointag.getAdvertisingIdentifier;
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("getAdvertisingIdentifier"),
            content: Text(result),
          );
        });
  }

  void _setBaseJobId() async {
    var result;
    try {
      FlutterJointag.NEWJOB_ID = 123456;
      result = await FlutterJointag.setBaseJobId;
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("setBaseJobId"),
            content: Text(result.toString()),
          );
        });
  }

  void _setInstallationId() async {
    var result;
    try {
      FlutterJointag.INSTALLATION_ID = "123456";
      result = await FlutterJointag.setInstallationId;
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("setInstallationId"),
            content: Text(result.toString()),
          );
        });
  }

  void _setGDPRConsent() async {
    var result;
    try {
      FlutterJointag.VENDOR_ID = 123456;
      FlutterJointag.CONSENT = true;
      result = await FlutterJointag.setGDPRConsent;
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("setGDPRConsent"),
            content: Text(result.toString()),
          );
        });
  }

  void _setSessionId() async {
    var result;
    try {
      FlutterJointag.SESSION_ID = "123456";
      result = await FlutterJointag.setSessionId;
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("setSessionId"),
            content: Text(result.toString()),
          );
        });
  }

  void _setAdvertisingEnabled() async {
    var result;
    try {
      result = await FlutterJointag.setAdvertisingEnabled;
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("setAdvertisingEnabled"),
            content: Text(result.toString()),
          );
        });
  }

  void _setAdvertisingDisabled() async {
    var result;
    try {
      result = await FlutterJointag.setAdvertisingDisabled;
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("setAdvertisingDisabled"),
            content: Text(result.toString()),
          );
        });
  }

  void _getInstallationId() async {
    var result;
    try {
      result = await FlutterJointag.getInstallationId;
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("getInstallationId"),
            content: Text(result),
          );
        });
  }

  void _enableCmp() async {
    var result;
    try {
      result = await FlutterJointag.enabledCmp;
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("enabledCmp"),
            content: Text(result.toString()),
          );
        });
  }

  void _checkPendingPermissions() async {
    var result;
    try {
      result = await FlutterJointag.checkPendingPermissions;
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("checkPendingPermissions"),
            content: Text(result),
          );
        });
  }
  void _getCustomActionListeners() async {
    var result;
    try {
      result = await FlutterJointag.getCustomActionListeners;
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("getCustomActionListeners"),
            content: Text(result.toString()),
          );
        });
  }

  void _addCustomActionListeners() async {
    var result;
    try {
      result = await FlutterJointag.addCustomActionListeners;
    } on PlatformException catch (e) {
      result = e.message;
    }
  }
}