【发布时间】:2021-10-06 11:35:49
【问题描述】:
我正在使用来自here 的flutter_geofire 插件。这允许我将我的id、纬度和经度流式传输到服务器,以便用户可以获取该详细信息。我想为这个插件添加一个属性heading我该怎么做?这是来自github的插件代码
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);
}
});
【问题讨论】:
-
我认为这是不可能的,它需要更改软件包附带的 dart 文件。这将暂时起作用,因为您运行 pub get 的净时间将重置它。很多时候,当我需要一个自定义版本的包(convex_navbar)时,我将类文件复制到我的代码中并进行了自己的编辑。可能有更好的方法,但这是我过去所做的。
-
你可以fork它,然后修改它,然后你就可以使用它了。
标签: flutter dart firebase-realtime-database geofire