How to get data from previous page when using stateful String link. Is it possible to get string from another file in stateful? I need to get the string from another file b into the stateful of file a. In case of stateless this was possible, but in stateful it is not possible.
Is there a way to solve this?
CodePudding user response:
I hate to disagree but using global variables in this situation when you can fix your problem easily is not wise although it works and it is very easy.
if you want to send data to another page via pushing a new page you can always use that newPage Constructor
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BalancePage(
items: "item",
),
),
);
New Page
class BalancePage extends StatefulWidget {
String? items;
BalancePage({
this.items,
});
@override
_BalancePageState createState() => _BalancePageState();
}
if you want to take data from another class you can set a getter
class newVal(){
String val ="ss";
String getVal(){
return val;
}
}
and you can call it anywhere like this
String ss = newVal().getVal;