This is Textformfield. It receives the value and then displays the information through it. TextEditContoller
This is page 1
Widget lngTextFormField(String label, String keyword, String text) {
TextEditingController lngtextController = TextEditingController(text: text);
lngtextController.selection = TextSelection.collapsed(offset: lngtextController.text.length);
return TextFormField(
controller: lngtextController,
onChanged: (value) {
saveAd(value, keyword);
},
decoration: InputDecoration(
labelText: label,
labelStyle: TextStyle(
fontFamily: 'supermarket',
fontSize: 16,
),
isDense: true,
),
);
}
This is a page 2 This is a save button that will return lat,lng to page 1.
void saveAddress() {
var lat = centerMap.latitude;
var lng = centerMap.longitude;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => EditAddressPage(
index: widget.index,
lat: lat.toString(),
lng: lng.toString(),
),
),
);
print("Saving address: Latitude: $lat, Longitude: $lng");
}
what can i do I want to send the second page lat,lng values back to page 1 instead of the existing values. I tried this, sometimes the value is sent but the original value is empty before the new value is sent. Maybe need to type something in TextFormfield before being able to save
There are a lot of option to do, but the one of the easiest is :
//you can use this
//or this
after 2nd page open and button pressed, you need to pass string to 1st page using Navigator.push (you have done it well)
inside initstate of the 1st page make a condition, example
this logic means that when the 1st page created they will set the value first before build()