Let's is how to add shadow to a container in flutter.
Here is the output of this example. You can observe the shadow below the container.
For achieving this, we can use PhysicalModel widget. This widget representing a physical layer that clips its children to a shape.
Here is the complete code from main.dart file for this example.
import 'package:flutter/material.dart';
void main(List<String> args) {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@
override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: MyLayoutWidget(),
),
);
}
}
class MyLayoutWidget extends StatelessWidget {
const MyLayoutWidget({
super.key,
});
@
override
Widget build(BuildContext context) {
return Center(
child: PhysicalModel(
color: Colors.black,
shadowColor: Colors.blue,
elevation: 20.0,
child: Container(
height: 100,
width: 100,
color: Colors.blue,
),
),
);
}
}
Thanks,Srikanth