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,144 +67,144 @@ 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>(
|
return Scaffold(
|
||||||
stream: widget.userService
|
appBar: AppBar(
|
||||||
.getCurrentUser(FirebaseAuth.instance.currentUser.uid),
|
backgroundColor: Colors.white,
|
||||||
builder: (_, snapshot) {
|
iconTheme: IconThemeData(
|
||||||
if (snapshot.hasData) {
|
color: Color(0xFF545454), //change your color here
|
||||||
return Scaffold(
|
),
|
||||||
appBar: AppBar(
|
),
|
||||||
backgroundColor: Colors.white,
|
body: SingleChildScrollView(
|
||||||
iconTheme: IconThemeData(
|
child: Column(
|
||||||
color: Color(0xFF545454), //change your color here
|
children: [
|
||||||
),
|
Row(
|
||||||
),
|
children: [
|
||||||
body: SingleChildScrollView(
|
Padding(
|
||||||
child: Column(
|
padding: const EdgeInsets.all(16.0),
|
||||||
children: [
|
child:
|
||||||
Row(
|
ProfilePicture(imageUrl: widget.user.profileUrl),
|
||||||
children: [
|
),
|
||||||
Padding(
|
Column(
|
||||||
padding: const EdgeInsets.all(16.0),
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
child:
|
children: [
|
||||||
ProfilePicture(imageUrl: snapshot.data.profileUrl),
|
Text(
|
||||||
),
|
widget.user.displayName,
|
||||||
Column(
|
style: TextStyle(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
fontSize: 26,
|
||||||
children: [
|
color: Colors.black,
|
||||||
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"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
Row(
|
||||||
],
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
top: 10,
|
||||||
|
right: 10,
|
||||||
|
bottom: 10,
|
||||||
|
),
|
||||||
|
child: Icon(
|
||||||
|
Icons.location_on,
|
||||||
|
color: Color(0xFFA5A5A5),
|
||||||
|
size: 17,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
widget.user.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(widget.user),
|
||||||
|
child: Text("Enregistrer"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
);
|
],
|
||||||
} else {
|
),
|
||||||
return Scaffold(
|
),
|
||||||
body: Center(
|
|
||||||
child: Text("Problème de connexion !"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+115
-111
@@ -16,69 +16,91 @@ 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 Scaffold(
|
return StreamBuilder<KiosqueUser>(
|
||||||
body: CustomScrollView(
|
stream: userService.getCurrentUser(FirebaseAuth.instance.currentUser.uid),
|
||||||
slivers: [
|
builder: (context, snapshot) {
|
||||||
SliverToBoxAdapter(
|
if (snapshot.hasError) {
|
||||||
child: Column(
|
return Scaffold(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
body: Center(
|
||||||
children: [
|
child: Text("Une erreur s'est produite"),
|
||||||
_buildProfileHeader(),
|
),
|
||||||
SizedBox(height: 24),
|
);
|
||||||
Padding(
|
}
|
||||||
padding: const EdgeInsets.only(
|
if (snapshot.hasData) {
|
||||||
left: 16,
|
return Scaffold(
|
||||||
top: 34,
|
body: CustomScrollView(
|
||||||
right: 16,
|
slivers: [
|
||||||
bottom: 16,
|
SliverToBoxAdapter(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
_buildProfileHeader(snapshot.data),
|
||||||
|
SizedBox(height: 24),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
left: 16,
|
||||||
|
top: 34,
|
||||||
|
right: 16,
|
||||||
|
bottom: 16,
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
"A lire plus tard",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 22,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
),
|
),
|
||||||
child: Text(
|
),
|
||||||
"A lire plus tard",
|
SliverPadding(
|
||||||
style: TextStyle(
|
padding: EdgeInsets.all(16),
|
||||||
fontSize: 22,
|
sliver: SliverGrid(
|
||||||
fontWeight: FontWeight.bold,
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
|
crossAxisCount: 2,
|
||||||
|
mainAxisSpacing: 16.0,
|
||||||
|
crossAxisSpacing: 16.0,
|
||||||
|
mainAxisExtent: 250,
|
||||||
|
),
|
||||||
|
delegate: SliverChildBuilderDelegate(
|
||||||
|
(context, int index) =>
|
||||||
|
ItemMagLarge(magazine: magazinesTest[index]),
|
||||||
|
childCount: magazinesTest.length,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
floatingActionButtonAnimator: FloatingActionButtonAnimator.scaling,
|
||||||
SliverPadding(
|
floatingActionButtonLocation:
|
||||||
padding: EdgeInsets.all(16),
|
FloatingActionButtonLocation.centerFloat,
|
||||||
sliver: SliverGrid(
|
floatingActionButton: Visibility(
|
||||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
child: FloatingActionButton.extended(
|
||||||
crossAxisCount: 2,
|
onPressed: () => _showEditProfileView(context, snapshot.data),
|
||||||
mainAxisSpacing: 16.0,
|
label: const Text(
|
||||||
crossAxisSpacing: 16.0,
|
'Editer',
|
||||||
mainAxisExtent: 250
|
style: TextStyle(
|
||||||
),
|
color: Color(0XFFFF567E),
|
||||||
delegate: SliverChildBuilderDelegate(
|
),
|
||||||
(context, int index) => ItemMagLarge(magazine: magazinesTest[index]),
|
),
|
||||||
childCount: magazinesTest.length,
|
icon: const Icon(
|
||||||
|
Icons.edit,
|
||||||
|
color: Color(0XFFFF567E),
|
||||||
|
),
|
||||||
|
backgroundColor: Colors.white,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
],
|
} else {
|
||||||
),
|
return Scaffold(
|
||||||
floatingActionButtonAnimator: FloatingActionButtonAnimator.scaling,
|
body: Center(
|
||||||
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
|
child: CircularProgressIndicator(),
|
||||||
floatingActionButton: Visibility(
|
|
||||||
child: FloatingActionButton.extended(
|
|
||||||
onPressed: () => _showEditProfileView(context),
|
|
||||||
label: const Text(
|
|
||||||
'Editer',
|
|
||||||
style: TextStyle(
|
|
||||||
color: Color(0XFFFF567E),
|
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
icon: const Icon(
|
}
|
||||||
Icons.edit,
|
},
|
||||||
color: Color(0XFFFF567E),
|
|
||||||
),
|
|
||||||
backgroundColor: Colors.white,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,70 +116,52 @@ class _ProfileViewState extends State<ProfileView> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildProfileHeader() {
|
Widget _buildProfileHeader(KiosqueUser user) {
|
||||||
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: user.profileUrl),
|
||||||
child: Text("Une erreur s'est produite"),
|
),
|
||||||
),
|
),
|
||||||
);
|
Text(
|
||||||
}
|
user.displayName,
|
||||||
if (snapshot.hasData) {
|
style: TextStyle(
|
||||||
return Column(
|
fontSize: 26,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
color: Colors.black,
|
||||||
children: [
|
),
|
||||||
Center(
|
),
|
||||||
child: Padding(
|
Row(
|
||||||
padding: const EdgeInsets.all(16.0),
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
child: ProfilePicture(imageUrl: snapshot.data.profileUrl),
|
children: [
|
||||||
),
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Icon(
|
||||||
|
Icons.location_on,
|
||||||
|
color: Color(0xFFA5A5A5),
|
||||||
|
size: 17,
|
||||||
),
|
),
|
||||||
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(),
|
|
||||||
),
|
),
|
||||||
);
|
Text(
|
||||||
}
|
user.city ?? "No location",
|
||||||
},
|
style: TextStyle(color: Colors.grey),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_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