下面是一个最小的应用程序,展示了我的担忧。如果运行它,您将看到每个可见项的构建方法都会运行,即使只有一项的数据发生了更改。
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyList extends StatelessWidget {
final List<int> items;
MyList(this.items);
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
print("item $index built");
return ListTile(
title: Text('${items[index]}'),
);
});
}
}
class MyApp extends StatefulWidget {
MyApp({Key? key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
List<int> items = List<int>.generate(10000, (i) => i);
void _incrementItem2() {
setState(() {
this.items[1]++;
});
}
@override …Run Code Online (Sandbox Code Playgroud) 我的机器上的swift版本是5.0.1。该项目的 swift 版本是 4.0。
我的Xcode版本是10.4
我是carthage bootstrap --platform ios在根目录下运行的。
*** Checking out CocoaAsyncSocket at "7.6.3"
*** Checking out papertraillumberjack at "0.1.8"
*** Checking out AFNetworking at "3.2.1"
*** Checking out fmdb at "2.6"
*** Checking out objective-c at "v4.8.1"
*** Checking out CocoaLumberjack at "3.4.2"
*** xcodebuild output can be found in /var/folders/7m/bb7zj_yj0_zfgjvv3lgntr040000gn/T/carthage-xcodebuild.wjVbNA.log
*** Downloading CocoaAsyncSocket.framework binary at "Version 7.6.3"
*** Building scheme "AFNetworking iOS" in AFNetworking.xcworkspace
*** Building scheme "CocoaLumberjack-iOS" in Lumberjack.xcworkspace
*** Building scheme "CocoaLumberjackSwift-iOS" in …Run Code Online (Sandbox Code Playgroud) 这里是 Riverpod 的新手。(使用 Flutter 和 hooks_riverpod,顺便说一句)。
使用 Hive 存储相关的项目列表。我需要调用Hive.initFlutter并等待 Hive 初始化,并在我的应用程序加载时执行相同的操作来打开配置单元框。之后,对 Hive 的调用是同步的。
我最初的想法(尽管我愿意接受更好的想法)是创建一个包含两个列表的 StateNotifier。该通知程序可以有一个异步的 setUp 函数。简化后的样子如下:
class ItemsNotifier extends StateNotifier<ItemsState> {
ItemsNotifier() : super(ItemsState([], []));
setUp() async {
await Hive.initFlutter();
// What is ItemDao? It's a data accessor object singleton used to house Hive logic.
await ItemDao().openBoxes();
// Putting a breakpoint here, I can see by calling `ItemDao().list1` etc that the lists have loaded with items as expected, but setting state here does not trigger a rebuild …Run Code Online (Sandbox Code Playgroud) 就在我提交之前,我已经通过使用git ..(我在一个子目录中)暂存了我的所有更改,并且我已经运行 git status 来查看暂存的更改。正如预期的那样,此时 Git 仅暂存了更改的文件。
在命令行中,我运行git commit一条消息,得到以下响应:
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
[SelectingDate 910641c4] Switching from many visibility animators to one translate animated view. Cuts down time to update list significantly.
7 files changed, 43 insertions(+), 15 deletions(-)
rename mobile/features/itemLists/CursorItemsCoordinator/{AnimatedVisibilityCursor.native.js => AnimatedTranslatingCursor.native.js} (52%)
Run Code Online (Sandbox Code Playgroud)
不习惯看到自动打包消息,但我发现其他文章可以帮助我摆脱它。尽管如此,根据他的 cl 回应,似乎已经做出了更改。
然后我立即运行git status,令我惊讶的是,这是响应:
On branch SelectingDate
No commits yet
Run Code Online (Sandbox Code Playgroud)
然后它列出了我的存储库中的所有文件作为暂存。
我的 repo 中的文件似乎已更新为当前版本,这很好。有谁知道可能发生了什么会从我当前的分支中删除所有提交/如何将它们取回(如果可能)?
这是完整的命令行交互:
? mobile …Run Code Online (Sandbox Code Playgroud) 在 Dart 中是否可以像在 TypeScript 中那样拥有恰好两种类型的列表?例如,这样的东西会编译:
List<int|String> foo = [
1,2,3,4,'baz'
];
Run Code Online (Sandbox Code Playgroud)
虽然这不会:
List<int|String> foo = [
1,2,false,4,'baz',[],3.0
];
Run Code Online (Sandbox Code Playgroud)