navigation_with_mapbox 0.0.2
navigation_with_mapbox: ^0.0.2 copied to clipboard
Add Turn By Turn Navigation to Your Flutter Application Using MapBox.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
//we import our plugin
import 'package:navigation_with_mapbox/navigation_with_mapbox.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
//instantiate our plugin class
final _navigationWithMapboxPlugin = NavigationWithMapbox();
@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;
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () async {
//in an asynchronous function we call the method that starts the map
await _navigationWithMapboxPlugin.startNavigation(
//origin refers to the user's starting point at the time of starting the navigation
origin:
WayPoint(latitude: 4.809432, longitude: -75.700660),
//destination refers to the end point or goal for the user at the time of starting the navigation
destination:
WayPoint(latitude: 4.759335, longitude: -75.923914),
//if we enable this option we can choose a destination with a sustained tap
setDestinationWithLongTap: false,
//if we enable this option we will activate the simulation of the route
simulateRoute: false,
//optional, message that will be displayed when starting the navigation map
msg: '¡Buen viaje, disfruta de tu recorrido!',
//unit of measure in which the navigation assistant will speak to us
//optional, default: metric
voiceUnits: 'imperial',
//language in which the navigation assistant will speak to us
//optional, default: en
language: 'es',
//if we enable this option we can see alternative routes when starting the navigation map
//optional, default: false
alternativeRoute: true,
//the style or theme with which the navigation map will be loaded
//optional, default: streets, others: dark, light, traffic_day, traffic_night, satellite, satellite_streets, outdoors
style: 'traffic_night',
//refers to the navigation mode, the route and time will be calculated depending on this
//optional, default: driving, others: walking, cycling
profile: '');
},
child: const Text('Iniciar Navegacion'),
),
ElevatedButton(
onPressed: () async {
//in an asynchronous function we call the method that starts the map
await _navigationWithMapboxPlugin.startNavigation(
//origin refers to the user's starting point at the time of starting the navigation
origin:
WayPoint(latitude: 4.809432, longitude: -75.700660),
//destination refers to the end point or goal for the user at the time of starting the navigation
destination:
WayPoint(latitude: 4.750128, longitude: -75.912423),
//if we enable this option we can choose a destination with a sustained tap
setDestinationWithLongTap: true,
//if we enable this option we will activate the simulation of the route
simulateRoute: false,
//language in which the navigation assistant will speak to us
//optional, default: en
language: 'es',
//optional, message that will be displayed when starting the navigation map
msg: '¡Buen viaje, disfruta de tu recorrido!',
//the style or theme with which the navigation map will be loaded
//optional, default: streets, others: dark, light, traffic_day, traffic_night, satellite, satellite_streets, outdoors
style: 'satellite_streets');
},
child: const Text('Iniciar Navegacion 2'),
),
],
),
),
),
);
}
}