v4_navigation_engine 0.1.43 v4_navigation_engine: ^0.1.43 copied to clipboard
Native custom Mapbox navigation for Mile projects.
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';
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_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');
OfflineDatas offlineDatas;
@override
void initState() {
SharedPreferences.getInstance().then((prefs) {
if(prefs.containsKey("ID_OF_ROUTE")) {
setState(() {
offlineDatas = 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: NavigationMode.NAVIGATE_IN_ROUTE, onDownloadFinished: onDownloadFinished,);
}
));
}
void onDownloadFinished() {
SharedPreferences.getInstance().then((prefs) {
if(prefs.containsKey("ID_OF_ROUTE")) {
setState(() {
offlineDatas = 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: 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: 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: 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: NavigationMode.NAVIGATE_IN_ROUTE),
),
);
},
child: Container(
height: 36,
width: 200,
color: Colors.blue,
child: Center(
child: Text(
"NAVIGATOR SPORT",
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 MAP",
style: TextStyle(
color: Colors.white,
),
),
),
)
),
Container(height: 20,),
InkWell(
onTap: () {
if(offlineDatas != null) {
Navigator.push(context,
MaterialPageRoute(
builder: (context) => NavigationOffline(mode: 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,
),
),
),
)
),
],
),
);
}
}