import 'package:flutter/material.dart'; import '../l10n/tr.dart'; import 'theme.dart'; /// 확인 창 하나 (E4 U7, 관리자 승인 10/22). 화면은 내용만 넘긴다. /// /// 약속 /// - 돌려주는 값: [확인] 을 누른 때만 true. [취소] · Esc · 바깥 누르기 · 뒤로는 false. /// - Enter = 첫 초점 단추. 되돌릴 수 없는 일 ([danger] 가 창을 열 때 true) 은 첫 초점이 [취소] (실수 막기), /// 그 밖은 [확인] (관리자 결정 10/22). /// - [danger] 가 창 안에서 바뀌면 (예: "영구 삭제" 체크) [확인] 단추만 빨강으로 바뀐다. 첫 초점은 연 때 그대로. /// - [title] · [body] · [confirmLabel] 은 창 안에서 [set] 으로 다시 그려진다 (체크 상자 등). Future confirmDialog( BuildContext context, { required String Function() title, required Widget Function(BuildContext ctx, StateSetter set) body, required String Function() confirmLabel, String? cancelLabel, bool Function()? danger, Widget? icon, }) async { final dangerAtOpen = danger?.call() ?? false; final ok = await showDialog( context: context, builder: (ctx) => StatefulBuilder( builder: (ctx, set) { final red = danger?.call() ?? false; return AlertDialog( scrollable: true, icon: icon, title: Text(title()), content: body(ctx, set), actions: [ TextButton( autofocus: dangerAtOpen, onPressed: () => Navigator.pop(ctx, false), child: Text(cancelLabel ?? tr('취소')), ), FilledButton( autofocus: !dangerAtOpen, style: red ? FilledButton.styleFrom(backgroundColor: JjColors.alert) : null, onPressed: () => Navigator.pop(ctx, true), child: Text(confirmLabel()), ), ], ); }, ), ); return ok == true; }