Open tazik561 opened 2 years ago
@tazik561 when you are using GetView
class MateMapScreen extends GetView<MateMapController> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(19),
child: Column(
children: [
SizedBox(
height: 12,
),
Container(
height: 60,
child: Row(
children: [ Text(controller.count.value);
]
},
),
],
),
),
I can see your are trying to execute
Get.find<MateMapController>().start(),
Do not know your use case, but try to call it on init
class MateMapController extends GetxController{
final int count= 0.obs;
@override
void onInit() {
start();
super.onInit();
}
void start(){
count.value = 1;
}
....
Something I recommend is to generate the app_routes class. As you can specify the bindings, when a Widget is using a controller. That will ensure all necessary ctrls are up before hand, executed, run and close automatically.
GetPage(
name: Routes.NAME,
page: () => TargetPage(),
binding: TargetBinding(),
fullscreenDialog: true)
Then simple call:
Get.toNamed(Routes.NAME);
GetX<MateMapController>(
GetX need a reactive variable, swap it to GetBuilder it you will not to use reactive variables.
init: controller,
remove this
initState: (_) => Get.find<MateMapController>().start(),
You dont need this, call start function on onInit of MateMapController.
I am trying to use GETX on my project. After installing getx lib and changing materialapp to
GetMaterialApp
:I made a binding class for one of my pages:
I have a page called
MateMapScreen
and byGet.to
I move to this page:In MateMapScreen page I am trying to use
GetX
like this:The problem is here! when
MateMapScreen
is started I got error:but when I press ctrl + s (hot reload), the error is gone and red color container is appeared . What is my mistake?