-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class TodoAddPage extends StatefulWidget { | ||
@override | ||
_TodoAddPageState createState() => _TodoAddPageState(); | ||
} | ||
|
||
class _TodoAddPageState extends State<TodoAddPage> { | ||
// 入力されたテキストをデータとして持つ | ||
String _text = ''; | ||
|
||
// データを元に表示するWidget | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text('リスト追加'), | ||
), | ||
body: Container( | ||
// 余白を付ける | ||
padding: EdgeInsets.all(64), | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
// 入力されたテキストを表示 | ||
Text(_text, style: TextStyle(color: Colors.blue)), | ||
const SizedBox(height: 8), | ||
// テキスト入力 | ||
TextField( | ||
// 入力されたテキストの値を受け取る(valueが入力されたテキスト) | ||
onChanged: (String value) { | ||
// データが変更したことを知らせる(画面を更新する) | ||
setState(() { | ||
// データを変更 | ||
_text = value; | ||
}); | ||
}, | ||
), | ||
const SizedBox(height: 8), | ||
Container( | ||
// 横幅いっぱいに広げる | ||
width: double.infinity, | ||
// リスト追加ボタン | ||
child: ElevatedButton( | ||
onPressed: () { | ||
// "pop"で前の画面に戻る | ||
// "pop"の引数から前の画面にデータを渡す | ||
Navigator.of(context).pop(_text); | ||
}, | ||
child: Text('リスト追加', style: TextStyle(color: Colors.white)), | ||
), | ||
), | ||
const SizedBox(height: 8), | ||
Container( | ||
// 横幅いっぱいに広げる | ||
width: double.infinity, | ||
// キャンセルボタン | ||
child: TextButton( | ||
// ボタンをクリックした時の処理 | ||
onPressed: () { | ||
// "pop"で前の画面に戻る | ||
Navigator.of(context).pop(); | ||
}, | ||
child: Text('キャンセル'), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |