我最近将我的代码迁移到空安全。在dart迁移命令中得到以下错误。
参数类型为“List<Slots?>?”不能分配给参数类型'List?‘在lib/responsemodels/appointment/calendar/calendar_response.g.dart:17:5
突出显示下面的错误抛出行
calendar_response.dart
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'calendar_response.dart';
// ***********************
我使用颤振http请求从服务器获取数据,并在用户滚动到屏幕底部时加载更多数据。我收到这个错误“未处理的异常:类型'List‘不是’Product‘’的一个子类型”。请帮帮忙,我整天都在挣扎,但没有成功。
model.dart文件
class Product {
final int id;
final String accountName,
callNumber,
whatsappNumber,
businessLocation,
caption;
final List<Images> productPhoto;
在我的问题中,答案要求将List<dynamic>转换为List<String>:
List<String> ls = (json['data'] as List).cast<String>().map((s) => s.toUpperCase()).toList();
我从其他语言中学到的经验让我第一次写到:
List<String> ls = (json['data'] as List<String>).map((s) => s.toUpperCase()).toList()
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:json_annotation/json_annotation.dart';
part 'http.g.dart';
@JsonSerializable()
class Album {
final int userId;
final int id;
final String title;
Album({this.userId, this.id, t
我已经成功地创建了一个应用程序接口,并在一个类对象中对其进行了解析,但是当我尝试在flutter应用程序中获取数据时,我得到了错误nosuchmethoderror the method 'map' was called on null,我真的不知道我做错了什么,谷歌上的所有示例都不起作用
这是输出
Unhandled Exception: NoSuchMethodError: The method 'map' was called on null.
Receiver: null
Tried calling: map(Closure: (dynamic) =&
我有两个模型:book和review。
在book.dart中,我有一个字段来列出与这本书相关的评论(在review.dart中定义)。
class Book {
final String id;
final String bookid;
final String title;
final String author;
final DateTime purchDate;
final String intro;
final List<Review> reviews;
Book(this.id, this.bookid, this.title, thi
我试图添加json支持我的颤振项目,但有一些困难,以使它正确。
我喜欢颤音,但说到json,我想要gson。
我创建了一个小项目来说明我的问题。
请用se
在尝试运行简单的json测试时,错误的类型'Match‘不是类型类型中的'Map’类型的子类型。
很明显,这里有些东西我很怀念!
感谢来自斯德哥尔摩的暴风雨!
import 'package:json_annotation/json_annotation.dart';
part 'json_lab.g.dart';
@JsonSerializable()
class Match {
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import './cart.dart';
class OrderItem {
final String id;
final double amount;
final List<CartItem> products;
final DateTime dateTime;
OrderItem
我使用以下省道包(json_annotation、json_serializable、build_runner)来根据这个序列化/反序列化json。
这是我的密码:
import 'package:json_annotation/json_annotation.dart';
part 'car_type.g.dart';
@JsonSerializable()
class CarType {
final int id;
@JsonKey(name: 'type_label')
final String label;
fi
首先,我对处理HTTP请求和其他东西非常陌生。 我已经用Java Spring创建了一个API,并且我有一堆Fitness程序分配给一个用户,但是当我试图在Flutter中从JSON中获取对象时,就会出现这个错误。我使用http和convert dart包。 List不是类型'Map‘的子类型 问题是这一行: var userModel = Users.fromJson(jsonMap); 这是getUsers方法: Future<Users> getUsers() async{
var client = http.Client();
var user
我有一个想要保存到本地存储的对象,但是每当我将该对象写入存储时,我都会得到标题中显示的错误。
这是完整的堆栈跟踪
[VERBOSE-2:ui_dart_state.cc(198)] Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Map<String, double>' in type cast
#0 new Product.fromJson (package:app/src/objects
当我尝试使用List.firstWhere并将orElse设置为返回null时出错
错误显示:The return type 'Null' isn't a 'City', as required by the closure's context
下面的示例代码
/// city.dart
class City {
final int id;
final String no;
final String name;
final String website;
final bool status;
City(this.id,
我的json序列化有一些问题,我使用json_serializable: ^6.2.0,所以我的代码是:
shift.dart
import 'package:hive/hive.dart';
import 'package:json_annotation/json_annotation.dart';
part 'shift.g.dart';
@HiveType(typeId: 1)
@JsonSerializable()
class Shift extends HiveObject {
@HiveField(0)
final Dat
我是新手,我试着从API中获取数据,但是我得到了错误。
type'_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Iterable<dynamic>'.
我从API中获取新闻数据。我尝试了一下简单API,它成功了,当我尝试一个复杂的API时,在省道代码中做了一些修改,我得到了这个错误。
抱歉,如果我没有正确解释的话。我已经粘贴了用于此API的所有代码。
我找不到任何解决办法。我在这里张贴我的代码。
post.dart
class Post {
我正试着从云中解析JSON,数据收到了,我尝试了很多stackOverflow的解决方案,但都没有用,我只是想熟悉一下颤动和飞镖。 但是我得到了这个错误: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<Category>' 这是我的代码:我收到的JSON数据:{ "totalRowCount":1,"pageSize":100,"categories":{ "Categor