jtproximity_flutter 1.0.2+3 copy "jtproximity_flutter: ^1.0.2+3" to clipboard
jtproximity_flutter: ^1.0.2+3 copied to clipboard

Next14 Kariboo Proximity SDK for Flutter

example/lib/main.dart

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

import 'package:device_info/device_info.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:jtproximity_flutter/jtproximity_flutter.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 FlutterProximityPlugin.checkPendingPermissions;
    } catch (err) {
      print('Caught error: $err');
    }
  }

  Future _requirePermission(DeviceInfoPlugin deviceInfo) async {
    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
    }

    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();
        }
      }
    }
  }

  @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: [
            ElevatedButton(
                child: Text("_requestTrackingAuthorization",
                    style: TextStyle(fontSize: 12)),
                onPressed: _requestTrackingAuthorization),
            ElevatedButton(
                child: Text("_addCustomActionListeners",
                    style: TextStyle(fontSize: 12)),
                onPressed: _addCustomActionListeners),
            ElevatedButton(
                child: Text("_removeCustomActionListeners",
                    style: TextStyle(fontSize: 12)),
                onPressed: _removeCustomActionListeners),
            ElevatedButton(
                child: Text("checkPendingPermissions",
                    style: TextStyle(fontSize: 12)),
                onPressed: _checkPendingPermissions),
            ElevatedButton(
                child: Text("enabledCmp", style: TextStyle(fontSize: 12)),
                onPressed: _enableCmp),
            ElevatedButton(
                child: Text("getContext", style: TextStyle(fontSize: 12)),
                onPressed: _getContext),
            ElevatedButton(
                child:
                    Text("getInstallationId", style: TextStyle(fontSize: 12)),
                onPressed: _getInstallationId),
            ElevatedButton(
                child:
                    Text("setInstallationId", style: TextStyle(fontSize: 12)),
                onPressed: _setInstallationId),
            ElevatedButton(
                child: Text("setAdvertisingDisabled",
                    style: TextStyle(fontSize: 12)),
                onPressed: _setAdvertisingDisabled),
            ElevatedButton(
                child: Text("setAdvertisingEnabled",
                    style: TextStyle(fontSize: 12)),
                onPressed: _setAdvertisingEnabled),
            ElevatedButton(
                child: Text("getSessionId", style: TextStyle(fontSize: 12)),
                onPressed: _getSessionId),
            ElevatedButton(
                child: Text("setSessionId", style: TextStyle(fontSize: 12)),
                onPressed: _setSessionId),
            ElevatedButton(
                child: Text("setBaseJobId", style: TextStyle(fontSize: 12)),
                onPressed: _setBaseJobId),
            ElevatedButton(
                child: Text("getAdvertisingIdentifier",
                    style: TextStyle(fontSize: 12)),
                onPressed: _getAdvertisingIdentifier),
            ElevatedButton(
                child: Text("getApiKey", style: TextStyle(fontSize: 12)),
                onPressed: _getApiKey),
            ElevatedButton(
                child: Text("getSecret", style: TextStyle(fontSize: 12)),
                onPressed: _getSecret),
            ElevatedButton(
                child: Text("isLimitAdTrackingEnabled",
                    style: TextStyle(fontSize: 12)),
                onPressed: _isLimitAdTrackingEnabled),
            ElevatedButton(
                child:
                    Text("getProfilingConsent", style: TextStyle(fontSize: 12)),
                onPressed: _getProfilingConsent),
            ElevatedButton(
                child: Text("getMonitoringConsent",
                    style: TextStyle(fontSize: 12)),
                onPressed: _getMonitoringConsent),
            ElevatedButton(
                child: Text("getAdvertisingConsent",
                    style: TextStyle(fontSize: 12)),
                onPressed: _getAdvertisingConsent),
            ElevatedButton(
                child:
                    Text("getAdvancedConsent", style: TextStyle(fontSize: 12)),
                onPressed: _getAdvancedConsent),
            ElevatedButton(
                child: Text("enableAdvancedConsent",
                    style: TextStyle(fontSize: 12)),
                onPressed: _enableAdvancedConsent),
            ElevatedButton(
                child: Text("enableProfilingConsent",
                    style: TextStyle(fontSize: 12)),
                onPressed: _enableProfilingConsent),
            ElevatedButton(
                child: Text("enableMonitoringConsent",
                    style: TextStyle(fontSize: 12)),
                onPressed: _enableMonitoringConsent),
            ElevatedButton(
                child: Text("enableAdvertisingConsent",
                    style: TextStyle(fontSize: 12)),
                onPressed: _enableAdvertisingConsent),
            ElevatedButton(
                child: Text(
                  "disableProfilingConsent",
                  style: TextStyle(fontSize: 12),
                ),
                onPressed: _disableProfilingConsent),
            ElevatedButton(
                child: Text("disableMonitoringConsent",
                    style: TextStyle(fontSize: 12)),
                onPressed: _disableMonitoringConsent),
            ElevatedButton(
                child: Text("disableAdvertisingConsent",
                    style: TextStyle(fontSize: 12)),
                onPressed: _disableAdvertisingConsent),
            ElevatedButton(
                child: Text("disableAdvancedConsent",
                    style: TextStyle(fontSize: 12)),
                onPressed: _disableAdvancedConsent),
            ElevatedButton(
                child: Text("sendTag", style: TextStyle(fontSize: 12)),
                onPressed: _sendTag),
            ElevatedButton(
                child: Text("sendTags", style: TextStyle(fontSize: 12)),
                onPressed: _sendTags),
            ElevatedButton(
                child:
                    Text("setExternalUserId", style: TextStyle(fontSize: 12)),
                onPressed: _setExternalUserId),
          ]),
        )),
      ),
    );
  }

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

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

  void _sendTags() async {
    var result;
    try {
      Map tags = {'sample1': 23, 'sample2': 27, 'sample3': 25};
      result = await FlutterProximityPlugin.sendTags(tags);
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("sendTags"),
            content: Text(result.toString()),
          );
        });
  }

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

  void _isLimitAdTrackingEnabled() async {
    var result;
    try {
      result = await FlutterProximityPlugin.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 FlutterProximityPlugin.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 FlutterProximityPlugin.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 FlutterProximityPlugin.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 _getProfilingConsent() async {
    var result;
    try {
      result = await FlutterProximityPlugin.getProfilingConsent;
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("getProfilingConsent"),
            content: Text(result.toString()),
          );
        });
  }

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

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

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

  void _getContext() async {
    var result;
    try {
      result = await FlutterProximityPlugin.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 FlutterProximityPlugin.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 FlutterProximityPlugin.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 {
      FlutterProximityPlugin.NEWJOB_ID = 123456;
      result = await FlutterProximityPlugin.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 {
      FlutterProximityPlugin.INSTALLATION_ID = "123456";
      result = await FlutterProximityPlugin.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 {
      FlutterProximityPlugin.VENDOR_ID = 123456;
      FlutterProximityPlugin.CONSENT = true;
      result = await FlutterProximityPlugin.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 _enableAdvancedConsent() async {
    var result;
    try {
      result = await FlutterProximityPlugin.enableAdvancedConsent;
    } on PlatformException catch (e) {
      result = e.message;
    }
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("enableAdvancedConsent"),
            content: Text(result.toString()),
          );
        });
  }

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

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

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

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

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

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

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

  void _setSessionId() async {
    var result;
    try {
      FlutterProximityPlugin.SESSION_ID = "123456";
      result = await FlutterProximityPlugin.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 FlutterProximityPlugin.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 FlutterProximityPlugin.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 FlutterProximityPlugin.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 FlutterProximityPlugin.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 FlutterProximityPlugin.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 FlutterProximityPlugin.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 customHandler(dynamic payload) {
    showDialog(
        context: this.context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("setExternalUserId"),
            content: Text(payload),
          );
        });
  }

  void _addCustomActionListeners() async {
    var result;
    try {
      FlutterProximityPlugin.addCustomActionListeners(customHandler, "test");
    } on PlatformException catch (e) {
      result = e.message;
    }
  }

  void _removeCustomActionListeners() async {
    var result;
    try {
      FlutterProximityPlugin.removeCustomActionListeners("test");
    } on PlatformException catch (e) {
      result = e.message;
    }
  }

  void _removeCustomActionListeners2() async {
    var result;
    try {
      FlutterProximityPlugin.removeCustomActionListeners("test2");
    } on PlatformException catch (e) {
      result = e.message;
    }
  }
}
0
likes
30
pub points
0%
popularity

Publisher

verified publishernext14.com

Next14 Kariboo Proximity SDK for Flutter

Homepage

License

MIT (LICENSE)

Dependencies

flutter, streams_channel

More

Packages that depend on jtproximity_flutter