Coder Social home page Coder Social logo

fluxmap's Introduction

Fluxmap

pub package Build Status

A map to handle real time location updates for multiple devices. The map takes a stream of Device objects for input and manages their state on the map

  • Automatic network status management: the devices network status is calculated from their last position report. Callbacks are available for state changes
  • Access to the map state: the state of the map is available via a provider

Screenshot

Screenshot

View this example on the web

Usage

Declare state mutations actions

Define you callbacks and options for devices state changes:

final flux = FluxMapState(
   onDeviceDisconnect: (device) =>
       print("Device ${device.name} is disconnected"),
   onDeviceOffline: (device) =>
       print("Device ${device.name} is offline"),
   onDeviceBackOnline: (device) =>
       print("Device ${device.name} is back online"),
   markerGestureDetectorBuilder: (context, device, child) {
       return GestureDetector(
           child: child,
           onTap: () {
             print("Tap $device");
           },
           onDoubleTap: () {
             print("Double tap $device");
           },
           onLongPress: () {
             print("Long press $device");
           });
   });

Use the positions stream

Create a stream controller for your positions updates:

final StreamController<Device> _devicesFlux = StreamController<Device>();

Place the map widget in your widgets tree:

Widget map = FluxMap(state: flux,
        devicesFlux: _devicesFlux.stream));

Then feed the map with location updates:

final device = Device(
   name: "phone 1",
   position: GeoPoint(latitude: 0.0, longitude: 0.0, speed: 31.0));
_devicesFlux.sink.add(device);_

Use map controls

To manage the map assets and controls an instance of Map controller is available:

flux.map.addMarker(name: "My marker",
                   marker: Marker( /* A Flutter Map marker*/))

Access to the map state

It is possible to plug on the map state with Provider: in a parent widget:

import 'package:fluxmap/fluxmap.dart';
import 'package:provider/provider.dart';

@override
Widget build(BuildContext context) {
  return StreamProvider<FluxMapStore>.value(
      initialData: FluxMapStore(),
      value: fluxMapStoreController.stream,
      child: MyWidget());
}

In the widget:

@override
Widget build(BuildContext context) {
  final mapState = Provider.of<FluxMapStore>(context).state;
  final device = mapState.devices[deviceId];
  Color color;
  switch (device.networkStatus) {
    case DeviceNetworkStatus.online:
      color = Colors.green;
      break;
    case DeviceNetworkStatus.disconnected:
      color = Colors.orange;
      break;
    case DeviceNetworkStatus.offline:
      color = Colors.lightBlueAccent;
      break;
    default:
      color = Colors.grey[300];
  }
  /// ...
  return SomeWidget();
}

fluxmap's People

Contributors

synw avatar

Stargazers

Semyon Titov avatar Eugeny Shlyagin avatar  avatar tom quas avatar Mariam Younes avatar  avatar  avatar Shujaat Ali Khan avatar  avatar Jean Paul Mosquera avatar  avatar igaurab avatar

Watchers

James Cloos avatar Ibrahima Gaye avatar  avatar  avatar

fluxmap's Issues

example real app

is posible to add in example a real app that load location from firebase realtime database?

thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.