Skip to content

Commit

Permalink
책 추가 버튼 클릭하면 다이얼로그로 데이터 입력받게 만듬
Browse files Browse the repository at this point in the history
  • Loading branch information
kangsudal committed Nov 9, 2019
1 parent d0f2bb3 commit 610b7d3
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions lib/page/shelfdetailpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,53 @@ class _ShelfDetailPageState extends State<ShelfDetailPage> {
ListModel<dynamic> _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<String> _asyncInputDialog(BuildContext context) async {
String bookName = '';
return showDialog<String>(
context: context,
barrierDismissible:
false, // dialog is dismissible with a tap on the barrier
builder: (BuildContext context) {
return AlertDialog(
title: Text('책 추가'),
content: new Row(
children: <Widget>[
new Expanded(
child: new TextField(
autofocus: true,
decoration: new InputDecoration(
labelText: '이름', hintText: 'eg. 나의 아름다운 정원'),
onChanged: (value) {
bookName = value;
},
))
],
),
actions: <Widget>[
FlatButton(
child: Text('Ok'),
onPressed: () {
Navigator.of(context).pop(bookName);
},
),
],
);
},
);
}

@override
void initState() {
super.initState();
Expand Down

0 comments on commit 610b7d3

Please sign in to comment.