You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.3 KiB
Dart

2 years ago
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<StatefulWidget> createState() {
return StateTestState();
}
}
class StateTestState extends ReactiveState<StateTest> {
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();
}),
]);
}
}