我正在尝试学习 Flutter 中的复选框。
问题是,当我想在 Scaffold(body:) 中使用复选框时,它正在工作。但我想在不同的地方使用它,比如 ListView 中的一个项目。
return Center(
child: Checkbox(
value: testValue,
onChanged: (bool value) {
setState() {
testValue = value;
}
},
));
Run Code Online (Sandbox Code Playgroud)
但它不起作用,更新和改变任何东西。
编辑:我通过在 StatefulBuilder 中放置复选框解决了我的问题。感谢@cristianbregant
return StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return Center(
child: CheckboxListTile(
title: const Text('Animate Slowly'),
value: _valueCheck,
onChanged: (bool value) {
setState(() {
_valueCheck = value;
});
},
secondary: const Icon(Icons.hourglass_empty),
),
);
});
Run Code Online (Sandbox Code Playgroud) 我的应用程序将文件发送到 ftp 服务器。我通过 MethodChannel 在 Android 上使用 java 发送文件。
这些部分适合在单线程中完成所有工作。但我想发送带有 AsyncTask (java) 和后台的文件。
另外我需要使用 MethodChannel 将文件上传结果发送到 Flutter。
我怎样才能做到这一点?我尝试在 AsyncTask 的 doInBackground 上使用 MethodChannel.Result 但它给了我这个错误:
Caused by: java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: AsyncTask #2
Run Code Online (Sandbox Code Playgroud) 我有一个具有相同对象的列表。
我想通过两个属性对它们进行两种排序
名字(从 a 到 Z)
第二种类型(按升序排列的数字,如 1,2,3...)
void main() {
List<MyObject> list = List();
list.add(MyObject('Apple', 'definition of type #1'));
list.add(MyObject('Strawberry', 'definition of type #8'));
list.add(MyObject('Banana', 'definition of type #2'));
list.add(MyObject('Orange', 'definition of type #3'));
list.add(MyObject('Kiwi', 'definition of type #1'));
list.add(MyObject('Peach', 'definition of type #4'));
list.add(MyObject('Orange', 'definition of type #1'));
list.add(MyObject('Apple', 'definition of type #8'));
list.add(MyObject('Peach', 'definition of type #2'));
list.add(MyObject('Strawberry', 'definition of type #17'));
list.add(MyObject('Peach', 'definition of type #1'));
list.add(MyObject('Banana', 'definition of type #5'));
list.add(MyObject('Apple', 'definition of type #16')); …Run Code Online (Sandbox Code Playgroud)