小编eli*_*ama的帖子

Flutter:RangeError(最大值):必须为正且 <= 2^32:不在包含范围 1..4294967296:0 内

我正在尝试制作一个随机选择某人的应用程序。在页面中,有一些文本字段和一个按钮,您可以在其中输入您的姓名。当我单击该按钮时,它会将我带到结果页面,我想在其中显示随机选择的人的姓名。我在结果页面的构造函数中传递了人员列表,并做了以下操作:

import 'package:flutter/material.dart';
import 'dart:math';
class ResultScreen extends StatefulWidget {
 final List persons;
ResultScreen({this.persons});

@override
_ResultScreenState createState() => _ResultScreenState();
}

class _ResultScreenState extends State<ResultScreen> {
final _random = Random();

// var selectedPerson = persons[_random.nextInt(persons.length)];
                // print(selectedPerson);
@override
Widget build(BuildContext context) {
return Material(
      child: Container(
    decoration: BoxDecoration(
        image: DecorationImage(
            image: AssetImage("lib/images/fond.jpg"), fit: BoxFit.cover)),
    child: Center(
      child: Text(' And the loser is\n ${widget.persons[_random.nextInt(widget.persons.length)]} ', 
  style: TextStyle(color: Colors.black, fontSize: 50, fontWeight: FontWeight.bold),),
    ),
  ),
  );
  }
  }
Run Code Online (Sandbox Code Playgroud)

当我导航器推送结果页面时出现此错误:

RangeError (max): Must be …
Run Code Online (Sandbox Code Playgroud)

dart flutter

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

使用flutter和firestore创建文档时如何存储文档ID

我正在创建一个 Todo 应用程序,我需要访问存储在 firestore 中的文档的 ID 才能删除它们。但是我在创建它时不知道如何保存它。这是我添加屏幕中创建新文档的部分。

 _firestore.collection('todos').add({
                    'title' : title,
                    'type' : type,
                    'date' : dayDate,
                    'time' : _dayTime,
                    'category' : category,
                    'author' : loggedInUser.uid,
                    //'id' : doc.id
                  
                  });
Run Code Online (Sandbox Code Playgroud)

我不知道如何访问它。而且我将我的任务显示到卡片中,当我长按它们时,我希望它们从 firestore 中删除,但我不能,因为我不知道他们的想法。这是我的空函数:

void deleteTask(){
_firestore.collection("todos").doc().delete();
}
Run Code Online (Sandbox Code Playgroud)

如果您有任何想法,请告诉我。谢谢你们!

dart flutter google-cloud-firestore

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

标签 统计

dart ×2

flutter ×2

google-cloud-firestore ×1