Files
superport/lib/screens/equipment/widgets/custom_dropdown_field.dart
JiWoong Sul e7860ae028
Some checks failed
Flutter Test & Quality Check / Test on macos-latest (push) Has been cancelled
Flutter Test & Quality Check / Test on ubuntu-latest (push) Has been cancelled
Flutter Test & Quality Check / Build APK (push) Has been cancelled
feat: 소프트 딜리트 기능 전면 구현 완료
## 주요 변경사항
- Company, Equipment, License, Warehouse Location 모든 화면에 소프트 딜리트 구현
- 관리자 권한으로 삭제된 데이터 조회 가능 (includeInactive 파라미터)
- 데이터 무결성 보장을 위한 논리 삭제 시스템 완성

## 기능 개선
- 각 리스트 컨트롤러에 toggleIncludeInactive() 메서드 추가
- UI에 "비활성 포함" 체크박스 추가 (관리자 전용)
- API 데이터소스에 includeInactive 파라미터 지원

## 문서 정리
- 불필요한 문서 파일 제거 및 재구성
- CLAUDE.md 프로젝트 상태 업데이트 (진행률 80%)
- 테스트 결과 문서화 (test20250812v01.md)

## UI 컴포넌트
- Equipment 화면 위젯 모듈화 (custom_dropdown_field, equipment_basic_info_section)
- 폼 유효성 검증 강화

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-12 20:02:54 +09:00

178 lines
5.5 KiB
Dart

import 'package:flutter/material.dart';
/// 드롭다운 기능이 있는 재사용 가능한 TextFormField 위젯
class CustomDropdownField extends StatefulWidget {
final String label;
final String hint;
final bool required;
final TextEditingController controller;
final FocusNode focusNode;
final List<String> items;
final Function(String) onChanged;
final Function(String)? onFieldSubmitted;
final String? Function(String)? getAutocompleteSuggestion;
final VoidCallback onDropdownPressed;
final LayerLink layerLink;
final GlobalKey fieldKey;
const CustomDropdownField({
Key? key,
required this.label,
required this.hint,
required this.required,
required this.controller,
required this.focusNode,
required this.items,
required this.onChanged,
this.onFieldSubmitted,
this.getAutocompleteSuggestion,
required this.onDropdownPressed,
required this.layerLink,
required this.fieldKey,
}) : super(key: key);
@override
State<CustomDropdownField> createState() => _CustomDropdownFieldState();
}
class _CustomDropdownFieldState extends State<CustomDropdownField> {
bool _isProgrammaticChange = false;
OverlayEntry? _overlayEntry;
@override
void dispose() {
_removeDropdown();
super.dispose();
}
void _showDropdown() {
_removeDropdown();
final RenderBox renderBox = widget.fieldKey.currentContext!.findRenderObject() as RenderBox;
final size = renderBox.size;
_overlayEntry = OverlayEntry(
builder: (context) => Positioned(
width: size.width,
child: CompositedTransformFollower(
link: widget.layerLink,
showWhenUnlinked: false,
offset: const Offset(0, 45),
child: Material(
elevation: 4,
borderRadius: BorderRadius.circular(4),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.grey.shade300),
borderRadius: BorderRadius.circular(4),
boxShadow: [
BoxShadow(
color: Colors.grey.withValues(alpha: 0.3),
spreadRadius: 1,
blurRadius: 3,
offset: const Offset(0, 1),
),
],
),
constraints: const BoxConstraints(maxHeight: 200),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: widget.items.map((item) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
setState(() {
_isProgrammaticChange = true;
widget.controller.text = item;
});
widget.onChanged(item);
WidgetsBinding.instance.addPostFrameCallback((_) {
_isProgrammaticChange = false;
});
_removeDropdown();
},
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
width: double.infinity,
child: Text(item),
),
);
}).toList(),
),
),
),
),
),
),
);
Overlay.of(context).insert(_overlayEntry!);
}
void _removeDropdown() {
if (_overlayEntry != null) {
_overlayEntry!.remove();
_overlayEntry = null;
}
}
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CompositedTransformTarget(
link: widget.layerLink,
child: TextFormField(
key: widget.fieldKey,
controller: widget.controller,
focusNode: widget.focusNode,
decoration: InputDecoration(
labelText: widget.label,
hintText: widget.hint,
suffixIcon: IconButton(
icon: const Icon(Icons.arrow_drop_down),
onPressed: () {
widget.onDropdownPressed();
_showDropdown();
},
),
),
onChanged: (value) {
if (!_isProgrammaticChange) {
widget.onChanged(value);
}
},
onFieldSubmitted: widget.onFieldSubmitted,
),
),
// 자동완성 후보 표시
if (widget.getAutocompleteSuggestion != null)
Builder(
builder: (context) {
final suggestion = widget.getAutocompleteSuggestion!(widget.controller.text);
if (suggestion != null && suggestion.length > widget.controller.text.length) {
return Padding(
padding: const EdgeInsets.only(left: 12, top: 2),
child: Text(
suggestion,
style: const TextStyle(
color: Color(0xFF1976D2),
fontWeight: FontWeight.bold,
fontSize: 13,
),
),
);
}
return const SizedBox.shrink();
},
),
],
);
}
}