You are on page 1of 13

import 'package:cloud_firestore/cloud_firestore.

dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:signup/comments.dart';
import 'package:signup/models/user.dart';
import 'package:signup/states/currentUser.dart';

//finalusersRef =Firestore.instance.collection('users');
class MyProfileFinal extends StatefulWidget {
//final OurUser userData;
//final String data;
static const routeName = '/myProfileFinal';
String uid;

MyProfileFinal({this.uid});

// String title;
// String age;
// String location;
// String description;

String image;

//const MyProfileFinal({Key key, this.userData}) : super(key: key);

//const MyProfileFinal({Key key, this.ourUser}) : super(key: key);

//const MyProfileFinal({Key key, this.ourUser}) : super(key: key);


//const MyProfileFinal({Key key, this.data}) : super(key: key);
@override
_MyProfileStateFinal createState() => _MyProfileStateFinal(
uid: this.uid,
);
}

class _MyProfileStateFinal extends State<MyProfileFinal> {


final reviewKey = GlobalKey<ScaffoldState>();

//final String _fullName = "Ali Qureshi";


//final String data;
//final String _status = "Property Dealer";
String uid;

//String image;
final String _listings = "Listings";

//final String _bio ="\"Hi, I am a Property Dealer.If you need property suitbale
for your needs. You can contact me.\"";

//int _rating = 0;
final FirebaseAuth _auth = FirebaseAuth.instance;
bool isAdmin = true;

_MyProfileStateFinal({this.uid});

//bool isAdmin = false;


Future<FirebaseUser> getUser() {
return _auth.currentUser();
}

FirebaseUser user;

@override
void initState() {
super.initState();
CurrentUser _current = Provider.of<CurrentUser>(context, listen: false);
//OurUser _currents = Provider.of<OurUser>(context,listen: false);
//
_current.updateStateFromDatabase(_current.getCurrentUser.uid,_current.getCurrentUse
r.displayName);
//print('Value1${_current.getCurrentUser.uid}');
//print('Value2$user.');
//print('${data}');
initUser();
}

initUser() async {
user = await _auth.currentUser();
setState(() {});
}

// void rate(int rating) {


// //Other actions based on rating such as api calls.
// setState(() {
// _rating = rating;
// });
// }

@override
Widget build(BuildContext context) {
WidgetsBinding.instance.addPostFrameCallback((_) => _showContact(context));

// Size screenSize = MediaQuery.of(context.size;


final data = ModalRoute.of(context).settings.arguments as String;
// CurrentUser _current = Provider.of<CurrentUser>(context,listen: false);
//_current.updateStateFromDatabase(data,_current.getCurrentUser.uid);

return SafeArea(
child: Scaffold(
key: reviewKey,
backgroundColor: Colors.white,
resizeToAvoidBottomPadding: false,
appBar: AppBar(
title: Text('My Profile'),
flexibleSpace: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.deepPurple, Color(0xff2470c7)],
stops: [0.5, 1.0],
),
),
),
centerTitle: true,
// actions: <Widget>[
// IconButton(
// icon: Icon(Icons.notifications),
// onPressed: () {
// Navigator.pushNamed(context, "/activityFeed");
// },
// )
// ],
//backgroundColor: Colors.blueAccent,
elevation: 0.0,
),
body: user != null
? Container(
child: StreamBuilder(
stream: Firestore.instance
.collection('users')
.where("uid", isEqualTo: data)
.snapshots(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (BuildContext context, int index) {
return Stack(
children: <Widget>[
SafeArea(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
SizedBox(height: 20.0),
// _buildProfileImage(),
Center(
child: Container(
width: 100.0,
height: 100.0,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(snapshot
.data.documents
.elementAt(index)['image']),
fit: BoxFit.cover,
),
borderRadius:
BorderRadius.circular(50.0),
border: Border.all(
color: Colors.black26,
width: 2.0,
),
),
),
),
//_buildFullName(),
Text(
snapshot.data.documents
.elementAt(index)['displayName'],
style: TextStyle(
fontFamily: 'Roboto',
color: Colors.black,
fontSize: 28.0,
fontWeight: FontWeight.w700,
),
),
// _buildStatus(context),
// Container(
// padding: EdgeInsets.symmetric(
// vertical: 4.0, horizontal: 6.0),
// decoration: BoxDecoration(
// color: Theme
// .of(context)
// .scaffoldBackgroundColor,
// borderRadius: BorderRadius.circular(4.0),
// ),
// child: Text(
// snapshot.data.documents.elementAt(index)
['title'],
// style: TextStyle(
// fontFamily: 'Spectral',
// color: Colors.black,
// fontSize: 20.0,
// fontWeight: FontWeight.w300,
// ),
// ),
// ),
SizedBox(height: 10.0),
// _buildBio(context),
Container(
width: 270,
//color: Colors.white,
child: Text(
snapshot.data.documents.elementAt(
index)['description'],
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Spectral',
fontWeight: FontWeight.w400,
//try changing weight to w500 if not
thin
fontStyle: FontStyle.italic,
color: Colors.grey[600],
fontSize: 16.0,
),
),
),
SizedBox(height: 8.0),
// _buildpropertyStatus(context),
Container(
//color: Colors.grey[500],
color: Colors.teal[700],
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(
vertical: 4.0,
horizontal: 6.0),
child: Text(
_listings,
style: TextStyle(
fontFamily: 'Spectral',
color: Colors.white,
fontSize: 18.0,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
// _buildPropertyList(),
Container(
margin: EdgeInsets.only(top: 15),
height: 200,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
GestureDetector(
onTap: () {
Navigator.pushNamed(
context, '/AdDetail');
},
child: Container(
width: 160.0,
child: Card(
child: Wrap(
children: <Widget>[
Container(
height: 140,
width: double.infinity,
child: Image.asset(
'assets/index.jpg',

fit: BoxFit.cover,
),
),
Container(
color: Colors.grey,
child: ListTile(
title: Text(
'heading',
style: TextStyle(
fontSize: 16,
color: Colors
.black),
),
// subtitle: Text(
// 'subHeading',
// style: TextStyle(
// fontSize: 14, color:
Colors.white),
// ),
),
),
],
),
),
),
),
GestureDetector(
onTap: () {
Navigator.pushNamed(
context, '/AdDetail');
},
child: Container(
width: 160.0,
child: Card(
child: Wrap(
children: <Widget>[
Container(
height: 140,
width: double.infinity,
child: Image.asset(
'assets/index.jpg',

fit: BoxFit.cover,
),
),
Container(
color: Colors.grey,
child: ListTile(
title: Text(
'heading',
style: TextStyle(
fontSize: 16,
color: Colors
.black),
),
// subtitle: Text(
// 'subHeading',
// style: TextStyle(
// fontSize: 14, color:
Colors.white),
// ),
),
),
],
),
),
),
), GestureDetector(
onTap: () {
Navigator.pushNamed(
context, '/AdDetail');
},
child: Container(
width: 160.0,
child: Card(
child: Wrap(
children: <Widget>[
Container(
height: 140,
width: double.infinity,
child: Image.asset(
'assets/index.jpg',

fit: BoxFit.cover,
),
),
Container(
color: Colors.grey,
child: ListTile(
title: Text(
'heading',
style: TextStyle(
fontSize: 16,
color: Colors
.black),
),
// subtitle: Text(
// 'subHeading',
// style: TextStyle(
// fontSize: 14, color:
Colors.white),
// ),
),
),
],
),
),
),
),
],
),
),
// _showReviewForm(),
Container(
margin: EdgeInsets.only(top: 30),
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: <Widget>[
Container(
// color:
Colors.blue,
color: Colors.teal[700],
width: MediaQuery.of(context)
.size
.width,
height: 25,
child: Center(
child: Text(
'User Reviews',
style: TextStyle(
fontSize: 18,
color: Colors.white,
fontWeight:
FontWeight.bold,
),
),
),
),
],
),
),
Container(
margin: EdgeInsets.only(top: 20),
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
//crossAxisAlignment:
CrossAxisAlignment.end,
children: [
Text(
'Click Icon for Reviews',
style: TextStyle(
fontSize: 14,
fontWeight:
FontWeight.bold),
),
GestureDetector(
onTap: () => showComments(
context,
postId: snapshot
.data.documents
.elementAt(index)['uid'],
//ownerId: ownerId,
// mediaUrl:
snapshot.data.documents.elementAt(index)['image'],
),
child: Icon(
Icons.chat,
size: 28.0,
color: Colors.blue[900],
),
),
],
),
),
Container(
margin: EdgeInsets.only(top: 30),
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: <Widget>[
Container(
//color: Colors.grey[500],
color: Colors.teal[700],
width: MediaQuery.of(context)
.size
.width,
height: 25,
child: Center(
child: Text(
'Personal Information',
style: TextStyle(
fontSize: 18,
fontWeight:
FontWeight.bold,
color: Colors.white),
),
),
)
],
),
),
// _showPersonalInformation(context),
SizedBox(
height: 17,
),
Container(
// decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(40.0),
// color: Colors.black54,
//
// ),
margin: EdgeInsets.only(
left: 14, right: 14, bottom: 10),
padding: EdgeInsets.all(10),

child: Column(
children: <Widget>[
Container(
height: 50,
//color: Colors.grey[400],
//color: Colors.grey[200],
//color: Colors.black38,
//color: Colors.blue[200],
decoration: BoxDecoration(
borderRadius:
BorderRadius.only(
topLeft: Radius
.circular(20),
topRight:
Radius.circular(
20)),
color: Colors.blue[200],
border: Border.all(
width: 1,
color: Colors.blue[300],
style:
BorderStyle.solid)),
child: Padding(
padding:
const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.start,
children: <Widget>[
Container(
width: 70,
child: Text(
'Name: ',
style: TextStyle(
fontWeight:
FontWeight
.bold,
color: Colors
.black54,
),
)),
SizedBox(
width: 50,
),
Text(
snapshot.data.documents
.elementAt(
index)[
'displayName'],
style: TextStyle(
color:
Colors.black87),
),
],
),
),
),
Container(
height: 50,
//color: Colors.grey[200],
//color: Colors.blue[200],
decoration: BoxDecoration(
// borderRadius:
BorderRadius.only(bottomLeft: Radius.circular(40),bottomRight:
Radius.circular(40)),color: Colors.blue[200],
color: Colors.blue[200],
border: Border.all(
width: 1,
color: Colors.blue[300],
style:
BorderStyle.solid)),
child: Padding(
padding:
const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.start,
children: <Widget>[
Container(
width: 70,
child: Text(
'Age: ',
style: TextStyle(
fontWeight:
FontWeight

.bold,color: Colors.black54,),
)),
SizedBox(
width: 50,
),
Text(
snapshot.data.documents
.elementAt(
index)['age'],
style: TextStyle(
color:
Colors.black87),
),
],
),
),
),
Container(
height: 70,
//color: Colors.grey[400],
color: Colors.blue[200],
child: Padding(
padding:
const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.start,
children: <Widget>[
Container(
width: 70,
child: Text(
'Address: ',
style: TextStyle(
fontWeight:
FontWeight

.bold,color: Colors.black54,),
)),
SizedBox(
width: 50,
),
Flexible(
child: Text(
snapshot.data.documents
.elementAt(
index)[
'address'],
style: TextStyle(
color:
Colors.black87),
)),
],
),
),
),
Container(
height: 50,
//color: Colors.grey[200],
// color: Colors.blue[200],
decoration: BoxDecoration(
borderRadius:
BorderRadius.only(
bottomLeft: Radius
.circular(20),
bottomRight:
Radius.circular(
20)),
color: Colors.blue[200],
border: Border.all(
width: 1,
color: Colors.blue[300],
style:
BorderStyle.solid)),
child: Padding(
padding:
const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.start,
children: <Widget>[
Container(
width: 70,
child: Text(
'Cell No: ',
style: TextStyle(
fontWeight:
FontWeight

.bold,color: Colors.black54,),
)),
SizedBox(
width: 50,
),
Text(
snapshot.data.documents
.elementAt(
index)[
'phoneNumber'],
style: TextStyle(
color:
Colors.black87),
),
],
),
),
),
],
),
),
// _editProfileButton(),
user.uid ==
snapshot.data.documents
.elementAt(index)['uid']
? Container(
child: Center(
child: FlatButton(
onPressed: () {
Navigator.pushNamed(
context,
'/AgentSignup');
},
child: Container(
height: 50,
width: 100,
decoration: BoxDecoration(
color:
Colors.grey[800],
borderRadius:
BorderRadius
.circular(
10)),
child: Center(
child: Text(
"Edit Profile",
style: TextStyle(
color:
Colors.white,
fontWeight:
FontWeight
.bold),
),
),
),
),
),
)
: Container(),
SizedBox(height: 8.0),
SizedBox(height: 8.0),
],
),
),
),
],
);
},
);
} else {
debugPrint('Loading...');
return Center(
child: Text('Loading...'),
);
}
},
),
)
: Center(child: Text("Error"))),
);
}

Widget _showContact(BuildContext context) {


return Container();
}
}

showComments(BuildContext context, {String postId}) {


Navigator.push(context, MaterialPageRoute(builder: (context) {
return Comments(
postId: postId,
//postOwnerId: ownerId,
// image: mediaUrl,
);
}));
}

You might also like