Skip to content

Commit d5531a2

Browse files
committed
Add presets
1 parent 0d7e292 commit d5531a2

3 files changed

Lines changed: 1755 additions & 23 deletions

File tree

example/lib/gallery_page.dart

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
22
import 'package:flutter/services.dart';
33
import 'package:material_palette/material_palette.dart';
44

5-
import 'gallery_presets.dart';
65
import 'shader_cards.dart';
76
import 'shader_card_components.dart';
87

@@ -18,6 +17,7 @@ class _GalleryPageState extends State<GalleryPage> {
1817
Widget build(BuildContext context) {
1918
final screenWidth = MediaQuery.of(context).size.width;
2019
final swatchSize = (screenWidth - 48) / 3;
20+
final presetEntries = presets.values.toList();
2121

2222
return Scaffold(
2323
backgroundColor: backgroundColor,
@@ -34,10 +34,10 @@ class _GalleryPageState extends State<GalleryPage> {
3434
mainAxisSpacing: 8,
3535
crossAxisSpacing: 8,
3636
),
37-
itemCount: galleryPresets.length,
37+
itemCount: presetEntries.length,
3838
itemBuilder: (context, index) {
3939
return _GallerySwatch(
40-
preset: galleryPresets[index],
40+
preset: presetEntries[index],
4141
size: swatchSize,
4242
);
4343
},
@@ -52,7 +52,7 @@ class _GallerySwatch extends StatefulWidget {
5252
required this.size,
5353
});
5454

55-
final GalleryPreset preset;
55+
final ShaderPreset preset;
5656
final double size;
5757

5858
@override
@@ -79,7 +79,7 @@ class _GallerySwatchState extends State<_GallerySwatch> {
7979
child: Padding(
8080
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
8181
child: Text(
82-
widget.preset.name,
82+
widget.preset.displayName,
8383
style: const TextStyle(color: Colors.white, fontSize: 12),
8484
),
8585
),
@@ -108,89 +108,89 @@ class _GallerySwatchState extends State<_GallerySwatch> {
108108

109109
void _copyToClipboard(BuildContext context) {
110110
final paramsCode = PresetGenerator.shaderParams(widget.preset.params);
111-
final clipboardText = '${widget.preset.name}\n\n${widget.preset.shaderType}:\n\n$paramsCode';
111+
final clipboardText = '${widget.preset.displayName}\n\n${widget.preset.shaderName}:\n\n$paramsCode';
112112
Clipboard.setData(ClipboardData(text: clipboardText));
113113
ScaffoldMessenger.of(context).showSnackBar(
114114
SnackBar(
115-
content: Text('Copied "${widget.preset.name}" preset to clipboard'),
115+
content: Text('Copied "${widget.preset.displayName}" preset to clipboard'),
116116
duration: const Duration(seconds: 2),
117117
),
118118
);
119119
}
120120

121121
Widget _buildShaderFill() {
122-
switch (widget.preset.shaderType) {
123-
case 'Turbulence':
122+
switch (widget.preset.shaderName) {
123+
case ShaderNames.turbulence:
124124
return TurbulenceGradientShaderFill(
125125
width: widget.size, height: widget.size, params: widget.preset.params,
126126
animationMode: ShaderAnimationMode.continuous, cache: true,
127127
);
128-
case 'Turbulence Radial':
128+
case ShaderNames.radialTurbulence:
129129
return RadialTurbulenceGradientShaderFill(
130130
width: widget.size, height: widget.size, params: widget.preset.params,
131131
animationMode: ShaderAnimationMode.continuous, cache: true,
132132
);
133-
case 'FBM':
133+
case ShaderNames.fbm:
134134
return FbmGradientShaderFill(
135135
width: widget.size, height: widget.size, params: widget.preset.params,
136136
animationMode: ShaderAnimationMode.continuous, cache: true,
137137
);
138-
case 'FBM Radial':
138+
case ShaderNames.radialFbm:
139139
return RadialFbmGradientShaderFill(
140140
width: widget.size, height: widget.size, params: widget.preset.params,
141141
animationMode: ShaderAnimationMode.continuous, cache: true,
142142
);
143-
case 'Simplex':
143+
case ShaderNames.simplex:
144144
return SimplexGradientShaderFill(
145145
width: widget.size, height: widget.size, params: widget.preset.params,
146146
animationMode: ShaderAnimationMode.continuous, cache: true,
147147
);
148-
case 'Simplex Radial':
148+
case ShaderNames.radialSimplex:
149149
return RadialSimplexGradientShaderFill(
150150
width: widget.size, height: widget.size, params: widget.preset.params,
151151
animationMode: ShaderAnimationMode.continuous, cache: true,
152152
);
153-
case 'Perlin':
153+
case ShaderNames.perlin:
154154
return PerlinGradientShaderFill(
155155
width: widget.size, height: widget.size, params: widget.preset.params,
156156
animationMode: ShaderAnimationMode.continuous, cache: true,
157157
);
158-
case 'Perlin Radial':
158+
case ShaderNames.radialPerlin:
159159
return RadialPerlinGradientShaderFill(
160160
width: widget.size, height: widget.size, params: widget.preset.params,
161161
animationMode: ShaderAnimationMode.continuous, cache: true,
162162
);
163-
case 'Voronoi':
163+
case ShaderNames.voronoi:
164164
return VoronoiGradientShaderFill(
165165
width: widget.size, height: widget.size, params: widget.preset.params,
166166
animationMode: ShaderAnimationMode.continuous, cache: true,
167167
);
168-
case 'Voronoi Radial':
168+
case ShaderNames.radialVoronoi:
169169
return RadialVoronoiGradientShaderFill(
170170
width: widget.size, height: widget.size, params: widget.preset.params,
171171
animationMode: ShaderAnimationMode.continuous, cache: true,
172172
);
173-
case 'Voronoise':
173+
case ShaderNames.voronoise:
174174
return VoronoiseGradientShaderFill(
175175
width: widget.size, height: widget.size, params: widget.preset.params,
176176
animationMode: ShaderAnimationMode.continuous, cache: true,
177177
);
178-
case 'Voronoise Radial':
178+
case ShaderNames.radialVoronoise:
179179
return RadialVoronoiseGradientShaderFill(
180180
width: widget.size, height: widget.size, params: widget.preset.params,
181181
animationMode: ShaderAnimationMode.continuous, cache: true,
182182
);
183-
case 'Grit':
183+
case ShaderNames.gritient:
184184
return GrittyGradientShaderFill(
185185
width: widget.size, height: widget.size, params: widget.preset.params,
186186
animationMode: ShaderAnimationMode.continuous, cache: true,
187187
);
188-
case 'Grit Radial':
188+
case ShaderNames.radient:
189189
return RadialGrittyGradientShaderFill(
190190
width: widget.size, height: widget.size, params: widget.preset.params,
191191
animationMode: ShaderAnimationMode.continuous, cache: true,
192192
);
193-
case 'Smarble':
193+
case ShaderNames.smarble:
194194
return MarbleSmearShaderFill(
195195
width: widget.size, height: widget.size, params: widget.preset.params,
196196
backgroundColor: const Color(0xFF202329), interactive: false,

lib/material_palette.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export 'package:material_palette/src/shader_wrap.dart';
77
export 'package:material_palette/src/shader_definitions.dart';
88
export 'package:material_palette/src/shader_registry.dart';
99
export 'package:material_palette/src/shader_material.dart';
10+
export 'package:material_palette/src/shader_presets.dart';
1011

1112
// Gradient fills (linear)
1213
export 'package:material_palette/src/shaders/gritty_gradient_shader_fill.dart';

0 commit comments

Comments
 (0)