1
1
import 'package:flutter/material.dart' ;
2
2
3
- void main () => runApp (MaterialApp (home: UserInput ()));
3
+ void main () => runApp (MaterialApp (home: ToDo ()));
4
4
5
- class UserInput extends StatefulWidget {
5
+ ////////////////////////////////
6
+ class ToDo extends StatefulWidget {
6
7
@override
7
- _UserInputState createState () => _UserInputState ();
8
+ _ToDoState createState () => _ToDoState ();
8
9
}
9
10
10
- class _UserInputState extends State <UserInput > {
11
- void updateUserText (String text) {
11
+ class _ToDoState extends State <ToDo > {
12
+ List <String > products = ['Tomate' , 'Käse' , 'Lauch' , 'Paprika' , 'Wein' ];
13
+
14
+ void addItem (String item) {
12
15
setState (() {
13
- userText = text ;
16
+ products. add (item) ;
14
17
});
18
+ Navigator .of (context).pop ();
15
19
}
16
20
17
- String userText = '' ;
21
+ void newEntry (){
22
+ showDialog <AlertDialog >(
23
+ context: context,
24
+ builder: (BuildContext context){
25
+ return AlertDialog (
26
+ content: TextField (
27
+ onSubmitted: addItem,
28
+ )
29
+ );
30
+ }
31
+ );
32
+ }
18
33
19
34
@override
20
35
Widget build (BuildContext context) {
21
- return Column (
22
- children : < Widget > [
23
- TextField (
24
- onChanged : updateUserText ,
36
+ return Scaffold (
37
+ appBar : AppBar (
38
+ title : Text ( 'To-Do-App' ),
39
+ backgroundColor : Color . fromRGBO ( 35 , 0 , 0 , 100 ) ,
25
40
),
26
- Text (userText),
27
- ],
28
-
41
+ body: ListView .builder (
42
+ itemCount: products.length,
43
+ itemBuilder: (context, i) {
44
+ return ToDoItem (products[i]);
45
+ },
46
+ ),
47
+ floatingActionButton: FloatingActionButton (
48
+ onPressed: newEntry,
49
+ child: Icon (Icons .add),
50
+ )
29
51
);
30
52
}
31
53
}
32
54
55
+ class ToDoItem extends StatelessWidget {
56
+ final String title;
57
+
58
+ const ToDoItem (this .title);
59
+
60
+ @override
61
+ Widget build (BuildContext context) {
62
+ return Container (
63
+ color: Colors .white,
64
+ padding: EdgeInsets .symmetric (horizontal: 22 ),
65
+ child: ListTile (
66
+ contentPadding: EdgeInsets .symmetric (vertical: 8 ),
67
+ leading: Checkbox (
68
+ value: false ,
69
+ ),
70
+ title: Text (
71
+ title,
72
+ style: TextStyle (
73
+ fontSize: 18.0 ,
74
+ fontWeight: FontWeight .w600,
75
+ color: Colors .black54),
76
+ ),
77
+ trailing: Icon (Icons .delete_outline),
78
+ ),
79
+ );
80
+ }
81
+ }
0 commit comments