navigine_sdk 0.0.1 copy "navigine_sdk: ^0.0.1" to clipboard
navigine_sdk: ^0.0.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';

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: "3F77-4634-FCEE-2423",
    );
    loadLocation();
  }

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

  startNavigation() async {
    thread = await NavigationThread.startNavigation();
    setState(() {});

    print(await thread.getLocation());

    print(await thread.getDeviceInfo());
  }

  StreamSubscription<DeviceInfo> stream;

  @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();
                      print(l.name);
                      print(l.version);

                      stream = thread.getDeviceInfoListener().listen((dI) {
                        print(dI.x);
                        print(dI.y);
                      });
                    }
                  : null,
            ),
            FlatButton(
                child: Text("Stop Location"),
                onPressed: () {
                  stream.cancel();
                }),
          ],
        ),
      ),
    );
  }
}
3
likes
0
pub points
31%
popularity

Publisher

verified publisheraawaz.dev

A new flutter plugin project.

Homepage

License

unknown (LICENSE)

Dependencies

flutter, meta

More

Packages that depend on navigine_sdk