Fix editing view issue
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import 'package:country_picker/country_picker.dart';
|
import 'package:country_picker/country_picker.dart';
|
||||||
import 'package:firebase_auth/firebase_auth.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:le_kiosque_by_gcs/model/user.dart';
|
import 'package:le_kiosque_by_gcs/model/user.dart';
|
||||||
@@ -8,10 +7,12 @@ import 'package:le_kiosque_by_gcs/ui/custom/profile_picture.dart';
|
|||||||
|
|
||||||
class EditProfileView extends StatefulWidget {
|
class EditProfileView extends StatefulWidget {
|
||||||
final UserService userService;
|
final UserService userService;
|
||||||
|
final KiosqueUser user;
|
||||||
|
|
||||||
const EditProfileView({
|
const EditProfileView({
|
||||||
Key key,
|
Key key,
|
||||||
@required this.userService,
|
@required this.userService,
|
||||||
|
@required this.user,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -19,6 +20,7 @@ class EditProfileView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _EditProfileViewState extends State<EditProfileView> {
|
class _EditProfileViewState extends State<EditProfileView> {
|
||||||
|
|
||||||
TextEditingController _countryController = TextEditingController();
|
TextEditingController _countryController = TextEditingController();
|
||||||
TextEditingController _cityController = TextEditingController();
|
TextEditingController _cityController = TextEditingController();
|
||||||
TextEditingController _dateController = TextEditingController();
|
TextEditingController _dateController = TextEditingController();
|
||||||
@@ -41,6 +43,7 @@ class _EditProfileViewState extends State<EditProfileView> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool _validateAndSaveForm() {
|
bool _validateAndSaveForm() {
|
||||||
final formState = _formKey.currentState;
|
final formState = _formKey.currentState;
|
||||||
if (formState.validate()) {
|
if (formState.validate()) {
|
||||||
@@ -64,13 +67,22 @@ class _EditProfileViewState extends State<EditProfileView> {
|
|||||||
_dateController.text = stringDate;
|
_dateController.text = stringDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
if (widget.user.birthDay != null) {
|
||||||
|
final stringDate = DateFormat.yMMMd().format(widget.user.birthDay);
|
||||||
|
_selectedDate = widget.user.birthDay;
|
||||||
|
_dateController.text = stringDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
_countryController.text = widget.user.country;
|
||||||
|
_genderController.text = widget.user.gender;
|
||||||
|
_cityController.text = widget.user.city;
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return StreamBuilder<KiosqueUser>(
|
|
||||||
stream: widget.userService
|
|
||||||
.getCurrentUser(FirebaseAuth.instance.currentUser.uid),
|
|
||||||
builder: (_, snapshot) {
|
|
||||||
if (snapshot.hasData) {
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
@@ -86,13 +98,13 @@ class _EditProfileViewState extends State<EditProfileView> {
|
|||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child:
|
child:
|
||||||
ProfilePicture(imageUrl: snapshot.data.profileUrl),
|
ProfilePicture(imageUrl: widget.user.profileUrl),
|
||||||
),
|
),
|
||||||
Column(
|
Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
snapshot.data.displayName,
|
widget.user.displayName,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 26,
|
fontSize: 26,
|
||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
@@ -113,7 +125,7 @@ class _EditProfileViewState extends State<EditProfileView> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
snapshot.data.city ?? "No location",
|
widget.user.city ?? "No location",
|
||||||
style: TextStyle(color: Colors.grey),
|
style: TextStyle(color: Colors.grey),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
@@ -182,7 +194,7 @@ class _EditProfileViewState extends State<EditProfileView> {
|
|||||||
SizedBox(
|
SizedBox(
|
||||||
height: 50,
|
height: 50,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () => _submitForm(snapshot.data),
|
onPressed: () => _submitForm(widget.user),
|
||||||
child: Text("Enregistrer"),
|
child: Text("Enregistrer"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -194,15 +206,6 @@ class _EditProfileViewState extends State<EditProfileView> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
return Scaffold(
|
|
||||||
body: Center(
|
|
||||||
child: Text("Problème de connexion !"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showGenderDialog() {
|
void _showGenderDialog() {
|
||||||
|
|||||||
+37
-33
@@ -16,7 +16,18 @@ class ProfileView extends StatefulWidget {
|
|||||||
class _ProfileViewState extends State<ProfileView> {
|
class _ProfileViewState extends State<ProfileView> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// TODO Removing
|
final userService = Provider.of<UserService>(context, listen: false);
|
||||||
|
return StreamBuilder<KiosqueUser>(
|
||||||
|
stream: userService.getCurrentUser(FirebaseAuth.instance.currentUser.uid),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.hasError) {
|
||||||
|
return Scaffold(
|
||||||
|
body: Center(
|
||||||
|
child: Text("Une erreur s'est produite"),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (snapshot.hasData) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: CustomScrollView(
|
body: CustomScrollView(
|
||||||
slivers: [
|
slivers: [
|
||||||
@@ -24,7 +35,7 @@ class _ProfileViewState extends State<ProfileView> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
_buildProfileHeader(),
|
_buildProfileHeader(snapshot.data),
|
||||||
SizedBox(height: 24),
|
SizedBox(height: 24),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(
|
padding: const EdgeInsets.only(
|
||||||
@@ -51,10 +62,11 @@ class _ProfileViewState extends State<ProfileView> {
|
|||||||
crossAxisCount: 2,
|
crossAxisCount: 2,
|
||||||
mainAxisSpacing: 16.0,
|
mainAxisSpacing: 16.0,
|
||||||
crossAxisSpacing: 16.0,
|
crossAxisSpacing: 16.0,
|
||||||
mainAxisExtent: 250
|
mainAxisExtent: 250,
|
||||||
),
|
),
|
||||||
delegate: SliverChildBuilderDelegate(
|
delegate: SliverChildBuilderDelegate(
|
||||||
(context, int index) => ItemMagLarge(magazine: magazinesTest[index]),
|
(context, int index) =>
|
||||||
|
ItemMagLarge(magazine: magazinesTest[index]),
|
||||||
childCount: magazinesTest.length,
|
childCount: magazinesTest.length,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -62,10 +74,11 @@ class _ProfileViewState extends State<ProfileView> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
floatingActionButtonAnimator: FloatingActionButtonAnimator.scaling,
|
floatingActionButtonAnimator: FloatingActionButtonAnimator.scaling,
|
||||||
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
|
floatingActionButtonLocation:
|
||||||
|
FloatingActionButtonLocation.centerFloat,
|
||||||
floatingActionButton: Visibility(
|
floatingActionButton: Visibility(
|
||||||
child: FloatingActionButton.extended(
|
child: FloatingActionButton.extended(
|
||||||
onPressed: () => _showEditProfileView(context),
|
onPressed: () => _showEditProfileView(context, snapshot.data),
|
||||||
label: const Text(
|
label: const Text(
|
||||||
'Editer',
|
'Editer',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
@@ -80,6 +93,15 @@ class _ProfileViewState extends State<ProfileView> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
return Scaffold(
|
||||||
|
body: Center(
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildProfileBody() {
|
Widget _buildProfileBody() {
|
||||||
@@ -94,30 +116,18 @@ class _ProfileViewState extends State<ProfileView> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildProfileHeader() {
|
Widget _buildProfileHeader(KiosqueUser user) {
|
||||||
final userService = Provider.of<UserService>(context, listen: false);
|
|
||||||
return StreamBuilder<KiosqueUser>(
|
|
||||||
stream: userService.getCurrentUser(FirebaseAuth.instance.currentUser.uid),
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
if (snapshot.hasError) {
|
|
||||||
return Scaffold(
|
|
||||||
body: Center(
|
|
||||||
child: Text("Une erreur s'est produite"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (snapshot.hasData) {
|
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Center(
|
Center(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: ProfilePicture(imageUrl: snapshot.data.profileUrl),
|
child: ProfilePicture(imageUrl: user.profileUrl),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
snapshot.data.displayName,
|
user.displayName,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 26,
|
fontSize: 26,
|
||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
@@ -135,29 +145,23 @@ class _ProfileViewState extends State<ProfileView> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
snapshot.data.city ?? "No location",
|
user.city ?? "No location",
|
||||||
style: TextStyle(color: Colors.grey),
|
style: TextStyle(color: Colors.grey),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
return Scaffold(
|
|
||||||
body: Center(
|
|
||||||
child: CircularProgressIndicator(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_showEditProfileView(BuildContext context) {
|
_showEditProfileView(BuildContext context, KiosqueUser user) {
|
||||||
final userService = Provider.of<UserService>(context, listen: false);
|
final userService = Provider.of<UserService>(context, listen: false);
|
||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (BuildContext context) => EditProfileView(userService: userService),
|
builder: (BuildContext context) => EditProfileView(
|
||||||
|
userService: userService,
|
||||||
|
user: user,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user