I have this error " [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. "
I have this page
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,
)),
],
),
),
),
);
}
}
Inside controller i declared "allSections" like:
RxList<SectionItemModel> allSections = <SectionItemModel>[].obs;
CodePudding user response:
Obx() is used only when there is an extended class of GetxController inside. I can only see HomeController. But I can't see where you initialized controller inside PageTwo.
CodePudding user response:
import 'package:flutter/material.dart';
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 GetMaterialApp(
home: 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,
)),
],
),
),
),
),
);
}
}
Inside controller i declared "allSectio
