如何编辑插件以添加我自己的属性?

How can I edit a plugin to add my own attributes?

我正在使用来自 here .This allows me to stream my id, latitude and longitude to the server so that the user can grab that details. I want to add one more attribute to this plugin heading How can I do it ? This is the plugin code from github

flutter_geofire 插件
  
import 'dart:async';

import 'package:flutter/services.dart';

class Geofire {
  static const MethodChannel _channel = const MethodChannel('geofire');

  static const EventChannel _stream = const EventChannel('geofireStream');

  static const onKeyEntered = "onKeyEntered";
  static const onGeoQueryReady = "onGeoQueryReady";
  static const onKeyMoved = "onKeyMoved";
  static const onKeyExited = "onKeyExited";

  static Stream<dynamic>? _queryAtLocation;

  static Future<bool> initialize(String path) async {
    final dynamic r = await _channel
        .invokeMethod('GeoFire.start', <String, dynamic>{"path": path});
    return r ?? false;
  }

  static Future<bool?> setLocation(
      String id, double latitude, double longitude) async {
    final bool? isSet = await _channel.invokeMethod('setLocation',
        <String, dynamic>{"id": id, "lat": latitude, "lng": longitude});
    return isSet;
  }

  static Future<bool?> removeLocation(String id) async {
    final bool? isSet = await _channel
        .invokeMethod('removeLocation', <String, dynamic>{"id": id});
    return isSet;
  }

  static Future<bool?> stopListener() async {
    final bool? isSet =
        await _channel.invokeMethod('stopListener', <String, dynamic>{});
    return isSet;
  }

  static Future<Map<String, dynamic>> getLocation(String id) async {
    final Map<dynamic, dynamic> response = await (_channel
        .invokeMethod('getLocation', <String, dynamic>{"id": id}));

    Map<String, dynamic> location = new Map();

    response.forEach((key, value) {
      location[key] = value;
    });

    // print(location);

    return location;
  }

  static Stream<dynamic>? queryAtLocation(
      double lat, double lng, double radius) {
    _channel.invokeMethod('queryAtLocation',
        {"lat": lat, "lng": lng, "radius": radius}).then((result) {
      // print("result" + result);
    }).catchError((error) {
      // print("Error " + error);
    });

    if (_queryAtLocation == null) {
      _queryAtLocation = _stream.receiveBroadcastStream();
    }
    return _queryAtLocation;
  }
}

在上面的setLocation方法中我想添加这样的东西

 static Future<bool?> setLocation(
      String id, double latitude, double longitude) async {
    final bool? isSet = await _channel.invokeMethod('setLocation',
        <String, dynamic>{"id": id, "lat": latitude, "lng": longitude, "hdg":heading});
    return isSet;
  }

即使我这样编辑,我的实时数据库中也只能得到纬度和经度? 我还缺少标题

我是这样称呼它的

void getLocationLiveUpdates() {
    hometabPageStreamSubscription =
        Geolocator.getPositionStream().listen((Position position) {
      initPositionPoint = position;

      //print("Position $initPosition");
      if (isDriverAvailable == true) {
        Geofire.setLocation(currentFirebaseUser.uid, position.latitude,
            position.longitude, position.heading);
      }
    });

您可以访问存储库并像下面那样使用。

dependencies:
  flutter_geofire:
    git:
      url: https://github.com/your_github/flutter_geofire.git

插件不变的情况下,按哪个。

  • 删除依赖并flutter pub get。然后重新添加 flutter pub get.
  • 执行 flutter clean 然后 flutter pub get