小编Mul*_*dec的帖子

How to catch an error coming from a Future in flutter widget test?

I'm facing an issue while doing widget testing on a widget that throws an exception during a Future.

Code to reproduce the problem

Here's a simple testwidget that reproduces the problem in a very simple way (thanks to Remi Rousselet for the simplification of the problem).

testWidgets('This test should pass but fails', (tester) async {
  final future = Future<void>.error(42);

  await tester.pumpWidget(FutureBuilder(
    future: future,
    builder: (_, snapshot) {
      return Container();
    },
  ));
});
Run Code Online (Sandbox Code Playgroud)

Expected result

我希望测试能够顺利完成。相反,它失败并显示以下错误:

??? EXCEPTION CAUGHT BY …
Run Code Online (Sandbox Code Playgroud)

error-handling dart flutter flutter-test

13
推荐指数
2
解决办法
1250
查看次数

Flutter Web 上传到 Firestore

我在使用 Flutter web 并将图像上传到 Firestore 时遇到问题。我很确定问题出在图像选择器中,因为普通(移动)图像选择器不适用于网络。普通图像选择器返回一个文件,但替代image_picker_web返回一个图像,该图像在上传时被拒绝,因为它需要一个Future<File>.

image_picker_web有一种替代方法可以返回Uint8List我使用过的 a,然后转换为Filevia dart:html- 并正常上传,但图像已损坏且无法查看。

这是我所做的:

按下按钮 - 选择图像Uint8List> 转换为Image,存储在内存中并在屏幕上显示

                  onPressed: () async {
                    //Upload Image as Uint8List
                    imageBytes = await ImagePickerWeb.getImage(asUint8List: true);
                    //Convert Uint8List to Image
                    _image = Image.memory(imageBytes);
                    //Show new image on screen
                    setBottomSheetState(() {
                      image = _image;
                    });
                  },
Run Code Online (Sandbox Code Playgroud)

