
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
선생님께서는
category = dataList[index]['category'];
imgUrl = dataList[index]['imgUrl'];
이렇게 변수에 담아서 쓰셨는데 저는 그냥 datList[index][category'] 를 썼거든요
선생님처럼 변수로 빼는게 더 좋은 코드인가요? 더 좋다면 이유를 알고 싶습니다.
(제 코드의 97번째 줄쯤에 있을 겁니다.)
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
List<Map<String, dynamic>> dataList = [
{
"category": "탑건: 매버릭",
"imgUrl": "https://i.ibb.co/sR32PN3/topgun.jpg",
},
{
"category": "마녀2",
"imgUrl": "https://i.ibb.co/CKMrv91/The-Witch.jpg",
},
{
"category": "범죄도시2",
"imgUrl": "https://i.ibb.co/2czdVdm/The-Outlaws.jpg",
},
{
"category": "헤어질 결심",
"imgUrl": "https://i.ibb.co/gM394CV/Decision-to-Leave.jpg",
},
{
"category": "브로커",
"imgUrl": "https://i.ibb.co/MSy1XNB/broker.jpg",
},
{
"category": "문폴",
"imgUrl": "https://i.ibb.co/4JYHHtc/Moonfall.jpg",
},
];
return Scaffold(
appBar: AppBar(
elevation: 0,
backgroundColor: Colors.white,
title: Text(
'Movie Reviews',
style: TextStyle(color: Colors.black, fontSize: 30),
),
actions: [
IconButton(
onPressed: () {},
icon: Icon(
Icons.person_outline,
color: Colors.black,
))
],
),
body: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
decoration: InputDecoration(
suffixIcon: Icon(Icons.search),
enabledBorder: OutlineInputBorder(),
hintText: '영화 제목을 검색해주세요.'),
),
),
Divider(
height: 1,
),
Expanded(
child: Card(
child: ListView.builder(
itemCount: dataList.length,
itemBuilder: (BuildContext ctx, int idx) {
// return을 안써줘서 계속 화면에 안나왔던 거였다...!!!
return Column(
children: [
Stack(
alignment: Alignment.center,
children: [
Image.network(
aList[idx] dat['imgUrl'],
//color, colorBlendMode 이용해 사진 불투명하게 만듦
color: Colors.grey,
colorBlendMode: BlendMode.modulate,
// 사진 크기조절로 애좀 먹음
// height, width, fit을 이용해서 사진 크기 조절함!!
height: 200,
width: double.infinity,
fit: BoxFit.cover,
),
Text(
dataList[idx]['category'],
style: TextStyle(
color: Colors.white,
fontSize: 35,
),
),
],
),
SizedBox(height: 10),
],
);
},
),
),
),
],
),
);
}
}
