4. detail page
import 'package:flutter/material.dart';
import 'home_page.dart'; // Place 클래스 가져오기
class DetailPage extends StatefulWidget {
const DetailPage({super.key});
@override
State<DetailPage> createState() => _DetailPageState();
}
class _DetailPageState extends State<DetailPage> {
late Place place; // 전달받은 장소 객체
final TextEditingController _memoController = TextEditingController();
@override
void didChangeDependencies() {
super.didChangeDependencies();
// arguments로 전달받은 Place 객체 가져오기
final args = ModalRoute.of(context)!.settings.arguments;
if (args != null && args is Place) {
place = args;
_memoController.text = place.memo; // 기존 메모 세팅
}
}
@override
void dispose() {
_memoController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('메모 작성'),
actions: [
IconButton(
icon: const Icon(Icons.save),
onPressed: () {
// 메모 저장
place.memo = _memoController.text.trim();
Navigator.pop(context, place); // 변경된 장소 반환
},
),
],
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
place.name,
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
const SizedBox(height: 4),
Text(
place.address,
style: const TextStyle(color: Colors.grey),
),
const SizedBox(height: 20),
const Text('메모 입력', style: TextStyle(fontSize: 16)),
const SizedBox(height: 8),
TextField(
controller: _memoController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
hintText: '이 장소에 대한 메모를 입력하세요',
),
maxLines: 6,
),
],
),
),
);
}
}
'Programming > Dart+Flutter' 카테고리의 다른 글
[기말고사 대비] 3. search page (0) | 2025.06.11 |
---|---|
[기말고사 대비] 2. home page (0) | 2025.06.11 |
[기말고사 대비] 0. 사전 설정 & 1. main page (0) | 2025.06.11 |
[중간고사 대비] Chapter 4. 플러터 위젯 사용법 (0) | 2025.04.23 |
[중간고사 대비] Chapter 3. 플러터 내부 구조 살펴보기 (0) | 2025.04.23 |