-
Notifications
You must be signed in to change notification settings - Fork 2
/
teamPage.dart
173 lines (167 loc) · 6.75 KB
/
teamPage.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'addMember.dart';
import 'memberDetails.dart';
class TeamPage extends StatefulWidget {
@override
_TeamPageState createState() => _TeamPageState();
}
class _TeamPageState extends State<TeamPage> {
final _scaffoldKey = GlobalKey<ScaffoldState>();
Future<bool> _confirmDismiss(DismissDirection direction) async {
return showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text("Do you want to remove this member ?"),
actions: <Widget>[
FlatButton(
child: Text("Yes"),
onPressed: () => Navigator.pop(context, true),
),
FlatButton(
child: Text("No"),
onPressed: () => Navigator.pop(context, false),
),
],
),
) ??
false;
}
void _removeMember(snapshot, index) async {
try {
await Firestore.instance.collection("teams").document(snapshot.data.documents[index].documentID).delete();
_showSnackBar("Team member removed !");
} catch (e) {
_showSnackBar("An error occured in removing team member");
}
}
void _showSnackBar(text) {
_scaffoldKey.currentState.showSnackBar(SnackBar(content: Text(text)));
}
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
body: StreamBuilder(
stream: Firestore.instance.collection("teams").orderBy("id").snapshots(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData) if (snapshot.data.documents.length != 0)
return ListView.builder(
padding: EdgeInsets.symmetric(horizontal: 10.0, vertical: 10.0),
physics: BouncingScrollPhysics(),
itemCount: snapshot.data.documents.length,
itemBuilder: (BuildContext context, int index) {
return Card(
clipBehavior: Clip.hardEdge,
child: Dismissible(
key: Key(snapshot.data.documents[index].documentID),
direction: DismissDirection.endToStart,
background: Container(
padding: EdgeInsets.only(right: 25.0),
alignment: Alignment.centerRight,
color: Colors.red,
child: Icon(
FontAwesomeIcons.userSlash,
size: 20.0,
color: Colors.white,
),
),
confirmDismiss: (direction) => _confirmDismiss(direction),
onDismissed: (direction) => _removeMember(snapshot, index),
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => MemberDetails(
name: snapshot.data.documents[index]["name"],
imgURL: snapshot.data.documents[index]["profileImage"],
instagramLink: snapshot.data.documents[index]["instagram"],
twitterLink: snapshot.data.documents[index]["twitter"],
linkedinLink: snapshot.data.documents[index]["linkedin"],
githubLink: snapshot.data.documents[index]["github"],
orderID: snapshot.data.documents[index]["id"],
team: snapshot.data.documents[index]["team"],
title: snapshot.data.documents[index]["title"],
websiteLink: snapshot.data.documents[index]["website"]),
),
);
},
child: ListTile(
leading: ClipOval(
clipBehavior: Clip.antiAlias,
child: CachedNetworkImage(
width: 55.0,
height: 100.0,
fit: BoxFit.cover,
imageUrl: snapshot.data.documents[index]["profileImage"],
progressIndicatorBuilder: (context, url, downloadProgress) => CircularProgressIndicator(value: downloadProgress.progress),
errorWidget: (context, url, error) => Icon(Icons.error),
),
),
title: Text(
snapshot.data.documents[index]["name"],
style: GoogleFonts.raleway(
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
subtitle: Text(
snapshot.data.documents[index]["title"],
style: GoogleFonts.openSans(
fontSize: 16,
),
),
),
),
),
);
});
else
return Container(
padding: EdgeInsets.only(top: 30),
alignment: Alignment.topCenter,
child: Text(
"Please add Team Members",
style: GoogleFonts.lato(
textStyle: TextStyle(
fontSize: 24,
fontWeight: FontWeight.w300,
),
),
),
);
else
return Center(
child: CircularProgressIndicator(),
);
},
),
floatingActionButton: FloatingActionButton(
tooltip: "Add Member",
child: Icon(Icons.add),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => AddMember(
pageTitle: "Add Member",
title: "",
team: "",
instagram: "",
twitter: "",
linkedin: "",
github: "",
name: "",
website: "",
),
),
);
},
),
);
}
}