CustomConfig constructor

CustomConfig({
  1. List<Color>? colors,
  2. List<List<Color>>? gradients,
  3. Alignment? gradientBegin,
  4. Alignment? gradientEnd,
  5. required List<int>? durations,
  6. required List<double>? heightPercentages,
  7. MaskFilter? blur,
})

Creates explicit wave layers from colors or gradients.

Provide exactly one of colors or gradients. The configured layer lists must have equal lengths, and each gradient must contain at least two colors.

Implementation

CustomConfig({
  List<Color>? colors,
  List<List<Color>>? gradients,
  this.gradientBegin,
  this.gradientEnd,
  required List<int>? durations,
  required List<double>? heightPercentages,
  this.blur,
})  : colors = colors,
      gradients = gradients,
      durations = durations,
      heightPercentages = heightPercentages,
      super(colorMode: ColorMode.custom) {
  if (colors == null && gradients == null) {
    Config.throwNullError('custom', 'colors` or `gradients');
  }
  if (colors != null && gradients != null) {
    throw FlutterError('Cannot provide both `colors` and `gradients`.');
  }
  if (durations == null) {
    Config.throwNullError('custom', 'durations');
  }
  if (heightPercentages == null) {
    Config.throwNullError('custom', 'heightPercentages');
  }
  final resolvedDurations = durations!;
  final resolvedHeightPercentages = heightPercentages!;
  Config._resolveLayerCount(
    'CustomConfig',
    colors: colors,
    gradients: gradients,
    durations: resolvedDurations,
    heightPercentages: resolvedHeightPercentages,
  );
  Config._validateDurations(resolvedDurations);
  Config._validateHeightPercentages(resolvedHeightPercentages);
  if (gradients == null && (gradientBegin != null || gradientEnd != null)) {
    throw FlutterError(
        'You set a gradient direction but forgot setting `gradients`.');
  }
  if (colors != null && colors.isEmpty) {
    throw FlutterError('`colors` must define at least one layer.');
  }
  if (gradients != null) {
    for (final gradient in gradients) {
      if (gradient.length < 2) {
        throw FlutterError(
            'Every gradient in `gradients` must have at least two colors.');
      }
    }
  }
}