-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_new_item_screen.dart
120 lines (109 loc) · 3.72 KB
/
add_new_item_screen.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:list/components/TextFieldAdd.dart';
final _firestore = Firestore.instance;
FirebaseUser loggedinUser;
class Addnewitem extends StatefulWidget {
@override
_AddnewitemState createState() => _AddnewitemState();
}
class _AddnewitemState extends State<Addnewitem> {
TextEditingController _textInputController1 = TextEditingController();
TextEditingController _textInputController2 = TextEditingController();
String item;
String quant;
String email;
void initState() {
super.initState();
getCurrentUser();
}
final _auth = FirebaseAuth.instance;
void getCurrentUser() async {
try {
final user = await _auth.currentUser();
if (user != null) {
loggedinUser = user;
// print(loggedinUser.email);
}
} catch (e) {
print(e);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Add Items"),
leading: IconButton(
icon: Icon(Icons.arrow_back_ios),
onPressed: () {
Navigator.pop(context);
}),
),
body: Center(
child: Container(
width: 300,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
TextFieldAddPage(
text: "item",
controlling: _textInputController1,
onchanged: (value) {
item = value;
}),
SizedBox(
height: 20,
),
TextFieldAddPage(
text: "Quantity",
controlling: _textInputController2,
onchanged: (value) {
quant = value;
}),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
color: Colors.tealAccent,
child: Text(
"Submit",
style: TextStyle(color: Colors.black),
),
onPressed: () {
DocumentReference new_item = _firestore
.collection('users')
.document(loggedinUser.uid)
.collection('items')
.document();
new_item.setData({
'email': loggedinUser.email,
'item': item,
'quant': quant,
});
_textInputController1.clear();
_textInputController2.clear();
}),
SizedBox(
width: 10,
),
RaisedButton(
color: Colors.tealAccent,
child: Text("Cancel",
style: TextStyle(color: Colors.black)),
onPressed: () {
Navigator.pop(context);
},
)
],
)
],
)),
));
}
}