Implementation
okButtonDidTap(BuildContext context) async {
if (_isSubmitting) return;
_isSubmitting = true;
final String farmId = farmCodeController.text.trim();
final bool result = await ApiService().userJoinFarm(farmId);
if (farmId.isEmpty) {
EventService().eventBus.fire(PopupEvent(
type: PopupType.alert,
action: PopupAction.show,
data: {"title": "농장코드 입력", "content": "올바른 농장코드를 입력하세요."},
onClose: () {
Navigator.of(context, rootNavigator: true).popUntil((route) => !route.settings.name!.startsWith(PopupScreen.routeName));
}));
}
if (result) {
EventService().eventBus.fire(PopupEvent(
type: PopupType.alert,
action: PopupAction.show,
data: {"title": "농장등록성공", "content": "농장이 정상적으로 등록되었습니다."},
onClose: () {
Navigator.of(context, rootNavigator: true).popUntil((route) => !route.settings.name!.startsWith(PopupScreen.routeName));
Navigator.of(context, rootNavigator: true).pushReplacementNamed(FarmLoadingScreen.routeName);
}));
} else {
EventService().eventBus.fire(PopupEvent(
type: PopupType.alert,
action: PopupAction.show,
data: {"title": "농장등록 실패", "content": "농장등록에 실패했습니다."},
onClose: () {
Navigator.of(context, rootNavigator: true).popUntil((route) => !route.settings.name!.startsWith(PopupScreen.routeName));
}));
}
_isSubmitting = false;
}