diff --git a/lib/page/shelfdetailpage.dart b/lib/page/shelfdetailpage.dart index 372fec4..8426745 100644 --- a/lib/page/shelfdetailpage.dart +++ b/lib/page/shelfdetailpage.dart @@ -19,16 +19,53 @@ class _ShelfDetailPageState extends State { ListModel _bookList; dynamic selectedItem; - void _addBook() { - - dynamic element = "new book"; - int index = selectedItem == null ? _bookList.length : _bookList.indexOf(selectedItem); + void _addBook() async { + dynamic newBook = await _asyncInputDialog(context); + print("New book name is $newBook"); + int index = selectedItem == null + ? _bookList.length + : _bookList.indexOf(selectedItem); setState(() { - _bookList.insert(index, element); + _bookList.insert(index, newBook); }); print(_bookList.length); } + Future _asyncInputDialog(BuildContext context) async { + String bookName = ''; + return showDialog( + context: context, + barrierDismissible: + false, // dialog is dismissible with a tap on the barrier + builder: (BuildContext context) { + return AlertDialog( + title: Text('책 추가'), + content: new Row( + children: [ + new Expanded( + child: new TextField( + autofocus: true, + decoration: new InputDecoration( + labelText: '이름', hintText: 'eg. 나의 아름다운 정원'), + onChanged: (value) { + bookName = value; + }, + )) + ], + ), + actions: [ + FlatButton( + child: Text('Ok'), + onPressed: () { + Navigator.of(context).pop(bookName); + }, + ), + ], + ); + }, + ); + } + @override void initState() { super.initState();