I've a problem with flutter pattern bloc provider, I've a page profile and another page profile_edit with form, i want to update data in profile page when i save the data from form, how to update the page profile when save the form?
this is my complete profile page:
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:transparent_image/transparent_image.dart';
import 'package:wags/bloc/profile/bloc.dart';
import 'package:wags/bloc/profile/profile_event.dart';
import 'package:wags/custom_widgets/wags_button_azure.dart';
import 'package:wags/custom_widgets/wags_loader.dart';
import 'package:wags/pages/profile_edit/profile_edit.dart';
import 'package:wags/repositories/user_repository.dart';
import 'package:wags/utility/wagsColor.dart';
class ProfilePage extends StatefulWidget {
final UserRepository userRepository;
const ProfilePage({Key key, this.userRepository}) : super(key: key);
@override
_ProfilePageState createState() => _ProfilePageState();
}
class _ProfilePageState extends State<ProfilePage> {
Widget build(BuildContext context) {
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
if (state is UninitializedProfile) {
return Center(
child: WagsLoader(width: 30, height: 30),
);
} else if (state is ProfileError) {
return Center(
child: Text(
'Recupero delle informazioni utente fallito',
style: TextStyle(
fontFamily: "AvenirNext",
fontSize: 15,
fontWeight: FontWeight.w400,
color: Colors.black,
),
),
);
} else if (state is ProfileLoaded) {
if (state.profile == null) {
return Center(
child: Text(
'Nessuna News trovata',
style: TextStyle(
fontFamily: "AvenirNext",
fontSize: 15,
fontWeight: FontWeight.w400,
color: Colors.black,
),
),
);
}
return Scaffold(
body: SingleChildScrollView(
child: Container(
child: SafeArea(
child: Column(
children: <Widget>[
Container(
padding:
EdgeInsets.symmetric(horizontal: 30, vertical: 20),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Spacer(),
state.profile.image == ""
? Image(
width: 180,
height: 180,
image: AssetImage(
"assets/profilo_placeholder.png"),
fit: BoxFit.cover,
)
: ClipRRect(
borderRadius:
BorderRadius.circular(90.0),
child: FadeInImage.memoryNetwork(
fit: BoxFit.cover,
width: 180,
height: 180,
placeholder: kTransparentImage,
image:
'https://projectinvictus.azurewebsites.net/userImage/${state.profile.uid}/${state.profile.image}',
),
),
Spacer(),
],
),
SizedBox(
height: 15,
),
state.profile.isWannabe
? Container(
margin: EdgeInsets.only(
bottom: 20,
),
child: Column(
children: <Widget>[
Row(
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.end,
children: <Widget>[
Image(
width: 31,
height: 34,
image: AssetImage(
"assets/wannabe_placeholder.png"),
fit: BoxFit.cover,
),
SizedBox(
width: 5,
),
Text(
"Wannabe",
style: TextStyle(
fontFamily: "AvenirNext",
fontSize: 20,
fontWeight: FontWeight.w700,
color: WagsColor.PrimaryColor,
),
)
],
),
Builder(builder: (context) {
if (state.profile.isWannabe) {
return Container(
margin: EdgeInsets.only(top: 5),
child: Text(
state.profile.isPubblic ? "profilo pubblico" : "profilo privato ",
style: TextStyle(
fontFamily: "AvenirNext",
fontSize: 12,
fontWeight: FontWeight.w400,
color: WagsColor
.PrimaryGreyColor,
),
),
);
} else {
return Container();
}
}),
],
),
)
: Container(),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
state.profile.fullname,
style: TextStyle(
fontFamily: "AvenirNext",
fontSize: 27,
fontWeight: FontWeight.w700,
color: Colors.black,
),
),
SizedBox(
width: 10,
),
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
ProfileEditMainPage(user: state.profile,),
),
);
},
child: Icon(
FontAwesomeIcons.edit,
color: WagsColor.PrimaryColor,
size: 20,
),
),
],
),
SizedBox(
height: 10,
),
Builder(builder: (context) {
if (state.profile.city != "" && state.profile.nationality == "") {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
state.profile.city,
style: TextStyle(
fontFamily: "AvenirNext",
fontSize: 17,
fontWeight: FontWeight.w400,
color: WagsColor.PrimaryGreyColor,
),
),
],
);
} else if (state.profile.city == "" && state.profile.nationality != "") {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
state.profile.nationality,
style: TextStyle(
fontFamily: "AvenirNext",
fontSize: 17,
fontWeight: FontWeight.w400,
color: WagsColor.PrimaryGreyColor,
),
),
],
);
} else if (state.profile.city != "" && state.profile.nationality != "") {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"${state.profile.city}, ${state.profile.nationality}",
style: TextStyle(
fontFamily: "AvenirNext",
fontSize: 17,
fontWeight: FontWeight.w400,
color: WagsColor.PrimaryGreyColor,
),
),
],
);
} else {
return Container();
}
}),
state.profile.description != ""
? Row(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.only(
top: 20, bottom: 20),
child: Text(
state.profile.description,
style: TextStyle(
fontFamily: "AvenirNext",
fontSize: 15,
fontWeight: FontWeight.w400,
color: Colors.black,
),
),
),
],
)
: Container(),
Column(
children: <Widget>[
state.profile.linkInstagram != ""
? Container(
margin: EdgeInsets.only(
bottom: 5,
),
child: Row(
children: <Widget>[
Icon(
FontAwesomeIcons.instagram,
color: Colors.black,
size: 20,
),
SizedBox(
width: 10,
),
Text(
"@${state.profile.linkInstagram}",
style: TextStyle(
fontFamily: "AvenirNext",
fontSize: 15,
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
],
),
)
: Container(),
state.profile.linkFacebook != ""
? Container(
margin: EdgeInsets.only(
bottom: 5,
),
child: Row(
children: <Widget>[
Icon(
FontAwesomeIcons.facebook,
color: Colors.black,
size: 20,
),
SizedBox(
width: 10,
),
Text(
"@${state.profile.linkFacebook}",
style: TextStyle(
fontFamily: "AvenirNext",
fontSize: 15,
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
],
),
)
: Container(),
state.profile.linkTwitter != ""
? Container(
child: Row(
children: <Widget>[
Icon(
FontAwesomeIcons.twitter,
color: Colors.black,
size: 20,
),
SizedBox(
width: 10,
),
Text(
"@${state.profile.linkTwitter}",
style: TextStyle(
fontFamily: "AvenirNext",
fontSize: 15,
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
],
),
)
: Container(),
],
),
],
),
),
Divider(),
Container(
padding:
EdgeInsets.symmetric(horizontal: 30, vertical: 20),
child: Row(
children: <Widget>[
Spacer(),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
"4325",
style: TextStyle(
fontFamily: "AvenirNext",
fontSize: 27,
fontWeight: FontWeight.w600,
color: Colors.black87,
),
),
Text(
"Followers",
style: TextStyle(
fontFamily: "AvenirNext",
fontSize: 12,
fontWeight: FontWeight.w400,
color: WagsColor.PrimaryGreyColor,
),
),
],
),
Spacer(),
Column(
children: <Widget>[
Text(
"7281",
style: TextStyle(
fontFamily: "AvenirNext",
fontSize: 27,
fontWeight: FontWeight.w600,
color: Colors.black87,
),
),
Text(
"Following",
style: TextStyle(
fontFamily: "AvenirNext",
fontSize: 12,
fontWeight: FontWeight.w400,
color: WagsColor.PrimaryGreyColor,
),
),
],
),
Spacer()
],
),
),
Container(
padding: EdgeInsets.only(left: 30, right: 30),
child: Column(
children: <Widget>[
Builder(builder: (context) {
if (state.profile.gender != "Uomo" &&
state.profile.isWannabe == false) {
return SizedBox(
height: 15,
);
} else {
return Container();
}
}),
Builder(builder: (context) {
if (state.profile.gender != "Uomo" &&
state.profile.isWannabe == false) {
return WagsButtonAzure(
buttonText: "Diventa Aspirante WAGS",
onPressed: null,
);
} else {
return Container();
}
}),
Builder(builder: (context) {
if (state.profile.gender != "Uomo" &&
state.profile.isWannabe == false) {
return SizedBox(
height: 15,
);
} else {
return Container();
}
}),
],
),
),
],
),
),
),
),
);
} else {
return Center(
child: WagsLoader(width: 30, height: 30),
);
}
},
);
}
}
I've try this but not work the page profile not reload data:
if (state.isSuccess) {
BlocProvider.of<ProfileBloc>(context).add(UninitializedProfile());
Navigator.of(context).pop();
}
Many thank in advance for help.