小编c49*_*c49的帖子

使用 FutureBuilder 和 Provider 在 Flutter 中没有元素的错误状态

使用Provider和FutureBuilder,我刚刚从数据库中删除了数据,同时它也被删除了,它显示一个红色的屏幕,状态不好,没有元素。添加数据没有问题,不显示这个问题。代码如下

堆栈跟踪

ter (12519): ??? EXCEPTION CAUGHT BY WIDGETS LIBRARY ????????????????????????????????????????????????????????????
I/flutter (12519): The following StateError was thrown building ViewNoteScreen(dirty, dependencies:
I/flutter (12519): [_ModalScopeStatus], state: _ViewNoteScreenState#f589b):
I/flutter (12519): Bad state: No element
I/flutter (12519): 
I/flutter (12519): The relevant error-causing widget was:
I/flutter (12519):   ViewNoteScreen file:///C:/Users/Admin/Desktop/daily%2010/provider_note/lib/main.dart:21:46
I/flutter (12519):
I/flutter (12519): When the exception was thrown, this was the stack:
I/flutter (12519): #0      ListMixin.firstWhere (dart:collection/list.dart:148:5)
I/flutter (12519): #1      Providers.findById (package:provider_note/helper/provider.dart:14:19)
I/flutter (12519): #2      _ViewNoteScreenState.build (package:provider_note/screens/view_note.dart:21:35)
I/flutter (12519): #3      StatefulElement.build (package:flutter/src/widgets/framework.dart:4663:28)
I/flutter (12519): …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-provider flutter-futurebuilder

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

单身人士如何在 Dart 中工作?

我是 Dart 和 Flutter 的新手。当我在学习教程时,我了解到我们可以使用 factory 关键字来制作单例。但在那之后,我得到了这个代码。

class AccountService {
  static final _instance = AccountService._internal();

  AccountService._internal();

  static AccountService getInstance() {
    return _instance;
  }
}
Run Code Online (Sandbox Code Playgroud)

我的问题。

  1. 代码如何工作?
  2. 什么时候getInstance()打电话?
  3. AccountService._internal()构造函数?
  4. static final _instance = AccountService._internal(); - 这什么时候被调用?

请帮我

singleton dart

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