I am working with API keys and I need to be able to access the same unique API from two different screens. Basically, I need the dataKey variable in both screens, and I get the dataKey variable from the getKey() function, which has a get method that fetches the key. Right now the getKey() function is in one of the files (todolist.dart), but I don’t know how to access it from my other file (add_new_item.dart).
Question posted in Android Studio
The official documentation can be found here.
The official documentation can be found here.
2
Answers
Trying to understand the question. I think if you need to access the API key in the second screen or which ever screen.
You can use the “import” statement to import the file where the API keys are, (that’s if it’s not in a widget class).
Then access it normally where you’ll need it.
Like.
Create a class, define the function getKey() inside the class. Then import the file where the Class is created. Then Use ClassName.getKey() syntax.