Can i set a image as a back ground in theme in flutter?

38 views Asked by At

I want to create a custom back ground image for every scaffold created how can i achieve it? I want to use it as theme with image

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
        scaffoldBackgroundColor: const Color(0xFF696969),
        
      ),
      home: const MainScreen(),
    );
  }
}```





when call scaffold i want image back ground for every scaffold made which is included in theme .How can I achieve this
1

There are 1 answers

0
A-E On

You should customize your scaffold in which it can always has an image as a background and a child to represent above that image.

try

class GroundImageScaffold extends StatelessWidget {
  Widget child;
  GroundImageScaffold({super.key,required this.child});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Stack(
          fit: StackFit.expand,
          children: [
            Image.asset('images/1.jpg', fit: BoxFit.cover,),
            child,
          ],
        ),
      ),
    );
  }
}

and the call

GroundImageScaffold(
          child: Center(
              child: Text(
            'Is Image Behind?',
            style: TextStyle(
                fontSize: 24, fontWeight: FontWeight.w500, color: Colors.amber),
          )),
        ),

result

enter image description here