color_mesh
1.0.2, released 2 years ago by hamzahayak.dev
A multi-point mesh gradient that extends Gradient and can be used in decorations and animations.
What it does
Provides a MeshGradient class that works similarly to RadialGradient and LinearGradient, supporting up to 8 colors with customizable offsets, strengths, and sigmas. It also includes MeshGradientContainer and AnimatedMeshGradientContainer widgets for building static or animated mesh gradient backgrounds.
AI-written summary of version 1.0.2, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want to add multi-point mesh gradients to your Flutter app UI.
- You need an animated gradient background that shuffles colors periodically.
- You want to use a custom gradient inside standard decorations like BoxDecoration.
Skip it when
- You are running on Android emulators using Impeller OpenGLES where the shader is currently not working.
- You prefer simple linear or radial gradients built natively into Flutter without shaders.
Strengths
- Supports up to 8 colors with configurable offsets, strengths, and sigmas.
- Supports lerping for smooth animations with BoxDecoration and AnimatedContainer.
- Includes ready-to-use container widgets for quick implementation.
Weaknesses
- Requires shader precaching or initialization at app startup.
- Shader compatibility issues on certain configurations like Impeller OpenGLES on Android emulators.
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
Call await MeshGradient.precacheShader() at app startup in main().
Future<void> main() async {
await MeshGradient.precacheShader();
runApp(const MyApp());
}
class MyMeshContainer extends StatelessWidget {
const MyMeshContainer({super.key});
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
gradient: MeshGradient(
colors: const [
Colors.red,
Colors.green,
Colors.yellow,
Colors.blue,
],
offsets: const [
Offset(0, 0),
Offset(0, 1),
Offset(1, 0),
Offset(1, 1),
],
strengths: const [1, 1, 1, 1],
sigmas: const [0.3, 0.2, 0.3, 0.25],
),
),
);
}
}Alternatives
Packages that do the same job and could replace color_mesh.
- flutter_color
Flutter plugin for working with color schemes like hex, hsl, xyz, and cielab.
82Compare - enhanced_gradients
Flutter gradient wrappers that interpolate colors in the HCT color system.
71Compare - derived_colors
Generate color variants and modifications for Flutter applications.
50Compare - oklch
Encode, decode, and pick colors using the OKLCH color space in Flutter apps.
58Compare