flutter - 如何在 Flutter 上的 StreamBuilder 之前调用 Future 方法?
问题描述
我试图在使用该信息获取流数据之前获取当前用户位置。所以使用 Flutter 1.17.5
,geolocator: ^5.3.2+2
我正在Position
使用 follow util 类
class LocationProvider {
Future<Position> getPosition() async {
Position position = await Geolocator()
.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
return position;
}
}
然后我必须将信息传递给bloc
才能使用标记检索流数据
Widget _getAllProducts(ProductBloc productBloc, LocationProvider locationProvider) async{
Position position = locationProvider.getPosition();
var longitude = position.longitude;
var latitude = position.latitude;
int meter = 50;
productBloc.allByRange(meter, latitude, longitude);
return StreamBuilder(
stream: productBloc.productsByRangeStream,
我是怎么收到这个消息的
A value of type 'StreamBuilder<List<ProductModel>>' can't be returned from method '_getAllProducts' because it has a return type of 'Widget'
编辑 1
class ProductBloc {
Stream<List<ProductModel>> get productsByRangeStream =>
_allByRangeProductsController.stream;
void allByRange(double range, double lat, double lon) async {
final products = await _productFirebaseService.allByRange(range, lat, lon);
_allByRangeProductsController.sink.add(products);
}
}
我该如何解决?
解决方案
推荐阅读
- google-apps-script - Google 工作表错误:访问带有 id 的文档时服务电子表格超时
- swift - 集合视图中单元格的宽度不正确
- oracle - 无法使用 Oracle PL/SQL 访问 Web 服务
- javascript - 查找文本并在单选按钮单击时替换它
- c - libcurl 会话和可选的连接重用
- autofac - Autofac RegisterAssemblyTypes 尝试解析所有公共类型
- typescript - console.log 使用 http get 从 json url 记录数据
- php - 致命错误:无法在第 690 行的 dmp/inc/function.php 中重新声明 contact_us()(之前在 dmp/inc/function.php:690 中声明)
- php - 警告:count():参数必须是数组或对象,在 C:\wamp\www\news13102020\admin\process.php 第 55 行实现 Countable
- android - 使用 materix 变换旋转和翻转 Android Fornt Camera2 图像