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).
CodePudding user response:
Create a class, define the function getKey() inside the class. Then import the file where the Class is created. Then Use ClassName.getKey() syntax.
CodePudding user response:
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.
getData(
final key = getKey():
// then the key stored key variable
// then use key in api call
)