小编K.c*_*him的帖子

如何使用 Google Maps For Flutter 将初始相机位置设置为当前设备的纬度和经度

我正在为我的应用程序使用 google maps flutter 插件。我希望初始相机位置目标(LatLng)与当前设备的纬度和经度完全相等,以便相机在启动时显示用户当前所在的位置。但是,我在尝试执行此操作时遇到了问题。我曾尝试使用 Location 和 Geolocator 包,但没有关于如何做我想要实现的目标的明确示例。

当我尝试使用currentLocation.latitudecurrentLocation.longitude位置包作为相机目标中 Latlng 的值时,我遇到了以下错误。

“初始化器只能访问静态成员”

坦率地说,我不知道在这种情况下这意味着什么。我已经阅读了一些示例,但没有一个清楚地实现我真正想要实现的目标

import 'package:flutter/cupertino.dart';
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:location/location.dart';


class Map extends StatefulWidget {
  @override
  State<Map> createState() => MapState();
}

class MapState extends State<Map> {
  Completer<GoogleMapController> _controller = Completer();
  var currentLocation = LocationData;

  var location = new Location();

 Future _getLocation() async {
    try {
      location.onLocationChanged().listen((LocationData currentLocation) {
        print('Latitude:${currentLocation.latitude}');
        print('Longitude:${currentLocation.longitude}');
        return LatLng(currentLocation.latitude, currentLocation.longitude);
      });
    } catch (e) {
     print('ERROR:$e');
      currentLocation = null; …
Run Code Online (Sandbox Code Playgroud)

google-maps flutter

15
推荐指数
2
解决办法
2万
查看次数

如何在Flutter App中正确使用BlocListener和BlocProvider

我在 Flutter 应用程序中使用 flutter_bloc 4.0.0,我使用 Felix Angelov 的示例(https://medium.com/flutter-community/firebase-login-with-flutter-bloc-47455e6047b0)来实现登录或使用块模式的登录流程。它工作正常,但在我更新我的 Flutter 并检查我的代码后,我发现了一系列错误。我不明白他们为什么要来,因为上周一切都很好。小部件的构建方法中的块的实现对我来说突然变得错误了。我收到错误:

\n\n

1.“BlocListener的\xe2\x80\x98A值类型不能从方法构建中返回\xe2\x80\x99,因为它有一个widget的返回类型”

\n\n
    \n
  1. \xe2\x80\x98BlocProvider> 的值类型可以从方法构建中返回\xe2\x80\x99,因为它的返回类型为 widget\xe2\x80\x99
  2. \n
\n\n

第一个错误的代码

\n\n
class LoginForm extends StatefulWidget {\n  final UserRepository _userRepository;\n\n  LoginForm({Key key, @required UserRepository userRepository})\n      : assert(userRepository != null),\n        _userRepository = userRepository,\n        super(key: key);\n\n  State<LoginForm> createState() => _LoginFormState();\n}\n\nclass _LoginFormState extends State<LoginForm> {\n  final TextEditingController _emailController = TextEditingController();\n  final TextEditingController _passwordController = TextEditingController();\n\n  LoginBloc _loginBloc;\n\n  UserRepository get _userRepository => widget._userRepository;\n\n  bool get isPopulated =>\n      _emailController.text.isNotEmpty && _passwordController.text.isNotEmpty;\n\n  bool isLoginButtonEnabled(LoginState state) …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-packages flutter-bloc

8
推荐指数
1
解决办法
4万
查看次数

如何解析 flutter 中的 graphql 响应

我正在尝试在我的 flutter 应用程序中解析来自 neo4j-graphql 后端的 graphql 响应。我正在使用 flutter_graphql 插件向后端进行查询。但是,当我尝试解析响应(JSON)时,我收到“LinkHashMap 不是用户映射的子类型”。

我尝试修改我的序列化类来解析响应,但没有可用的。下面是来自 neo4j graphql 的 JSON 响应


 /*I HAVE EDITED THE JSON RESPONSE. THE FULL JSON RESPONSE FROM THE SERVER IS AS BELOW*/
{
  "data": {
    "User": [
      {
        "userId": 1,
        "city": "NewYork",
        "country": "User",
        "captionType": "User",
        "state": "New York",
        "firstName": "example2",
        "lastname": "example",
        "email": "example2@gmail.com"
      }
    ]
  },
  "extensions": {
    "type": "READ_ONLY"
  }
}
Run Code Online (Sandbox Code Playgroud)

下面是代表上述响应的类


 /*I HAVE EDITED THE JSON RESPONSE. THE FULL JSON RESPONSE FROM THE SERVER IS AS …
Run Code Online (Sandbox Code Playgroud)

parsing json dart graphql flutter

5
推荐指数
1
解决办法
6366
查看次数