小编TEZ*_*EZZ的帖子

如何解决错误“类型‘Null’不是类型转换中类型‘String’的子类型”

我一直在尝试调试此错误类型“Null”不是类型转换中“String”类型的子类型,但无法找到产生错误的确切位置,除了触发 POST API 调用时生成错误之外。

店铺等级

import 'package:freezed_annotation/freezed_annotation.dart';
part 'shop.freezed.dart';
part 'shop.g.dart';

@freezed
class Shop with _$Shop {
  factory Shop({
      String? id,
      @JsonKey(name: 'shopNumber')String? number,
      @JsonKey(name: 'created') String? createdAt,
      @JsonKey(name: 'updated') String? updatedAt,
      int? calendar}) = _Shop;

  factory Shop.fromJson(Map<String, dynamic> json) => _$ShopFromJson(json);

  static Shop fromJsonModel(Map<String, dynamic> json) => Shop.fromJson(json);
}
Run Code Online (Sandbox Code Playgroud)

后期功能-创建店铺

Future<void> postShop() async {
    Shop shop;
    
    shop = await shopSvc.create(Shop(calendar: widget.calendar?.id, number: _shopNumber));

        var newCalendar = widget.calendar?.copyWith(shop: shop);
        Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => ShopInfoScreen(calendar: newCalendar!)));
      }
    } catch …
Run Code Online (Sandbox Code Playgroud)

http dart flutter dart-null-safety

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

标签 统计

dart ×1

dart-null-safety ×1

flutter ×1

http ×1