Home > OS >  How to set different background images for dark and light mode? (flutter)
How to set different background images for dark and light mode? (flutter)

Time:11-02

I want to set different app background images for dark and light theme and I want them to change according to the system theme.

I am also using a flutter package adaptive_theme: ^3.1.1 to change between dark and light theme as per system mode.

my code for app background image:

return SafeArea(
  child: Container(
     decorarion: BoxDecoration(
       image: DecorationImage(
          image: AssetImage('/path'),
         ),
       fit: BoxFit.cover
    ),
    child: Scaffold(...),
  ),
);

How to implement the package I have to achieve my desired result or is there any other way around?

CodePudding user response:

You can probably infer the right background like this.

Theme.of(context).brightness == Brightness.light ? AssetImage('/path/light') : AssetImage('/path/dark')
  • Related