mapmyindia_nearby_plugin 0.2.0 copy "mapmyindia_nearby_plugin: ^0.2.0" to clipboard
mapmyindia_nearby_plugin: ^0.2.0 copied to clipboard

A Flutter plugin for integrating MapmyIndia Nearby widget in a Flutter application on Android and iOS platfroms.

example/lib/main.dart

import 'dart:convert';

import 'package:flutter/material.dart';

import 'package:flutter/services.dart';
import 'package:mapmyindia_nearby_plugin/mapmyindia_nearby_plugin.dart';
import 'package:mapmyindia_gl/mapmyindia_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();
    MapmyIndiaAccountManager.setMapSDKKey(MAP_SDK_KEY);
    MapmyIndiaAccountManager.setRestAPIKey(REST_API_KEY);
    MapmyIndiaAccountManager.setAtlasClientId(ATLAS_CLIENT_ID);
    MapmyIndiaAccountManager.setAtlasClientSecret(ATLAS_CLIENT_SECRET);
    _nearbyResult = NearbyResult();
  }


  void openMapmyIndiaNearbyWidget() 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?.eLoc == null? 'ELoc: ':'ELoc: ${_nearbyResult?.eLoc}'),
                      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: () => {
                          openMapmyIndiaNearbyWidget(),
                        })
                    ]
                )
            )
      ),
    );
  }
}
1
likes
105
pub points
60%
popularity

Publisher

verified publishermapmyindia.com

A Flutter plugin for integrating MapmyIndia Nearby widget in a Flutter application on Android and iOS platfroms.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, mapmyindia_gl, mapmyindia_place_widget

More

Packages that depend on mapmyindia_nearby_plugin