navigine_sdk 1.1.1 copy "navigine_sdk: ^1.1.1" to clipboard
navigine_sdk: ^1.1.1 copied to clipboard

outdated

A new flutter plugin project.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:navigine_sdk/navigine_sdk.dart';
import 'dart:async';

import 'package:navigine_sdk_example/image_view.dart';

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

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

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: HomeScreen(),
      ),
    );
  }
}

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  NavigineSDK? navigine;
  NavigationThread? thread;

  double progress = 0.0;

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

  Future<void> initPlatformState() async {
    navigine = await NavigineSDK.initializeSDK(
      userHash: "4723-71B6-9558-E374",
    );
    loadLocation();
  }

  loadLocation() async {
    await navigine?.loadLocation(
      locationId: 96499,
      onSuccess: () {
        print('Success');
        // This is a test.
        startNavigation();
      },
      onFailed: (code) {
        print("Failed $code");
      },
      onUpdate: (state) {
        setState(() {
          progress = state / 100;
        });
      },
    );
  }

  DeviceInfo? deviceInfo;

  startNavigation() async {
    thread = await NavigationThread.startNavigation();
    setState(() {});
    thread!.getDeviceInfoListener().listen((d) {
      setState(() {
        print(d.x);
        print(d.y);
        deviceInfo = d;
      });
    });
  }

  StreamSubscription<DeviceInfo>? stream;
  Location? l;
  SubLocation? subLocation;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          children: <Widget>[
            FlatButton(
              child: Text("Get Location"),
              onPressed: thread != null
                  ? () async {
                      Location l = await thread!.getLocation();
                      showDialog(
                        context: context,
                        builder: (_) => SimpleDialog(
                          children: l.subLocations
                              .map(
                                (e) => ListTile(
                                  title: Text(e.name),
                                  onTap: () {
                                    setState(() {
                                      subLocation = e;
                                    });
                                    Navigator.pop(context);
                                  },
                                ),
                              )
                              .toList(),
                        ),
                      );
                    }
                  : null,
            ),
            FlatButton(
              child: Text("Stop Location"),
              onPressed: () {
                stream?.cancel();
              },
            ),
            if (subLocation != null)
              SubLocationWidget(
                subLocation: subLocation!,
                x: deviceInfo?.x ?? 0,
                y: deviceInfo?.y ?? 0,
              ),
          ],
        ),
      ),
    );
  }
}
3
likes
0
points
42
downloads

Publisher

verified publishernavigine.com

Weekly Downloads

A new flutter plugin project.

Homepage

License

unknown (license)

Dependencies

collection, flutter, meta

More

Packages that depend on navigine_sdk

Packages that implement navigine_sdk