v4_navigation_engine 0.1.87 copy "v4_navigation_engine: ^0.1.87" to clipboard
v4_navigation_engine: ^0.1.87 copied to clipboard

Native custom Mapbox navigation for Mile projects.

example/lib/main.dart

import 'dart:convert';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'package:v4_navigation_engine/v4_navigation_lib.dart' as Nav;
import 'package:v4_navigation_engine_example/about.dart';
import 'package:v4_navigation_engine_example/navigation_download.dart';
import 'package:v4_navigation_engine_example/navigation_offline.dart';
import 'package:v4_navigation_engine_example/navigation_polyline.dart';
import 'package:v4_navigation_engine_example/navigation_saas.dart';
import 'package:v4_navigation_engine_example/navigation_sportif.dart';
import 'package:v4_navigation_engine_example/navigation_v4.dart';
import 'package:v4_navigation_engine_example/navigation_white_label.dart';

import 'modal.dart';

void main() {
  runApp(
      MaterialApp(
        initialRoute: MyApp.routeName,
        routes: {
          MyApp.routeName : (context) => MyApp(),
          About.routeName : (context) => About(),
        },
      )
  );
}

class MyApp extends StatefulWidget {
  static String routeName = "/";
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  //For iOS ONLY
  static const platform = const MethodChannel('com.mile.v4_navigation_engine_example/view_controller');

  Nav.OfflineDatas offlineDatas;

  @override
  void initState() {
    SharedPreferences.getInstance().then((prefs) {
      if(prefs.containsKey("ID_OF_ROUTE")) {
        setState(() {
          offlineDatas = Nav.OfflineDatas.fromDynamicData(json.decode(prefs.getString("ID_OF_ROUTE")));
        });
      }
    });
    super.initState();
  }

  runDownload() {
    Navigator.of(context).push(PageRouteBuilder(
        opaque: false,
        pageBuilder: (BuildContext context, _, __) {
          return NavigationDownload(mode: Nav.NavigationMode.NAVIGATE_IN_ROUTE, onDownloadFinished: onDownloadFinished,);
        }
    ));
  }

  void onDownloadFinished() {
    SharedPreferences.getInstance().then((prefs) {
      if(prefs.containsKey("ID_OF_ROUTE")) {
        setState(() {
          offlineDatas = Nav.OfflineDatas.fromDynamicData(json.decode(prefs.getString("ID_OF_ROUTE")));
        });
      }
    });
  }

  @override
  Widget build(BuildContext context) {

    return Scaffold(
        appBar: AppBar(
          title: const Text('Mile Navigation Plugin'),
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            InkWell(
                onTap: () {
                  Navigator.push(context,
                    MaterialPageRoute(
                      builder: (context) => NavigationV4(mode: Nav.NavigationMode.NAVIGATE_IN_ROUTE),
                    ),
                  );
                },
                child: Container(
                  height: 36,
                  width: 200,
                  color: Colors.blue,
                  child: Center(
                    child: Text(
                      "NAVIGATION V4",
                      style: TextStyle(
                        color: Colors.white,
                      ),
                    ),
                  ),
                )
            ),
            Container(height: 20,),
            InkWell(
                onTap: () {
                  Navigator.push(context,
                    MaterialPageRoute(
                      builder: (context) => NavigationWhiteLabel(mode: Nav.NavigationMode.NAVIGATE_IN_ROUTE),
                    ),
                  );
                },
                child: Container(
                  height: 36,
                  width: 200,
                  color: Colors.blue,
                  child: Center(
                    child: Text(
                      "NAVIGATOR WHITELABEL",
                      style: TextStyle(
                        color: Colors.white,
                      ),
                    ),
                  ),
                )
            ),

            Container(height: 20,),
            InkWell(
                onTap: () {
                  Navigator.push(context,
                    MaterialPageRoute(
                      builder: (context) => NavigationPolyline(mode: Nav.NavigationMode.NAVIGATE_IN_ROUTE),
                    ),
                  );
                },
                child: Container(
                  height: 36,
                  width: 200,
                  color: Colors.blue,
                  child: Center(
                    child: Text(
                      "NAVIGATOR POLYLINE",
                      style: TextStyle(
                        color: Colors.white,
                      ),
                    ),
                  ),
                )
            ),
            Container(height: 20,),
            InkWell(
                onTap: () {
                  Navigator.push(context,
                    MaterialPageRoute(
                      builder: (context) => NavigationSportif(mode: Nav.NavigationMode.NAVIGATE_IN_ROUTE),
                    ),
                  );
                },
                child: Container(
                  height: 36,
                  width: 200,
                  color: Colors.blue,
                  child: Center(
                    child: Text(
                      "NAVIGATOR SPORT",
                      style: TextStyle(
                        color: Colors.white,
                      ),
                    ),
                  ),
                )
            ),

            InkWell(
                onTap: () {
                  Navigator.push(context,
                    MaterialPageRoute(
                      builder: (context) => NavigationSaas(mode: Nav.NavigationMode.NAVIGATE_IN_ROUTE),
                    ),
                  );
                },
                child: Container(
                  height: 36,
                  width: 200,
                  color: Colors.blue,
                  child: Center(
                    child: Text(
                      "NAVIGATOR SAAS",
                      style: TextStyle(
                        color: Colors.white,
                      ),
                    ),
                  ),
                )
            ),

            Container(height: 40,),
            InkWell(
                onTap: () {
                  Modal.show(context, null, "Download the map", null, "to run the route while offline", "DOWNLOAD", runDownload, "NOT NOW", null);
                },
                child: Container(
                  height: 36,
                  width: 200,
                  color: Colors.blue,
                  child: Center(
                    child: Text(
                      "DOWNLOAD V4 MAP",
                      style: TextStyle(
                        color: Colors.white,
                      ),
                    ),
                  ),
                )
            ),
            Container(height: 20,),
            InkWell(
                onTap: () {

                },
                child: Container(
                  height: 36,
                  width: 200,
                  color: Colors.blue,
                  child: Center(
                    child: Text(
                      "DOWNLOAD LABEL MAP",
                      style: TextStyle(
                        color: Colors.white,
                      ),
                    ),
                  ),
                )
            ),
            Container(height: 20,),
            InkWell(
                onTap: () {
                  if(offlineDatas != null) {
                    Navigator.push(context,
                      MaterialPageRoute(
                        builder: (context) => NavigationOffline(mode: Nav.NavigationMode.NAVIGATE_IN_ROUTE, offlineDatas: this.offlineDatas,),
                      ),
                    );
                  }
                },
                child: Container(
                  height: 36,
                  width: 200,
                  color: offlineDatas == null ? Colors.grey : Colors.blue,
                  child: Center(
                    child: Text(
                      "START OFFLINE NAVIGATION",
                      style: TextStyle(
                        color: Colors.white,
                      ),
                    ),
                  ),
                )
            ),
            Container(height: 5,),
            InkWell(
                onTap: () {
                  setState(() {
                    offlineDatas = null;
                    SharedPreferences.getInstance().then((prefs) {
                      prefs.remove("ID_OF_ROUTE");
                    });
                  });
                },
                child: Container(
                  height: 36,
                  width: 200,
                  color: offlineDatas == null ? Colors.grey : Colors.red,
                  child: Center(
                    child: Text(
                      "REMOVE ROUTE IN CACHE",
                      style: TextStyle(
                        color: Colors.white,
                      ),
                    ),
                  ),
                )
            ),
          ],
        ),
    );
  }
}
0
likes
20
pub points
0%
popularity

Publisher

unverified uploader

Native custom Mapbox navigation for Mile projects.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on v4_navigation_engine