class Resource { final T? data; final bool isLoading; final Exception? error; Resource({this.data, this.isLoading = false, this.error}); static const _unset = Object(); Resource copyWith({T? data, bool? isLoading, Object? error = _unset}) { return Resource( data: data ?? this.data, isLoading: isLoading ?? this.isLoading, // Distinguish "not provided" from an explicit null to allow clearing error. error: error == _unset ? this.error : error as Exception?, ); } }