使用 BLoC 库时,我们将所有变量存储在状态类中。但是在哪里存储 TextEditingController,它不会改变,但它的值会改变?
假设我有一个像这样的状态类(仅作为示例):
@freezed
abstract class EditItemState with _$EditItemState {
const factory EditItemState.updated({
TextEditingController titleController,
ShoppingItem shoppingItem,
}) = _ShoppingListLoaded;
}
Run Code Online (Sandbox Code Playgroud)
和肘级:
class EditItemCubit extends Cubit<EditItemState> {
EditItemCubit() : super(EditItemState.updated());
Future<void> titleUpdated() async {
emit(
EditItemState.updated().copyWith(
shoppingItem: state.shoppingItem.copyWith(
title: state.titleController.text,
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
所以Cubit类逻辑看起来很混乱。我建议将此类控制器直接保留在小部件或 BLoC/Cubit 类中。这是正确的做法吗?
想象一下,在正确设置 analysis_options.yaml 文件后,您有一个包含数千条 lint 警告的项目。现在你需要解决所有的混乱。手动完成这一切可能会花费您很多时间,而大多数问题都非常简单,例如“var”而不是“final”,双引号而不是单引号等。
有什么方法可以让 Android Studio在终端中或通过运行任何特定命令自动修复所有最简单的 lint 警告,例如“使用常量构造函数首选常量”等?
如何根据Dart中的if语句声明变量?在 Kotlin 中,它看起来像这样:
val max = if (a > b) {
a
} else {
b
}
Run Code Online (Sandbox Code Playgroud)
在 Dart 中甚至有可能吗?