How can I send "records" variable to another screen?
Asked
Active
Viewed 79 times
1

padaleiana
- 955
- 1
- 14
- 23
-
Does this answer your question? [Passing data to StatefulWidget and accessing it in it's state in Flutter](https://stackoverflow.com/questions/50287995/passing-data-to-statefulwidget-and-accessing-it-in-its-state-in-flutter) – bartektartanus Feb 07 '23 at 11:52
2 Answers
1
if you have a SecondScreen()
you can pass data to it when you navigate to it from it's constructor like this
class SecondScreen extendsS StatelessWidget {
SecondScreen(this.gotRecords);
final Box? gotRecords;
/* more code*/
}
and now when you try to navigate pass that records
in that constructor like this :
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const SecondScreen(gotRecords:records)),
);
and from that screen you can use it.

Gwhyyy
- 7,554
- 3
- 8
- 35
1
another solution is to just call the box wherever you want by its name
I see that your Hive box is called Details, so wherever you want to use that same box, just call simply from any screen in your app:
Box? records = Hive.box("Details");

Gwhyyy
- 7,554
- 3
- 8
- 35