tar_sdk_flutter 2.1.2 copy "tar_sdk_flutter: ^2.1.2" to clipboard
tar_sdk_flutter: ^2.1.2 copied to clipboard

Implementation of the TAR SDK for Flutter.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:tar_sdk_flutter/tar_sdk_flutter.dart';
import 'package:tar_sdk_flutter/tar_sdk_flutter_method_channel.dart';
import 'package:tar_sdk_flutter/tar_sdk_flutter_platform_interface.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';

void main() async {
  await dotenv.load(fileName: '.env');
  runApp(const MyApp());
}

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

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

class _MyAppState extends State<MyApp> {
  CancelListening cancelListening = () {};

  final _tarSdkFlutterPlugin = TarSdkFlutter();

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    // 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(() {
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('TAR SDK example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              TextButton(onPressed: () async {
                var isSupported = await _tarSdkFlutterPlugin.isSupported();
                if (isSupported) {
                  var apiKey = dotenv.env['TAR_APIKEY'] ?? '';
                  var settings = TARSettings(
                    apiKey: apiKey, 
                    language: 'hu',
                    defaultLanguage: 'hu',
                    activeLanguages: [ 'en', 'nl', 'fr', 'hu' ],
                    walletMode: true,
                    mapMode: true,
                    paintingMode: true,
                    colorPalette: {
                      'blue': '#000000'
                    },
                    startMode: TARStartMode.geo,
                    useProduction: true);
                  cancelListening = await _tarSdkFlutterPlugin.startListening(
                    (success) {
                      print('OnInitialize $success');
                    }, 
                    (message) {
                      print('OnSDKMessage ${message['assetID']}');
                    }, 
                    () {
                      print('OnSDKUnload');
                      cancelListening();
                    });
                  await _tarSdkFlutterPlugin.showTAR(settings);
                }
              },
              child: const Text('Open TAR SDK')),
              TextButton(onPressed: () async {
                var isSupported = await _tarSdkFlutterPlugin.isSupported();
                if (isSupported) {
                  var apiKey = dotenv.env['TAR_APIKEY'] ?? '';
                  var settings = TARWithAssetSettings(
                    apiKey: apiKey, 
                    language: 'nl', 
                    defaultLanguage: 'nl',
                    activeLanguages: [ 'en', 'nl', 'fr' ], 
                    colorPalette: {
                      'blue': '#ff0000'
                    }, 
                    startMode: TARStartMode.indoor,
                    useProduction: true,
                    assetId: '672b8243aba9420026abc5e4');
                  cancelListening = await _tarSdkFlutterPlugin.startListening(
                    (success) {
                      print('OnInitialize $success');
                    }, 
                    (message) {
                      print('OnSDKMessage ${message['assetID']}');
                    }, 
                    () {
                      print('OnSDKUnload');
                      cancelListening();
                    });
                  await _tarSdkFlutterPlugin.showTARWithAsset(settings);
                }
              },
              child: const Text('Open TAR SDK with asset'))
            ]
          )
        ),
      ),
    );
  }
}
2
likes
130
points
51
downloads

Publisher

unverified uploader

Weekly Downloads

Implementation of the TAR SDK for Flutter.

Homepage

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on tar_sdk_flutter