mappls_nearby_plugin 1.0.0 mappls_nearby_plugin: ^1.0.0 copied to clipboard
A Flutter plugin for integrating Mappls Nearby widget in a Flutter application on Android and iOS platfroms.
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:mappls_nearby_plugin/mappls_nearby_plugin.dart';
import 'package:mappls_gl/mappls_gl.dart';
void main() {
runApp(MaterialApp(
home: MyApp(),
));
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
static const String MAP_SDK_KEY = "";
static const String REST_API_KEY = "";
static const String ATLAS_CLIENT_ID = "";
static const String ATLAS_CLIENT_SECRET = "";
NearbyResult? _nearbyResult;
@override
void initState() {
super.initState();
MapplsAccountManager.setMapSDKKey(MAP_SDK_KEY);
MapplsAccountManager.setRestAPIKey(REST_API_KEY);
MapplsAccountManager.setAtlasClientId(ATLAS_CLIENT_ID);
MapplsAccountManager.setAtlasClientSecret(ATLAS_CLIENT_SECRET);
_nearbyResult = NearbyResult();
}
void openMapplsNearbyWidget() async {
NearbyResult nearbyResult;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
nearbyResult = await openNearbyWidget(nearbyUIOption: NearbyUIOption(categoryIconColor: "#FF0000"));
} on PlatformException {
nearbyResult = NearbyResult();
}
print(json.encode(nearbyResult.toJson()));
// 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;
setState(() {
_nearbyResult = nearbyResult;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Nearby Plugin example'),
),
body: Center(
child: Column(
children: [
SizedBox(height: 20),
Text(_nearbyResult?.distance == null? 'Distance: ':'Distance: ${_nearbyResult?.distance}'),
SizedBox(height: 20),
Text(_nearbyResult?.mapplsPin == null? 'ELoc: ':'ELoc: ${_nearbyResult?.mapplsPin}'),
SizedBox(height: 20),
Text(_nearbyResult?.placeName == null? 'Place Name: ':'Place Name: ${_nearbyResult?.placeName}'),
SizedBox(height: 20),
Text(_nearbyResult?.placeAddress == null? 'Place Address: ':'Place Address: ${_nearbyResult?.placeAddress}'),
SizedBox(height: 20),
Text(_nearbyResult?.orderIndex == null? 'Index: ':'Index: ${_nearbyResult?.orderIndex}'),
SizedBox(height: 20),
TextButton(
child: Text('Open Nearby Search Widget'),
onPressed: () => {
openMapplsNearbyWidget(),
})
]
)
)
),
);
}
}