Open In App

Flutter – Inner Shadow Effect

Last Updated : 30 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

If you want to give the inner shadow effect in your flutter application you can use the Box shadow property of the Box Decoration. A sample image is given below to get an idea about what we are going to do in this article.

Flutter - Inner Shadow Effect

 

How to use?

You can use the Box shadow property of the container to make the inner shadow effect.

Container(
          child: Center(child: Text('Geeks for Geeks')),
          height: 100,
          width: 250,
          decoration: BoxDecoration(
                 boxShadow: [
                   BoxShadow(
                     color: Colors.green,
                   ),
                   BoxShadow(
                     color: Colors.white70,
                     spreadRadius: -5.0,
                     blurRadius: 20.0,
                   ),
                 ],
               ),
             ),

Step By Step Implementation

Step 1: Create a New Project in Android Studio

To set up Flutter Development on Android Studio please refer to Android Studio Setup for Flutter Development, and then create a new project in Android Studio please refer to Creating a Simple Application in Flutter.

Step 2: Add the Material package that gives us the important methods and then call the runApp method in the main function that will call our application.

import 'package:flutter/material.dart';
void main() {
runApp(RunMyApp());
}

Step 3: Now we have to make a stateless widget named RunMyApp Because our application does not go to change its state and then return the MaterialApp widget which allows us the set the title and theme and many more.

class RunMyApp extends StatelessWidget {
const RunMyApp({super.key});
@override
Widget build(BuildContext context) {
  return MaterialApp(home:);
}
}

Step 4: Give the home property and there can be a scaffold widget that has the property of AppBar and body. AppBar allows us to give the title of AppBar, color, leading, and trailing icon. Body contains the Container and has a child Text. We can decorate the container using Box Decoration, Box Decoration further has the box shadow to give the inner shadow effect.

 BoxShadow(
           color: Colors.white70,
           spreadRadius: -5.0,
           blurRadius: 20.0,
    ),

Final Code  

The final code has the column widget that allows to have multiple widgets and has an example of rectangle, rounded corner rectangle, and circular containers.

Dart




import 'package:flutter/material.dart';
  
void main() {
  runApp(RunMyApp());
}
  
class RunMyApp extends StatelessWidget {
  const RunMyApp({super.key});
  
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(primarySwatch: Colors.green),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: Text('Inner Shadow Effect'),
        ),
        body: Center(
          child: Column(
              
            children: [
              SizedBox(height: 50,),
              Container(
                child: Center(child: Text('Geeks for Geeks')),
                height: 100,
                width: 250,
                decoration: BoxDecoration(
                  boxShadow: [
                    BoxShadow(
                      color: Colors.green,
                    ),
                    BoxShadow(
                      color: Colors.white70,
                      spreadRadius: -5.0,
                      blurRadius: 20.0,
                    ),
                  ],
                ),
              ),
              SizedBox(
                height: 50,
              ),
              Container(
                child: Center(child: Text('Geeks for Geeks')),
                height: 100,
                width: 250,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(20),
                  boxShadow: [
                    BoxShadow(
                      color: Colors.green,
                    ),
                    BoxShadow(
                      color: Colors.white70,
                      spreadRadius: -5.0,
                      blurRadius: 20.0,
                    ),
                  ],
                ),
              ),
              SizedBox(
                height: 50,
              ),
              Container(
                child: Center(child: Text('Geeks for Geeks')),
                height: 100,
                width: 100,
                decoration: BoxDecoration(
                  borderRadius:BorderRadius.circular(50) ,
                  boxShadow: [
                    BoxShadow(
                      color: Colors.green,
                    ),
                    BoxShadow(
                      color: Colors.white70,
                      spreadRadius: -5.0,
                      blurRadius: 20.0,
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}


Output:

Flutter - Inner shadow Effect

 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads