-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserinput.dart
100 lines (95 loc) · 2.87 KB
/
userinput.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
class UserEntry extends StatefulWidget {
final Function adding;
UserEntry(this.adding);
@override
_UserEntryState createState() => _UserEntryState();
}
class _UserEntryState extends State<UserEntry> {
final namecontroller = TextEditingController();
final pricecontroller = TextEditingController();
DateTime? selectedDate;
void PresentDatePicker() {
showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(
2021,
),
lastDate: DateTime.now())
.then((value) {
if (value == null) {
return;
}
setState(() {
selectedDate = value;
});
});
}
@override
Widget build(BuildContext context) {
return Card(
child: Container(
padding: EdgeInsets.all(10),
child: Column(
children: [
TextField(
cursorColor: Colors.green,
decoration: InputDecoration(labelText: 'GAME NAME'),
controller: namecontroller,
),
TextField(
decoration: InputDecoration(
labelText: 'GAME PRICE',
),
controller: pricecontroller,
keyboardType: TextInputType.number,
onSubmitted: (_) {
widget.adding(
namecontroller.text,
double.parse(pricecontroller.text),
selectedDate,
);
},
),
Container(
height: 70,
child: Row(
children: [
Expanded(
child: Text(selectedDate == null
? 'No Date Chosen'
: 'Date: ${DateFormat.yMd().format(selectedDate!)}'),
),
FlatButton(
onPressed: PresentDatePicker,
child: Text(
'choose date',
style: TextStyle(
fontWeight: FontWeight.bold,
),
))
],
),
),
TextButton(
onPressed: () {
if (double.parse(pricecontroller.text) > 0) {
widget.adding(
namecontroller.text,
double.parse(pricecontroller.text),
selectedDate,
);
}
Navigator.of(context).pop();
},
child: Text('Add to list'),
style: TextButton.styleFrom(primary: Colors.deepPurple),
),
],
),
),
);
}
}