Edit User profile
This commit is contained in:
+5
-2
@@ -3,6 +3,8 @@ import 'package:firebase_core/firebase_core.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_settings_screens/flutter_settings_screens.dart';
|
import 'package:flutter_settings_screens/flutter_settings_screens.dart';
|
||||||
import 'package:le_kiosque_by_gcs/services/auth/main_auth.dart';
|
import 'package:le_kiosque_by_gcs/services/auth/main_auth.dart';
|
||||||
|
import 'package:le_kiosque_by_gcs/services/firestore/firebase_user_service.dart';
|
||||||
|
import 'package:le_kiosque_by_gcs/services/firestore/user_service.dart';
|
||||||
import 'package:le_kiosque_by_gcs/ui/view/landing.dart';
|
import 'package:le_kiosque_by_gcs/ui/view/landing.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
@@ -26,9 +28,10 @@ class MyApp extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
home: MultiProvider(
|
home: MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
Provider<Auth>(create: (_) => MainAuth())
|
Provider<Auth>(create: (_) => MainAuth()),
|
||||||
|
Provider<UserService>(create: (_) => FirebaseUserService())
|
||||||
],
|
],
|
||||||
child: LandingPageView(),
|
builder: (context, widget) => LandingPageView(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-8
@@ -1,14 +1,21 @@
|
|||||||
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
|
|
||||||
class KiosqueUser {
|
class KiosqueUser {
|
||||||
final String uid;
|
String uid;
|
||||||
final String displayName;
|
String displayName;
|
||||||
final String city;
|
String city;
|
||||||
final String country;
|
String country;
|
||||||
final String phoneNumber;
|
String phoneNumber;
|
||||||
final String emailAddress;
|
String emailAddress;
|
||||||
final String gender;
|
String gender;
|
||||||
final String profileUrl;
|
String profileUrl;
|
||||||
|
DateTime createdAt;
|
||||||
|
DateTime updatedAt;
|
||||||
|
DateTime birthDay;
|
||||||
|
|
||||||
KiosqueUser({
|
KiosqueUser({
|
||||||
|
this.createdAt,
|
||||||
|
this.updatedAt,
|
||||||
this.uid,
|
this.uid,
|
||||||
this.displayName,
|
this.displayName,
|
||||||
this.city,
|
this.city,
|
||||||
@@ -17,5 +24,17 @@ class KiosqueUser {
|
|||||||
this.emailAddress,
|
this.emailAddress,
|
||||||
this.gender,
|
this.gender,
|
||||||
this.profileUrl,
|
this.profileUrl,
|
||||||
|
this.birthDay,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KiosqueUser toKiosqueUser(User firebaseUser) {
|
||||||
|
return KiosqueUser(
|
||||||
|
uid: firebaseUser.uid,
|
||||||
|
phoneNumber: firebaseUser.phoneNumber,
|
||||||
|
profileUrl: firebaseUser.photoURL ?? "https://www.ltc.lu/images/Contact/no_user_picture.jpg",
|
||||||
|
displayName: firebaseUser.displayName,
|
||||||
|
createdAt: firebaseUser.metadata.creationTime,
|
||||||
|
emailAddress: firebaseUser.email,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
|
|
||||||
import 'package:le_kiosque_by_gcs/services/auth/auth.dart';
|
import 'package:le_kiosque_by_gcs/services/auth/auth.dart';
|
||||||
import 'package:firebase_auth/firebase_auth.dart';
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
import 'package:flutter_login_facebook/flutter_login_facebook.dart';
|
import 'package:flutter_login_facebook/flutter_login_facebook.dart';
|
||||||
import 'package:google_sign_in/google_sign_in.dart';
|
import 'package:google_sign_in/google_sign_in.dart';
|
||||||
|
import 'package:le_kiosque_by_gcs/services/firestore/user_service.dart';
|
||||||
|
|
||||||
class MainAuth implements Auth {
|
class MainAuth implements Auth {
|
||||||
|
|
||||||
FirebaseAuth _auth = FirebaseAuth.instance;
|
FirebaseAuth _auth = FirebaseAuth.instance;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -17,7 +16,9 @@ class MainAuth implements Auth {
|
|||||||
final userAuth = await googleUser.authentication;
|
final userAuth = await googleUser.authentication;
|
||||||
if (userAuth.accessToken != null) {
|
if (userAuth.accessToken != null) {
|
||||||
final authCredential = GoogleAuthProvider.credential(
|
final authCredential = GoogleAuthProvider.credential(
|
||||||
accessToken: userAuth.accessToken, idToken: userAuth.idToken);
|
accessToken: userAuth.accessToken,
|
||||||
|
idToken: userAuth.idToken,
|
||||||
|
);
|
||||||
final authResult = await _auth.signInWithCredential(authCredential);
|
final authResult = await _auth.signInWithCredential(authCredential);
|
||||||
return authResult.user;
|
return authResult.user;
|
||||||
} else {
|
} else {
|
||||||
@@ -66,4 +67,4 @@ class MainAuth implements Auth {
|
|||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||||
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
|
import 'package:le_kiosque_by_gcs/model/user.dart';
|
||||||
|
import 'package:le_kiosque_by_gcs/services/firestore/user_service.dart';
|
||||||
|
|
||||||
|
class FirebaseUserService implements UserService {
|
||||||
|
FirebaseFirestore _firestore = FirebaseFirestore.instance;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Stream<KiosqueUser> getCurrentUser(String uid) {
|
||||||
|
final snapshots = _firestore.collection("users").doc(uid).snapshots();
|
||||||
|
return snapshots.map(
|
||||||
|
(event) {
|
||||||
|
final data = event.data();
|
||||||
|
return KiosqueUser(
|
||||||
|
uid: data["uid"],
|
||||||
|
displayName: data['displayName'],
|
||||||
|
emailAddress: data['emailAddress'],
|
||||||
|
city: data['city'],
|
||||||
|
country: data['country'],
|
||||||
|
gender: data['gender'],
|
||||||
|
profileUrl: data['profileUrl'],
|
||||||
|
phoneNumber: data['phoneNumber'],
|
||||||
|
createdAt: (data['createdAt'] as Timestamp).toDate(),
|
||||||
|
updatedAt : (data['updatedAt'] as Timestamp)?.toDate(),
|
||||||
|
birthDay : (data['birthDay'] as Timestamp)?.toDate(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> save(KiosqueUser kiosqueUser) async {
|
||||||
|
final user = {
|
||||||
|
'uid': kiosqueUser.uid,
|
||||||
|
'displayName': kiosqueUser.displayName,
|
||||||
|
'emailAddress': kiosqueUser.emailAddress,
|
||||||
|
'profileUrl': kiosqueUser.profileUrl,
|
||||||
|
'phoneNumber': kiosqueUser.phoneNumber,
|
||||||
|
'city': kiosqueUser.city,
|
||||||
|
'country': kiosqueUser.country,
|
||||||
|
'gender': kiosqueUser.gender,
|
||||||
|
'createdAt': kiosqueUser.createdAt,
|
||||||
|
'updatedAt': kiosqueUser.updatedAt,
|
||||||
|
'birthDay': kiosqueUser.birthDay,
|
||||||
|
};
|
||||||
|
return await _firestore.collection("users").doc(user['uid']).set(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> updateCurrentUser(data) async {
|
||||||
|
final userId = FirebaseAuth.instance.currentUser.uid;
|
||||||
|
return await _firestore.collection("users").doc(userId).set(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import 'package:le_kiosque_by_gcs/model/user.dart';
|
||||||
|
|
||||||
|
abstract class UserService {
|
||||||
|
Future<void> save(KiosqueUser kiosqueUser);
|
||||||
|
Future<void> updateCurrentUser(dynamic data);
|
||||||
|
Stream<KiosqueUser> getCurrentUser(String uid);
|
||||||
|
}
|
||||||
|
|
||||||
+14
-2
@@ -1,5 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:le_kiosque_by_gcs/model/user.dart';
|
||||||
import 'package:le_kiosque_by_gcs/services/auth/auth.dart';
|
import 'package:le_kiosque_by_gcs/services/auth/auth.dart';
|
||||||
|
import 'package:le_kiosque_by_gcs/services/firestore/user_service.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import '../custom/custom_elevated_button.dart';
|
import '../custom/custom_elevated_button.dart';
|
||||||
@@ -9,8 +11,13 @@ class AuthView extends StatelessWidget {
|
|||||||
|
|
||||||
Future<void> _signWithGoogle(context) async {
|
Future<void> _signWithGoogle(context) async {
|
||||||
final auth = Provider.of<Auth>(context, listen: false);
|
final auth = Provider.of<Auth>(context, listen: false);
|
||||||
|
final userService = Provider.of<UserService>(context, listen: false);
|
||||||
try {
|
try {
|
||||||
await auth.signInWithGoogle();
|
final firebaseUser = await auth.signInWithGoogle();
|
||||||
|
if (firebaseUser.metadata.creationTime == firebaseUser.metadata.lastSignInTime) {
|
||||||
|
final kiosqueUser = toKiosqueUser(firebaseUser);
|
||||||
|
await userService.save(kiosqueUser);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("Error $e");
|
print("Error $e");
|
||||||
}
|
}
|
||||||
@@ -18,8 +25,13 @@ class AuthView extends StatelessWidget {
|
|||||||
|
|
||||||
Future<void> _signInWithFacebook(context) async {
|
Future<void> _signInWithFacebook(context) async {
|
||||||
final auth = Provider.of<Auth>(context, listen: false);
|
final auth = Provider.of<Auth>(context, listen: false);
|
||||||
|
final userService = Provider.of<UserService>(context, listen: false);
|
||||||
try {
|
try {
|
||||||
await auth.signInWithFacebook();
|
final firebaseUser = await auth.signInWithFacebook();
|
||||||
|
if (firebaseUser.metadata.creationTime == firebaseUser.metadata.lastSignInTime) {
|
||||||
|
final kiosqueUser = toKiosqueUser(firebaseUser);
|
||||||
|
await userService.save(kiosqueUser);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("Error $e");
|
print("Error $e");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class EditProfileView extends StatefulWidget {
|
|
||||||
@override
|
|
||||||
_EditProfileViewState createState() => _EditProfileViewState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _EditProfileViewState extends State<EditProfileView> {
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
backgroundColor: Colors.white,
|
|
||||||
iconTheme: IconThemeData(
|
|
||||||
color: Color(0xFF545454), //change your color here
|
|
||||||
)
|
|
||||||
),
|
|
||||||
body: Container(
|
|
||||||
width: double.infinity,
|
|
||||||
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,249 @@
|
|||||||
|
import 'package:country_picker/country_picker.dart';
|
||||||
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:le_kiosque_by_gcs/model/user.dart';
|
||||||
|
import 'package:le_kiosque_by_gcs/services/firestore/user_service.dart';
|
||||||
|
import 'package:le_kiosque_by_gcs/ui/custom/profile_picture.dart';
|
||||||
|
|
||||||
|
class EditProfileView extends StatefulWidget {
|
||||||
|
final UserService userService;
|
||||||
|
|
||||||
|
const EditProfileView({
|
||||||
|
Key key,
|
||||||
|
@required this.userService,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_EditProfileViewState createState() => _EditProfileViewState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _EditProfileViewState extends State<EditProfileView> {
|
||||||
|
TextEditingController _countryController = TextEditingController();
|
||||||
|
TextEditingController _cityController = TextEditingController();
|
||||||
|
TextEditingController _dateController = TextEditingController();
|
||||||
|
TextEditingController _genderController = TextEditingController();
|
||||||
|
|
||||||
|
DateTime _selectedDate;
|
||||||
|
|
||||||
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
KiosqueUser currentUser;
|
||||||
|
|
||||||
|
void _submitForm(KiosqueUser user) async {
|
||||||
|
if (_validateAndSaveForm()) {
|
||||||
|
user.country = _countryController.text.toString();
|
||||||
|
user.city = _cityController.text.toString();
|
||||||
|
user.gender = _genderController.text.toString();
|
||||||
|
user.birthDay = _selectedDate;
|
||||||
|
|
||||||
|
await widget.userService.save(user);
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _validateAndSaveForm() {
|
||||||
|
final formState = _formKey.currentState;
|
||||||
|
if (formState.validate()) {
|
||||||
|
formState.save();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _selectDate(BuildContext context) async {
|
||||||
|
final DateTime picked = await showDatePicker(
|
||||||
|
context: context,
|
||||||
|
initialDate: DateTime.now(),
|
||||||
|
firstDate: DateTime(1900, 8),
|
||||||
|
lastDate: DateTime(2101),
|
||||||
|
);
|
||||||
|
|
||||||
|
final stringDate = DateFormat.yMMMd().format(picked);
|
||||||
|
_selectedDate = picked;
|
||||||
|
_dateController.text = stringDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return StreamBuilder<KiosqueUser>(
|
||||||
|
stream: widget.userService
|
||||||
|
.getCurrentUser(FirebaseAuth.instance.currentUser.uid),
|
||||||
|
builder: (_, snapshot) {
|
||||||
|
if (snapshot.hasData) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
iconTheme: IconThemeData(
|
||||||
|
color: Color(0xFF545454), //change your color here
|
||||||
|
),
|
||||||
|
),
|
||||||
|
body: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child:
|
||||||
|
ProfilePicture(imageUrl: snapshot.data.profileUrl),
|
||||||
|
),
|
||||||
|
Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
snapshot.data.displayName,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 26,
|
||||||
|
color: Colors.black,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
top: 10,
|
||||||
|
right: 10,
|
||||||
|
bottom: 10,
|
||||||
|
),
|
||||||
|
child: Icon(
|
||||||
|
Icons.location_on,
|
||||||
|
color: Color(0xFFA5A5A5),
|
||||||
|
size: 17,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
snapshot.data.city ?? "No location",
|
||||||
|
style: TextStyle(color: Colors.grey),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: Form(
|
||||||
|
key: _formKey,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
TextFormField(
|
||||||
|
controller: _countryController,
|
||||||
|
readOnly: true,
|
||||||
|
validator: (value) => value.isEmpty ? 'Ne doit pas être vide ! !' : null,
|
||||||
|
onTap: () => _showCountryPicker(context),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
hintText: 'Pays',
|
||||||
|
labelText: "Pays",
|
||||||
|
hoverColor: Colors.black,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 16),
|
||||||
|
TextFormField(
|
||||||
|
controller: _cityController,
|
||||||
|
validator: (value) => value.isEmpty ? 'Ne doit pas être vide ! !' : null,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
hintText: 'Ville',
|
||||||
|
labelText: "Ville",
|
||||||
|
hoverColor: Colors.black,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 16),
|
||||||
|
TextFormField(
|
||||||
|
validator: (value) => value.isEmpty ? 'Ne doit pas être vide ! !' : null,
|
||||||
|
controller: _genderController,
|
||||||
|
onTap: () => _showGenderDialog(),
|
||||||
|
readOnly: true,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
hintText: 'Genre',
|
||||||
|
labelText: "Genre",
|
||||||
|
hoverColor: Colors.black,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 16),
|
||||||
|
TextFormField(
|
||||||
|
readOnly: true,
|
||||||
|
validator: (value) => value.isEmpty ? 'Ne doit pas être vide ! !' : null,
|
||||||
|
controller: _dateController,
|
||||||
|
onTap: () => _selectDate(context),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
hintText: 'Date de naissance',
|
||||||
|
labelText: "Date de naissance",
|
||||||
|
hoverColor: Colors.black,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 16),
|
||||||
|
SizedBox(
|
||||||
|
height: 50,
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: () => _submitForm(snapshot.data),
|
||||||
|
child: Text("Enregistrer"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return Scaffold(
|
||||||
|
body: Center(
|
||||||
|
child: Text("Problème de connexion !"),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _showGenderDialog() {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text("Genre"),
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
ListTile(
|
||||||
|
title: Text("Homme"),
|
||||||
|
onTap: () {
|
||||||
|
_genderController.text = "Homme";
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
title: Text("Femme"),
|
||||||
|
onTap: () {
|
||||||
|
_genderController.text = "Femme";
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _showCountryPicker(BuildContext context) {
|
||||||
|
showCountryPicker(
|
||||||
|
context: context,
|
||||||
|
showPhoneCode: false,
|
||||||
|
onSelect: (Country country) {
|
||||||
|
setState(() {
|
||||||
|
_countryController.text = country.displayNameNoCountryCode;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
-17
@@ -6,29 +6,26 @@ import 'package:le_kiosque_by_gcs/ui/view/main.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class LandingPageView extends StatelessWidget {
|
class LandingPageView extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
final auth = Provider.of<Auth>(context, listen: false);
|
final auth = Provider.of<Auth>(context, listen: false);
|
||||||
return StreamBuilder<User>(
|
return StreamBuilder<User>(
|
||||||
stream: auth.authStateChanges(),
|
stream: auth.authStateChanges(),
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.connectionState == ConnectionState.active) {
|
if (snapshot.connectionState == ConnectionState.active) {
|
||||||
if (snapshot.data == null) {
|
if (snapshot.data == null) {
|
||||||
return AuthView();
|
return AuthView();
|
||||||
} else {
|
} else {
|
||||||
return MainView();
|
return MainView();
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return Scaffold(
|
|
||||||
body: Center(
|
|
||||||
child: CircularProgressIndicator(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return Scaffold(
|
||||||
|
body: Center(
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,15 @@ import 'package:firebase_auth/firebase_auth.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:le_kiosque_by_gcs/model/news.dart';
|
import 'package:le_kiosque_by_gcs/model/news.dart';
|
||||||
|
import 'package:le_kiosque_by_gcs/services/auth/auth.dart';
|
||||||
|
import 'package:le_kiosque_by_gcs/services/auth/main_auth.dart';
|
||||||
import 'package:le_kiosque_by_gcs/ui/view/home.dart';
|
import 'package:le_kiosque_by_gcs/ui/view/home.dart';
|
||||||
import 'package:le_kiosque_by_gcs/ui/view/news/news.dart';
|
import 'package:le_kiosque_by_gcs/ui/view/news/news.dart';
|
||||||
import 'package:le_kiosque_by_gcs/ui/view/profile.dart';
|
import 'package:le_kiosque_by_gcs/ui/view/profile.dart';
|
||||||
import 'package:le_kiosque_by_gcs/ui/view/search/search.dart';
|
import 'package:le_kiosque_by_gcs/ui/view/search/search.dart';
|
||||||
import 'package:le_kiosque_by_gcs/ui/view/setting/setting.dart';
|
import 'package:le_kiosque_by_gcs/ui/view/setting/setting.dart';
|
||||||
import 'package:le_kiosque_by_gcs/ui/view/subscription/subscription.dart';
|
import 'package:le_kiosque_by_gcs/ui/view/subscription/subscription.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class MainView extends StatefulWidget {
|
class MainView extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
@@ -33,9 +36,13 @@ class _MainViewState extends State<MainView> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_showSettingView(BuildContext context) {
|
_showSettingView(BuildContext context) {
|
||||||
|
final auth = Provider.of<Auth>(context, listen: false);
|
||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (_) => SettingView(),
|
builder: (context) => Provider(
|
||||||
|
create: (context) => MainAuth(),
|
||||||
|
child: SettingView(auth: auth),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -43,7 +50,7 @@ class _MainViewState extends State<MainView> {
|
|||||||
void _showSearchView(BuildContext context) {
|
void _showSearchView(BuildContext context) {
|
||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (_) => SearchView(),
|
builder: (context) => SearchView(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+60
-36
@@ -1,9 +1,12 @@
|
|||||||
import 'package:firebase_auth/firebase_auth.dart';
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:le_kiosque_by_gcs/model/magazine.dart';
|
import 'package:le_kiosque_by_gcs/model/magazine.dart';
|
||||||
|
import 'package:le_kiosque_by_gcs/model/user.dart';
|
||||||
|
import 'package:le_kiosque_by_gcs/services/firestore/user_service.dart';
|
||||||
import 'package:le_kiosque_by_gcs/ui/custom/item_mag_large.dart';
|
import 'package:le_kiosque_by_gcs/ui/custom/item_mag_large.dart';
|
||||||
import 'package:le_kiosque_by_gcs/ui/custom/profile_picture.dart';
|
import 'package:le_kiosque_by_gcs/ui/custom/profile_picture.dart';
|
||||||
import 'package:le_kiosque_by_gcs/ui/view/edit_profil.dart';
|
import 'package:le_kiosque_by_gcs/ui/view/editprofile/edit_profil.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class ProfileView extends StatefulWidget {
|
class ProfileView extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
@@ -92,48 +95,69 @@ class _ProfileViewState extends State<ProfileView> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildProfileHeader() {
|
Widget _buildProfileHeader() {
|
||||||
final imageUrl = FirebaseAuth.instance.currentUser.photoURL;
|
final userService = Provider.of<UserService>(context, listen: false);
|
||||||
return Column(
|
return StreamBuilder<KiosqueUser>(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
stream: userService.getCurrentUser(FirebaseAuth.instance.currentUser.uid),
|
||||||
children: [
|
builder: (context, snapshot) {
|
||||||
Center(
|
if (snapshot.hasError) {
|
||||||
child: Padding(
|
return Scaffold(
|
||||||
padding: const EdgeInsets.all(16.0),
|
body: Center(
|
||||||
child: ProfilePicture(imageUrl: imageUrl),
|
child: Text("Une erreur s'est produite"),
|
||||||
),
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
"Eric Ampire",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 26,
|
|
||||||
color: Colors.black,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: Icon(
|
|
||||||
Icons.location_on,
|
|
||||||
color: Color(0xFFA5A5A5),
|
|
||||||
size: 17,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
Text(
|
);
|
||||||
"Lubumbashi",
|
}
|
||||||
style: TextStyle(color: Colors.grey),
|
if (snapshot.hasData) {
|
||||||
)
|
return Column(
|
||||||
],
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
)
|
children: [
|
||||||
],
|
Center(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: ProfilePicture(imageUrl: snapshot.data.profileUrl),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
snapshot.data.displayName,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 26,
|
||||||
|
color: Colors.black,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Icon(
|
||||||
|
Icons.location_on,
|
||||||
|
color: Color(0xFFA5A5A5),
|
||||||
|
size: 17,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
snapshot.data.city ?? "No location",
|
||||||
|
style: TextStyle(color: Colors.grey),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return Scaffold(
|
||||||
|
body: Center(
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_showEditProfileView(BuildContext context) {
|
_showEditProfileView(BuildContext context) {
|
||||||
|
final userService = Provider.of<UserService>(context, listen: false);
|
||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (BuildContext context) => EditProfileView(),
|
builder: (BuildContext context) => EditProfileView(userService: userService),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-2
@@ -57,6 +57,27 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0"
|
version: "1.1.0"
|
||||||
|
cloud_firestore:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: cloud_firestore
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.14.3"
|
||||||
|
cloud_firestore_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: cloud_firestore_platform_interface
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.2.0"
|
||||||
|
cloud_firestore_web:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: cloud_firestore_web
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.2.1"
|
||||||
collection:
|
collection:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -64,6 +85,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.15.0"
|
version: "1.15.0"
|
||||||
|
country_picker:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: country_picker
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.3"
|
||||||
crypto:
|
crypto:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -133,7 +161,7 @@ packages:
|
|||||||
name: firebase_core
|
name: firebase_core
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.5.1"
|
version: "0.5.2"
|
||||||
firebase_core_platform_interface:
|
firebase_core_platform_interface:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -241,7 +269,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0"
|
version: "1.1.0"
|
||||||
intl:
|
intl:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: intl
|
name: intl
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
|
|||||||
+4
-1
@@ -31,8 +31,9 @@ dependencies:
|
|||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
cupertino_icons: ^1.0.2
|
cupertino_icons: ^1.0.2
|
||||||
firebase_core: 0.5.1
|
firebase_core: 0.5.2
|
||||||
firebase_auth: 0.18.2
|
firebase_auth: 0.18.2
|
||||||
|
cloud_firestore: 0.14.3
|
||||||
google_sign_in: ^4.5.6
|
google_sign_in: ^4.5.6
|
||||||
flutter_login_facebook: 0.4.0+1
|
flutter_login_facebook: 0.4.0+1
|
||||||
provider: ^4.0.0
|
provider: ^4.0.0
|
||||||
@@ -40,6 +41,8 @@ dependencies:
|
|||||||
flutter_settings_screens: ^0.2.1+1
|
flutter_settings_screens: ^0.2.1+1
|
||||||
url_launcher: ^6.0.2
|
url_launcher: ^6.0.2
|
||||||
carousel_slider: ^3.0.0
|
carousel_slider: ^3.0.0
|
||||||
|
country_picker: ^2.0.3
|
||||||
|
intl: ^0.16.1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
Reference in New Issue
Block a user