import 'package:flutter/cupertino.dart'; import 'package:get/get.dart'; import 'package:isekai_wiki/reactive/reactive.dart'; class StateTestController extends GetxController { var count = 0.obs; @override void onInit() { debugPrint("StateTestController onInit"); super.onInit(); } void updateState({required int count}) { debugPrint("StateTestController updateState"); this.count.value = count; } } class StateTest extends StatefulWidget { final VoidCallback? onPressed; final int count; const StateTest({super.key, this.onPressed, required this.count}); @override State createState() { return StateTestState(); } } class StateTestState extends ReactiveState { StateTestController c = StateTestController(); @override void initState() { super.initState(); Get.put(c); } @override void receiveProps() { c.updateState(count: widget.count); } @override Widget render(BuildContext context) { return Column(children: [ Center( child: Obx( () => Text(c.count.value.toString()), ), ), CupertinoButton.filled( child: const Text("增加"), onPressed: () { widget.onPressed?.call(); }), ]); } }