I am new to flutter .Here I stored a value to a variable doc_id
,I want to use this value in another file called comments.dart . So I did something like below but it gives null value in comment.dart .
await FirebaseFirestore.instance
.collection('blogs')
.add({
'title': titleController.text,
}).then((value) {
doc_id = value.id;
comment(postid: docid);
successAlert(context);
}).catchError((error) =>
errorAlert(context));
Comment.dart
class comment extends StatefulWidget {
final String? postid;
const comment({Key? key, this.postid}) : super(key: key);
_commentState createState() => _commentState();
}
class _commentState extends State<comment> {
@override
Widget build(BuildContext context) {
return
Text(widget.postid);
}
}
2
Answers
Just create a global variable and assign from there
Finally assign the value
Finally use it in your class