Fix editing view issue

This commit is contained in:
2021-03-31 22:39:08 +02:00
parent 54fc7e33aa
commit e294752ab8
2 changed files with 252 additions and 245 deletions
+115 -111
View File
@@ -16,69 +16,91 @@ class ProfileView extends StatefulWidget {
class _ProfileViewState extends State<ProfileView> {
@override
Widget build(BuildContext context) {
// TODO Removing
return Scaffold(
body: CustomScrollView(
slivers: [
SliverToBoxAdapter(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildProfileHeader(),
SizedBox(height: 24),
Padding(
padding: const EdgeInsets.only(
left: 16,
top: 34,
right: 16,
bottom: 16,
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(
body: CustomScrollView(
slivers: [
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",
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
),
SliverPadding(
padding: EdgeInsets.all(16),
sliver: SliverGrid(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: 16.0,
crossAxisSpacing: 16.0,
mainAxisExtent: 250,
),
delegate: SliverChildBuilderDelegate(
(context, int index) =>
ItemMagLarge(magazine: magazinesTest[index]),
childCount: magazinesTest.length,
),
),
)
),
],
),
),
SliverPadding(
padding: EdgeInsets.all(16),
sliver: SliverGrid(
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,
floatingActionButtonLocation:
FloatingActionButtonLocation.centerFloat,
floatingActionButton: Visibility(
child: FloatingActionButton.extended(
onPressed: () => _showEditProfileView(context, snapshot.data),
label: const Text(
'Editer',
style: TextStyle(
color: Color(0XFFFF567E),
),
),
icon: const Icon(
Icons.edit,
color: Color(0XFFFF567E),
),
backgroundColor: Colors.white,
),
),
),
],
),
floatingActionButtonAnimator: FloatingActionButtonAnimator.scaling,
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: Visibility(
child: FloatingActionButton.extended(
onPressed: () => _showEditProfileView(context),
label: const Text(
'Editer',
style: TextStyle(
color: Color(0XFFFF567E),
);
} else {
return Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
),
icon: const Icon(
Icons.edit,
color: Color(0XFFFF567E),
),
backgroundColor: Colors.white,
),
),
);
}
},
);
}
@@ -94,70 +116,52 @@ class _ProfileViewState extends State<ProfileView> {
);
}
Widget _buildProfileHeader() {
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(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: ProfilePicture(imageUrl: snapshot.data.profileUrl),
),
Widget _buildProfileHeader(KiosqueUser user) {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: ProfilePicture(imageUrl: user.profileUrl),
),
),
Text(
user.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.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);
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) => EditProfileView(userService: userService),
builder: (BuildContext context) => EditProfileView(
userService: userService,
user: user,
),
),
);
}