我一直在尝试调试此错误类型“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)