无法使用getx颤动来发起列表
我有一个列表,我想通过从数据库中获取数据来启动它。出现此错误消息
[GET]已检测到GetX的不当使用。 您只能将GETX或OBX用于将要更新的特定小部件。 如果您看到此错误,您可能没有将任何可观察的变量插入GetX/obx 或将它们插入getx认为适合更新的范围之外 (示例:getx => heidewidget => variable observable)。 如果您需要更新父窗口小部件和子小部件,请将每个小部件包装在OBX/GETX中。
class PasswordController extends GetxController {
final passwordsList = <Password>[].obs;
final db = Dao.instance;
Future<void> initilizePasswordsList() async {
final passwords = await db.getAllPasswords();
passwordsList.addAll([...passwords]);
return;
}
}
Future<void> main() async {
final passwordController = Get.put(PasswordController());
await passwordController.initilizePasswordsList();
runApp(const MyApp());
}
const PasswordsList({super.key});
@override
Widget build(BuildContext context) {
return GetX<PasswordController>(
builder: (controller) {
return ListView(
children: controller.passwordsList
.map((e) => Obx(
() => PasswordTile(
password: e.password,
websiteName: e.websiteName,
),
))
.toList(),
);
},
);
}
}
I have a list and I want to initilize it by getting the data from the database. and this error message appears
[Get] the improper use of a GetX has been detected.
You should only use GetX or Obx for the specific widget that will be updated.
If you are seeing this error, you probably did not insert any observable variables into GetX/Obx
or insert them outside the scope that GetX considers suitable for an update
(example: GetX => HeavyWidget => variableObservable).
If you need to update a parent widget and a child widget, wrap each one in an Obx/GetX.
class PasswordController extends GetxController {
final passwordsList = <Password>[].obs;
final db = Dao.instance;
Future<void> initilizePasswordsList() async {
final passwords = await db.getAllPasswords();
passwordsList.addAll([...passwords]);
return;
}
}
Future<void> main() async {
final passwordController = Get.put(PasswordController());
await passwordController.initilizePasswordsList();
runApp(const MyApp());
}
const PasswordsList({super.key});
@override
Widget build(BuildContext context) {
return GetX<PasswordController>(
builder: (controller) {
return ListView(
children: controller.passwordsList
.map((e) => Obx(
() => PasswordTile(
password: e.password,
websiteName: e.websiteName,
),
))
.toList(),
);
},
);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
listView
中删除obx
e 是不可观察的,password> passwordlist
是。您已经在使用getx
观察它。因此,您的listView
应该看起来像:Remove the
Obx
inside theListView
ase
is not observable,passwordList
is. And you are already observing it withGetX
. Therefore yourListView
should look like: