// ✍️ 커뮤니티 게시판 - 글쓰기 화면 (UI 전용). // 서버 통신/상태는 lib/function/board_write_controller.dart가 담당한다. import 'package:flutter/material.dart'; import '../function/board_write_controller.dart'; import '../theme/app_palette.dart'; import 'app_notice.dart'; import 'title_pill.dart'; class BoardWriteScreen extends StatefulWidget { final String studentId; final String category; final String categoryName; const BoardWriteScreen({ super.key, required this.studentId, required this.category, required this.categoryName, }); @override State createState() => _BoardWriteScreenState(); } class _BoardWriteScreenState extends State { late final BoardWriteController _controller; final _titleController = TextEditingController(); final _contentController = TextEditingController(); @override void initState() { super.initState(); _controller = BoardWriteController(studentId: widget.studentId); } @override void dispose() { _controller.dispose(); _titleController.dispose(); _contentController.dispose(); super.dispose(); } Future _submit() async { final (success, message) = await _controller.submit( category: widget.category, title: _titleController.text, content: _contentController.text, ); if (!mounted) return; AppNotice.show( context, message, icon: success ? Icons.check_circle_rounded : Icons.error_outline_rounded, ); if (success) Navigator.of(context).pop(true); } @override Widget build(BuildContext context) { return ListenableBuilder( listenable: _controller, builder: (context, _) { return Scaffold( backgroundColor: AppPalette.mist, appBar: AppBar( backgroundColor: Colors.transparent, foregroundColor: AppPalette.ink, elevation: 0, centerTitle: true, title: TitlePill('${widget.categoryName} 글쓰기'), actions: [ TextButton( onPressed: _controller.isSubmitting ? null : _submit, child: _controller.isSubmitting ? const SizedBox( width: 18, height: 18, child: CircularProgressIndicator(strokeWidth: 2), ) : const Text( '등록', style: TextStyle( color: AppPalette.ink, fontWeight: FontWeight.bold, ), ), ), ], ), body: SingleChildScrollView( padding: const EdgeInsets.all(20), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ const Padding( padding: EdgeInsets.only(bottom: 4, left: 4), child: Text( '글쓴이는 익명으로 표시됩니다.', style: TextStyle(color: Colors.grey, fontSize: 12.5), ), ), const SizedBox(height: 8), TextField( controller: _titleController, maxLength: 100, decoration: InputDecoration( hintText: '제목', filled: true, fillColor: AppPalette.paper, border: OutlineInputBorder( borderRadius: BorderRadius.circular(14), borderSide: BorderSide(color: AppPalette.sage), ), ), ), TextField( controller: _contentController, maxLines: 12, minLines: 8, decoration: InputDecoration( hintText: '내용을 입력하세요', filled: true, fillColor: AppPalette.paper, border: OutlineInputBorder( borderRadius: BorderRadius.circular(14), borderSide: BorderSide(color: AppPalette.sage), ), ), ), ], ), ), ); }, ); } }