A Flutter widget for creating interactive 3D lighting effects, providing an immersive visual experience with customizable light sources and dynamic shadows.
- Two lighting modes: parallel and radial lighting
- Interactive light source position control
- Customizable lighting parameters (intensity, radius, etc.)
- Beautiful light source indicator and guide lines
- Adjustable dark areas
- Circular border effect
Add this dependency to your pubspec.yaml
file:
dependencies:
flutter_3d_effect: ^1.0.0
The simplest way to use the widget:
Light3DEffect(
size: 300,
imagePath: 'assets/images/your_image.png',
)
Example with full customization:
Light3DEffect(
size: 300,
imagePath: 'assets/images/your_image.png',
backgroundColor: Colors.black,
lightType: LightType.parallel,
lightIntensity: 0.95,
lightRadius: 0.8,
darkIntensity: 0.2,
showIndicator: true,
indicatorSize: 24,
showIndicatorLine: true,
showBorder: true,
onPositionChanged: (x, y) {
print('Light position changed: ($x, $y)');
},
)
size
: Widget size (square)imagePath
: Path to the image resourcebackgroundColor
: Background color of the widget
lightType
: Type of light source (parallel/radial)lightIntensity
: Intensity of the light effect (0.0 to 1.0)lightRadius
: Radius of the light effect (0.0 to 1.0)darkIntensity
: Intensity of dark areas (0.0 to 1.0)
showIndicator
: Toggle light source indicator visibilityindicatorSize
: Size of the light source indicatorindicatorColor
: Color of the light source indicatorindicatorOpacity
: Opacity of the light source indicator
showIndicatorLine
: Toggle guide line visibilityindicatorLineColor
: Color of the guide lineindicatorLineWidth
: Width of the guide lineindicatorLineDashWidth
: Width of guide line dashesindicatorLineDashSpace
: Space between guide line dashes
showBorder
: Toggle border visibilityborderColor
: Color of the borderborderWidth
: Width of the border
- Add the widget to your project
- Configure image assets in
pubspec.yaml
:
flutter:
assets:
- assets/images/
Here's a complete example showing how to implement the 3D light effect in your app:
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(
backgroundColor: Colors.black,
body: Center(
child: Light3DEffect(
size: 300,
imagePath: 'assets/images/sample.png',
lightType: LightType.parallel,
lightIntensity: 0.95,
onPositionChanged: (x, y) {
print('Light position: ($x, $y)');
},
),
),
),
);
}
}
- The widget maintains a square aspect ratio (width equals height)
- Light source position can be adjusted by dragging
- Image resources must be properly configured in
pubspec.yaml
- The widget works best with images that have clear subjects and good contrast
Contributions are welcome! If you find a bug or want to add a new feature:
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.