I want to use a background image for every page in my Flutter app. Therefore, I want to have a class that I can use to return a BoxDecoration to call it from every new page that I create. For the moment, I'm using a simple global function backgroundImage() that returns a BoxDecoration. Is there a way to have a custom class that I can directly pass to decoration: instead of calling a global function?
BoxDecoration backgroundImage() {
return BoxDecoration(
image: DecorationImage(
image: AssetImage("images/background.png"),
fit: BoxFit.cover,
),
);
}
class HomeScreen extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: backgroundImage(),
child: null /* add child content here */,
),
);
}
}