Options constructor

Options({
  1. double tension = 0.45,
  2. double width = 50,
  3. double height = 20,
  4. double hoverFactor = -0.3,
  5. double gap = 5,
  6. double forceFactor = 0.15,
  7. double forceFactorBuild = 1,
  8. double forceFactorOnTap = 1,
  9. int stepRedrawing = 2,
  10. List<LayerModel>? layers,
  11. List<TouchModel>? touches,
  12. List<int>? layerNumbers,
  13. List<double>? scaleOptionLayer,
  14. double noise = 0,
})

Options - powerful customization engine for fluid physics widget

  • Example of a Minimum Liquid Effect Setting
  final options = Options(
    layers: [
      LayerModel(
        points: [],
        viscosity: 0.9,
        touchForce: 30,
        forceLimit: 15,
        color: const Color(0xFF00FF00),
      ),
    ],
    gap: 15,
    noise: 5,
    forceFactorBuild: 10,
    forceFactorOnTap: 150,
  );
  • Use options
Widget _buildLiquidButton() {
  return LiquidContainer(
    onTap: () {
      // same code
    },
    optionsParam: options,
    child: const SizedBox(
      height: 80,
      width: 300,
    ),
  );
}

Implementation

Options({
  this.tension = 0.45,
  this.width = 50,
  this.height = 20,
  this.hoverFactor = -0.3,
  this.gap = 5,
  this.forceFactor = 0.15,
  this.forceFactorBuild = 1,
  this.forceFactorOnTap = 1,
  this.stepRedrawing = 2,
  List<LayerModel>? layers,
  List<TouchModel>? touches,

  /// To draw layers
  List<int>? layerNumbers,

  /// Scale object size at each level, independent of layer order
  List<double>? scaleOptionLayer,
  this.noise = 0,
})  : layers = layers ??
          [
            LayerModel(
              points: [],
              viscosity: 0.5,
              touchForce: 100,
              forceLimit: 2,
            ),
            LayerModel(
              points: [],
              viscosity: 0.8,
              touchForce: 150,
              forceLimit: 3,
            ),
          ],
      touches = touches ?? [] {
  assert(stepRedrawing > 0);
  this.layerNumbers =
      layerNumbers ?? List.generate(this.layers.length, (index) => index);
  layerScales =
      scaleOptionLayer ?? List.generate(this.layers.length, (index) => 1.0);
}