생김새

코드
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(home: MyApp()));
}
class MyApp extends StatefulWidget {
MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
var name = ['닭강정', '마라샹궈', '소불고기'];
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () {
showDialog(
context: context,
builder: (context) {
return Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.zero),
child: Homework(),
);
},
);
},
),
appBar: AppBar(),
body: ListView.builder(
itemCount: 3,
itemBuilder: (context, i) {
return ListTile(
leading: Image.asset('grape.png'),
title: Text(name[i]),
);
},
),
);
}
}
class Homework extends StatelessWidget {
const Homework({super.key});
@override
Widget build(BuildContext context) {
return SizedBox(
width: 300,
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
spacing: 15,
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Contact',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
TextField(),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: Navigator.of(context).pop,
child: Text('Cancel'),
),
TextButton(
onPressed: Navigator.of(context).pop,
child: Text('OK'),
),
],
),
],
),
),
);
}
}
모범답안
class DialogUI extends StatelessWidget {
DialogUI({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Dialog(
child: Container(
width: 300,
height: 300,
child: Column(
children: [
TextField(),
TextButton( child: Text('완료'), onPressed:(){} ),
TextButton(
child: Text('취소'),
onPressed:(){ Navigator.pop(context); })
],
),
),
);
}
}