-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCart.dart
144 lines (133 loc) · 4.92 KB
/
Cart.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'infoLibri.dart';
class Cart extends StatefulWidget {
@override
_CartState createState() => _CartState();
}
class _CartState extends State<Cart> {
Icon cusIcon=Icon(Icons.search);
Widget cusSearchBar=Text("Carrello");
final FirebaseAuth auth=FirebaseAuth.instance;
String getCurrentUserId(){
return auth.currentUser.uid;
}
TextEditingController _controller=TextEditingController();
Widget cerca(BuildContext context) {
if(!isSearching) {
return StreamBuilder(
stream: FirebaseFirestore.instance.collection('users').doc(getCurrentUserId()).collection("WishList").snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
return ListView(
children: snapshot.data.docs.map((document) {
return new ListTile(
leading: Image.network(document['copertina']),
title: Text(document['titolo']),
subtitle: Text("Autore: " + document['autore']),
onTap: (){
var docId=document.id;
final FirebaseAuth auth=FirebaseAuth.instance;
final User user=auth.currentUser;
final uid=user.uid;
Navigator.of(context).push(
MaterialPageRoute(builder: (context)=>infoLibro(docId, uid))
);
},
);
}).toList(),
);
}
);}
else {
return StreamBuilder(
stream: FirebaseFirestore.instance.collection('users').doc(getCurrentUserId()).collection("WishList")
.orderBy('titolo')
.where('titolo', isGreaterThanOrEqualTo: _controller.text)
.where('titolo', isLessThan: _controller.text+'z')
.snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
return ListView(
children: snapshot.data.docs.map((document) {
return new ListTile(
leading: Image.network(document['copertina']),
title: Text(document['titolo']),
subtitle: Text("Autore: " + document['autore']),
onTap: (){
var docId=document.id;
final FirebaseAuth auth=FirebaseAuth.instance;
final User user=auth.currentUser;
final uid=user.uid;
Navigator.of(context).push(
MaterialPageRoute(builder: (context)=>infoLibro(docId, uid))
);
},
);
}).toList(),
);
}
);
}
}
bool isSearching=false;
@override
Widget build(BuildContext context) {
return new Scaffold(
backgroundColor: Colors.white,
appBar: new AppBar(
backgroundColor: Color.fromRGBO(77, 49, 71, 10),
actions: <Widget>[
IconButton(
onPressed: (){
setState(() {
if(this.cusIcon.icon==Icons.search){
this.cusIcon=Icon(Icons.cancel);
this.cusSearchBar=new TextField(
controller: _controller,
textInputAction: TextInputAction.go,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Cerca...",
hintStyle: TextStyle(
fontSize: 20.0,
color: Colors.white,
)
),
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
onChanged: (value){
setState(() {
isSearching=true;
});
},
);
}
else{
this.cusIcon=Icon(Icons.search);
this.cusSearchBar=Text("Carrello");
isSearching=false;
_controller.text="";
}
});
},
icon: cusIcon,
)
],
title: cusSearchBar,
),
body: cerca(context),
);
}
}