In Flutter, you can use the BoxShadow
class – child property of Container to create a shadows effect around an icon or shadow property for – inside the icon. Here’s a simple example:
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Flutter Icon Shadow')),
body: Center(
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.5),
blurRadius: 10,
spreadRadius: 5,
offset: const Offset(5, 5),
),
],
),
child: const Padding(
padding: EdgeInsets.all(20.0),
child: Icon(
Icons.flutter_dash,
size: 100,
color: Colors.blue,
),
),
),
),
),
);
}
}
Explanation:
- A
Container
is wrapped around the icon. - The
BoxDecoration
property is used to define the shadow withBoxShadow
. - You can customize the shadow color, blur radius, spread radius, and offset.
The above code creates shadow arround the full icon:
To have shadow behind the icon itself, you could use the property shadows of the Icon.
body: Center( child: const Padding( padding: EdgeInsets.all(20.0), child: Icon( Icons.flutter_dash, size: 500, color: Colors.blue, shadows: [ Shadow( color: Colors.blue, offset: const Offset(0 ,3), blurRadius: 15.0) ], ), ), ),
Let me know if you’d like to modify this or need additional effects!