2 글 보임 - 1 에서 2 까지 (총 2 중에서)
-
글쓴이글
-
2023년 7월 9일 20:11 #90210
김영재참가자import 'package:flutter/material.dart';
void main() { runApp(MaterialApp(home: MyApp())); }
// ignore: must_be_immutable class MyApp extends StatefulWidget { MyApp({super.key});
@override State<MyApp> createState() => _MyAppState(); }
class _MyAppState extends State<MyApp> { var name = ['원숭이', '강아지', '토끼'];
addNew(newContact) { setState(() { name.add(newContact); }); }
@override Widget build(BuildContext context) { return Scaffold( floatingActionButton: FloatingActionButton( child: Icon(Icons.menu), onPressed: () { showDialog( context: context, builder: (context) { return DialogUI(addNew: addNew); }); }, ), appBar: AppBar( title: Text("Contact App"), leading: Icon(Icons.density_medium), actions: [ Icon(Icons.search), SizedBox(width: 15), Icon(Icons.favorite), SizedBox(width: 15), Icon(Icons.home), ], ), body: ListView.builder( itemCount: name.length, itemBuilder: (c, i) { return ListTile( title: Text(name[i]), leading: SizedBox( width: 150, height: 150, child: Image.asset('assets/profile$i.jpg', fit: BoxFit.contain,), )); }), ); } }
class DialogUI extends StatelessWidget { DialogUI({this.addNew, super.key});
final addNew; final inputData = TextEditingController();
@override Widget build(BuildContext context) { return Dialog( child: SizedBox( width: 200, height: 200, child: Column( children: [ Text( "Contact", style: TextStyle(fontSize: 24), ), Container( padding: EdgeInsets.fromLTRB(20, 0, 20, 0), child: TextField( controller: inputData, )), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ TextButton( onPressed: () { addNew(inputData.text); }, child: Text("추가")), TextButton(onPressed: () {}, child: Text("취소")) ], ) ], ), ), ); } }
코드를 이렇게 넣었는데 화면에 강아지 조금 크게 출력됩니다.
픽사베이에서 원본이 이미지까지 똑 같이 다운로드 받았는데 왜 그럴까요?
-
글쓴이글
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
- 답변은 로그인 후 가능합니다.