I created new document on FirstPage and I can print his docAtricle.id (auto id created in firestore database). I can’t pass this object to Secound Page. I tried few metods but without any results. I would like to put it as a value to the next page
class NewTravelPageInformation extends StatelessWidget {
NewTravelPageInformation({super.key, required this.value});
final TextEditingController nameOfTheTravel = TextEditingController();
final TextEditingController descriptionOfTheTravel = TextEditingController();
final String value;
@override
onPressed: () {
createNewArticle(nameOfTheArticle: name, descriptionOfTheArticle: description);
Navigator.pushNamed(context, '/secoundpage');
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => SecoundPage(value : value),),);
.
.
.
Future createNewArticle({required String nameOfTheArticle, required descriptionOfTheArticle }) async {
final docArticle = FirebaseFirestore.instance.collection('users').doc(user.uid).collection('Articles').doc();
// Create document and write data to Firebase
await docArticle.set({
'name': nameOfTheArticle,
'description': descriptionOfTheArticle,
'Article_id': docArticle.id,
'user_id': user.uid,
});
// print the id of the created Article
print(docArticle.id);
In the first Page I command that he need to create New Document and now I would like to get this docArticle.id and pass it to Secound Page becouse I would like create new collection “Information” in this document
class SecoundPage extends StatefulWidget {
String value;
SecoundPage({super.key, required this.value});
@override
State<SecoundPage> createState() => _SecoundPage(value);
}
class _SecoundPage extends State<SecoundPage> {
String value;
_SecoundPage(this.value);
Future createNewInformation({required String nameOfTheInformation, required descriptionOfTheInformation}) async {
final docInformations = FirebaseFirestore.instance.collection('users').doc(user.uid)
.collection('Articles').doc(widget.value).collection('Informations').doc();
await docInformations.set({
'name': nameOfTheInformation,
'description': descriptionOfTheInformation,
});
}
Is my method correct and how to pass object docArticle.id ??
Przemysław is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.