What is the best way to pass variable (photoUrl) to a Widget? Adding widget inside state class it says: Only static members can be accessed in initializers.
Changing method to static neither solves my issue.
class _ABState extends State<AB> {
int _selectedPage = 0;
String photoUrl; /* Value set in initState()*/
/* To switch between pages */
final _pageOptions = [
Text('Page 1'),
accountPage(), /* Page 2 */
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: _pageOptions[_selectedPage],
);
}
}
/* Widget outside class requires photoUrl */
Widget accountPage() {
return Container(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photoUrl),
),
),
);
}