CounterBinding:
class CounterBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut(() => CounterController());
}
}
CounterController:
class CounterController extends GetxController {
int count = 0;
void increase(){
count += 1;
update();
}
}
CounterPage:
class CounterPage extends StatelessWidget {
final controller = Get.find<CounterController>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Counter"),
),
body: Center(
child: GetBuilder<CounterController>(builder: (logic) {
return Text("${controller.count}", style: const TextStyle(fontSize: 50),);
}),
),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.add),
onPressed: controller.increase,
),
);
}
}
标签:count,const,class,getx,controller,getbuilder,extends,方法,CounterController
From: https://www.cnblogs.com/wufong/p/17969164