I need To pass Data to Another flutter Page without navigating
Eg: in page 1 have a button clicking this button should store into selecteddocumentedId
so this documentid can i use in any another flutter page so i can get the data
class _EeachWorkModelState extends State<EeachWorkModel> {
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () {},
In this on tap
widget.prolist['doc_id']
this should be passed without navigating to another screen
2
Answers
Use a persistent storage maybe like shared_preferences
Page one, on button event you set a value using a key and on any other page you read it using same key.
If you want the ID value to persist even after closing and reopening the app – between app sessions, you need to use shared preference, as described by the earlier contributor.
Otherwise, you might need to use state management to effectively store the state (i.e. the selectedDocumentID), such as Riverpod or GetIt.
I personally use Riverpod, and here’s how it will work in Riverpod.
You will first need to add flutter_riverpod package to you pubspec.yaml
Read the full initial setup by reading through this highly recommended article. Particularly note the ProviderScope, using ConsumerWidget, Using Consumer and Using ConsumerStatefulWidget & ConsumerState sections.
Presuming the ID is a String, you can simply use state provider, initiate the ID value as empty String ” as below
Then set the document ID value by using
And read the value anywhere within consumer widget using
If your selectedDocumentID is a complex object, or you need to implement a number of methods to the class, you should consider using notifier Provider instead of state provider.