转换Uint8ListFileusingdart:html File和 name as users UID.png (PNG Uploaded)

 imageFile = html.File(imageBytes, …
Run Code Online (Sandbox Code Playgroud)

firebase flutter google-cloud-firestore flutter-web

13
推荐指数
1
解决办法
2074
查看次数

Runtime.getRuntime().availableProcessors() 在容器优化操作系统上始终返回 1

我正在 GCP 上的 kubernetes 引擎上部署 Elasticsearch,但遇到了性能问题。Elasticsearch根据核心数量确定各种线程池的大小。尽管我创建了一个 32 核 VM,但线程池大小仅为 1。

我确实编写了一个测试程序来打印Runtime.getRuntime().availableProcessors(),它只是打印为 1 。

我想这与“容器优化操作系统”有关,这是使用 Kubernetes Engine 的虚拟机上允许的唯一操作系统。当我在 GCP 上创建 Debian VM 时,Runtime.getRuntime().availableProcessors()返回 8。不确定如何在 GCP kubernetes 引擎上使用 elasticsearch。欢迎任何想法或建议。

当我在没有 kubernetes 的 GCP 上创建 Debian 虚拟机时,返回Runtime.getRuntime().availableProcessors()8。

java elasticsearch kubernetes google-kubernetes-engine

7
推荐指数
1
解决办法
4890
查看次数

Flutter 构建失败异常 java.lang.ClassNotFoundException: com.android.tools.lint.client.api.Vendor

我正在使用这个命令来创建构建

flutter build apk  --split-per-abi  --no-sound-null-safety --no-tree-shake-icons --no-shrink -v
Run Code Online (Sandbox Code Playgroud)

我使用的是颤振版本2.5.0

我收到这个错误

Caused by: java.lang.ClassNotFoundException: com.android.tools.lint.client.api.Vendor
[        ]  at com.intellij.util.lang.UrlClassLoader.findClass(UrlClassLoader.java:328)
[        ]  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
[        ]  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题来创建构建?

flutter

7
推荐指数
1
解决办法
8814
查看次数

如何在 Stateless Widget 中实例化最终变量?

我正在尝试根据输入值将某些值分配给某些属性。该值在小部件的整个生命周期中保持不变。因此我使用了Stateless小部件。但是,我无法从构造函数中为 props 分配值。

class InOrOut extends StatelessWidget {
  final Condition condition;
  final bool isIconVisible;
  final Color backgroudColor;
  final Color foregrounndColor;

  InOrOut({Key key, this.condition, this.isIconVisible}) : super(key: key) {
    switch (condition) {
      case Condition.IN:
        backgroudColor = Colors.green[100];
        foregrounndColor = Colors.green[100];
        isIconVisible = false
        break;
      case Condition.ABSENT:
        backgroudColor = Colors.grey[300];
        foregrounndColor = Colors.green[100];
        isIconVisible = true;
        break;
      case Condition.OUT:
        backgroudColor = Colors.red[100];
        foregrounndColor = Colors.green[100];
        isIconVisible = false;
        break;
      default:
        backgroudColor = Colors.red[100];
        foregrounndColor = Colors.green[100];
        isIconVisible = false;
    } …
Run Code Online (Sandbox Code Playgroud)

flutter

6
推荐指数
1
解决办法
4468
查看次数

在 ios 上进行代码签名时,无法在 Codemagic 上创建身份验证会话

我觉得我错过了一些东西,但不能确定。我正在尝试将 codemagic 的自动代码签名功能用于 IOS 应用商店发布。

但是在构建过程中它会打印;

> /usr/local/bin/flutter build ios --release --no-codesign

Warning: Building for device with codesigning disabled. You will have to manually codesign before deploying to device.
Run Code Online (Sandbox Code Playgroud)

并在出版期间打印;

"Error Domain=ITunesSoftwareServiceErrorDomain Code=-22020 \"We are unable to create an authentication session.\" UserInfo={NSLocalizedDescription=We are unable to create an authentication session., NSLocalizedFailureReason=Unable to validate your application.}"
Run Code Online (Sandbox Code Playgroud)

我正在启用应用商店连接,选择自动代码签名并选择应用商店来配置配置文件类型。而且我确定我的 ID 和其他字段是正确的。

任何帮助,将不胜感激。

flutter codemagic

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

无法使用 Flutter 从 Firestore 检索文档

.. 我正在将 Cloud Firestore 用于我正在进行的 Flutter 项目。

数据库截图

上面添加的是我的数据库模型的屏幕截图。

基本上每个用户文档都有自己的个人信息字段和他/她的项目集合。

项目示例 1

项目示例 2

以上是两个项目展开后的截图。它具有项目的详细信息,例如其 CR、字段、成员等。

 x = StreamBuilder(
          stream: _projectStreamLock ? null : Firestore.instance.collection('User').document(_savedUser.user.uid).collection('Projects').snapshots(),
          builder: (BuildContext context,AsyncSnapshot<QuerySnapshot> snapshots){
            if(snapshots.hasData && !_projectStreamLock){

              List<DocumentSnapshot> projectList = snapshots.data.documents;

              _savedUser.user.projects = [];

              for(int i=0;i<projectList.length;i++){
                _savedUser.user.projects.add(Project(name: projectList[i].documentID,field: projectList[i].data["Field"],subField: projectList[i].data["SubField"],completionRate: projectList[i].data["CR"],members: projectList[i].data["Members"]));
              }

              return ListView.builder(
                  itemCount: snapshots.data.documents.length,
                  itemBuilder: (_,int index){
                    print(snapshots.data.documents[index].documentID + " : " + snapshots.data.documents[index].data["CR"].toString());
                    return ProjectCard(
                      globalHeight: _height,globalWidth: _width,
                      projectDetails: Project(
                          name : snapshots.data.documents[index].documentID,
                          completionRate: snapshots.data.documents[index].data["CR"],
                          field: snapshots.data.documents[index].data["Field"],
                          members: snapshots.data.documents[index].data["Members"],
                          subField: "Hello", …
Run Code Online (Sandbox Code Playgroud)

dart flutter google-cloud-firestore

2
推荐指数
1
解决办法
264
查看次数

Android 模拟器不处理 http get 请求,但 iOS 模拟器工作正常

我想要做的是:使用谷歌地图 api 获取数据,然后将数据传递到下一个屏幕。

有什么问题:它在 iOS 模拟器上运行良好,它设法进入下一个屏幕并用数据填充地图(打印位置、“yay”、http 状态代码和“loopyays”)。但是在 android 模拟器上,它只打印位置和“yay”,并挂在那里,不会导航到下一个屏幕。

什么地方出了错?:/ 请帮帮我..

class _LoadingScreenState extends State<LoadingScreen> {
  void getUserLocation() async {
    try {
      Position position = await Geolocator()
          .getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
      print(position);
      Set<Marker> markers = {};
      String url =
          'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${position.latitude},${position.longitude}&maxprice=4&radius=1500&type=restaurant&keyword=cruise&key=AIzaSyDVzxxxxxxxxxxxxxxxxxxx';
      print('yay');
      http.Response data = await http.get(url);
      print(data.statusCode);
      var resultList = jsonDecode(data.body)['results'];
      for (Map i in resultList) {
        var coords = (i['geometry']['location']);
        print('loopyay');
        markers.add(Marker(
            markerId: MarkerId(i['name']),
            position: LatLng(coords['lat'], coords['lng'])));
      }

      Navigator.push(context, MaterialPageRoute(builder: (context) {
        return UserLocationScreen(
          userLocation: position,
          markers: markers,
        ); …
Run Code Online (Sandbox Code Playgroud)

android http dart flutter

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

如何使用react js复制typeform

我是 React js 的新手,我想创建一个像 typeform 这样的表单,但我没有使用 typeform。我有一个包含 5 个问题的列表,我希望在用户单击“下一步”后,它会一一出现,并具有像打字机一样的滑动效果。

这个问题也可能来自 json 数据。我刚刚使用了一种方法。

这是沙箱链接:https://codesandbox.io/s/brave-firefly-2c47h

reactjs material-ui typeform

-1
推荐指数
1
解决办法
4762
查看次数