我想将一个带有参数的函数分配给一个已经声明的变量,这样我就可以稍后执行它。
像这样的东西:
void main() {
Function p;
p = print('1'); // should not execute;
p;
}
Run Code Online (Sandbox Code Playgroud)
我怎么做?是否可以?
每当我尝试将图片上传到 Google Ads(应用广告系列)时,我都会收到:
\n\n\n\n现在可以\xe2\x80\x99 上传此文件。稍后再试。
\n
我等了几个小时并再次尝试,但仍然不起作用。我的图像代表了要求。
\n为什么会发生这种情况?
\n每当我尝试在小部件上使用“换行”选项(Windows 上的 Alt + Enter / macOS 上的 Option + Enter)时,我都会收到可以使用的可用换行小部件的有限列表(所有这些都与flutter_bloc 包)。
我希望获得完整的默认颤振列表,如下所示:
我应该怎么办?
我正在使用冻结的包来生成数据类。
该包支持使用注释禁用 copyWith 生成@Freezed(copyWith: false)。
我想对我的冻结数据类实现自定义copyWith。这是我的代码:
@Freezed(copyWith: false)
class AuthenticationState with _$AuthenticationState {
const factory AuthenticationState({
String? userId,
ErrorObject? errorObject,
}) = _AuthenticationState;
AuthenticationState copyWith({
String? userId,
ErrorObject? errorObject,
}) {
return AuthenticationState(
userId: userId ?? this.userId,
errorObject: errorObject, // resets if not provided
);
}
}
Run Code Online (Sandbox Code Playgroud)
I 代运行成功并且没有静态分析错误。
但是当我运行该应用程序时,我收到此错误:
authentication_bloc.freezed.dart:32:7:错误:非抽象类“_$_AuthenticationState”缺少这些成员的实现:
- AuthenticationState.copyWith 尝试任一
- 提供一个实现,
- 从超类或 mixin 继承实现,
- 将类标记为抽象类,或者
- 提供“noSuchMethod”实现。
类 __$_AuthenticationState 实现 _AuthenticationState { ^^^^^^^^^^^^^^^^^^^^^^lib/authentication/bloc/authentication_state.dart:28:23:上下文:'AuthenticationState.copyWith'在这里定义。
问题是什么?如何copyWith在冻结类中实现自定义?