【发布时间】:2022-01-10 16:28:43
【问题描述】:
我有这个错误“ [Get] 检测到对 GetX 的不当使用。 您应该只对将要更新的特定小部件使用 GetX 或 Obx。 如果您看到此错误,您可能没有在 GetX/Obx 中插入任何可观察变量 或将它们插入 GetX 认为适合更新的范围之外 (例如:GetX => HeavyWidget => variableObservable)。 如果您需要更新父小部件和子小部件,请将每个小部件包装在 Obx/GetX 中。 "
我有这个页面
import 'package:get/get.dart';
import 'package:spotify_clone/application/themes/theme_config.dart';
import 'package:spotify_clone/modules/home/home_controller.dart';
import 'package:spotify_clone/modules/home/widget/components/page_two_components.dart/search_bar.dart';
import 'package:spotify_clone/modules/home/widget/components/page_two_components.dart/search_custom_delegate.dart';
import 'package:spotify_clone/modules/home/widget/components/page_two_components.dart/section.dart';
class PageTwo extends GetView<HomeController> {
const PageTwo({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
title: Text(
"Buscar",
style: ThemeConfig().getTextStyle(fontSize: 24),
),
)
];
},
body: ListView(
shrinkWrap: true,
children: [
GestureDetector(
onTap: () => showSearch(
context: context,
delegate: SearchCustomDelegate(),
),
child: const SearchBar(),
),
Obx(() => Section(
title: "Navegar por todas seções",
items: controller.allSections,
)),
],
),
),
),
);
}
}
在控制器内部,我声明了“allSections”,例如:
RxList<SectionItemModel> allSections = <SectionItemModel>[].obs;
【问题讨论】:
标签: flutter dart flutter-layout flutter-dependencies flutter-getx