build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Describes the part of the user interface represented by this widget.

The framework calls this method when this widget is inserted into the tree in a given BuildContext and when the dependencies of this widget change (e.g., an InheritedWidget referenced by this widget changes). This method can potentially be called in every frame and should not have any side effects beyond building a widget.

The framework replaces the subtree below this widget with the widget returned by this method, either by updating the existing subtree or by removing the subtree and inflating a new subtree, depending on whether the widget returned by this method can update the root of the existing subtree, as determined by calling Widget.canUpdate.

Typically implementations return a newly created constellation of widgets that are configured with information from this widget's constructor and from the given BuildContext.

The given BuildContext contains information about the location in the tree at which this widget is being built. For example, the context provides the set of inherited widgets for this location in the tree. A given widget might be built with multiple different BuildContext arguments over time if the widget is moved around the tree or if the widget is inserted into the tree in multiple places at once.

The implementation of this method must only depend on:

If a widget's build method is to depend on anything else, use a StatefulWidget instead.

See also:

  • StatelessWidget, which contains the discussion on performance considerations.

Implementation

@override
Widget build(BuildContext context) {
  return AnimatedRadialGauge(
    /// The animation duration.
    duration: const Duration(seconds: 5),
    curve: Curves.elasticOut,

    /// Define the radius.
    /// If you omit this value, the parent size will be used, if possible.
    radius: Dimens.space150,

    /// Gauge value.
    value: percentage,

    /// Optionally, you can configure your gauge, providing additional
    /// styles and transformers.
    axis: GaugeAxis(
      /// Provide the [min] and [max] value for the [value] argument.
      min: 0,
      max: 100,

      /// Render the gauge as a 180-degree arc.
      degrees: 250,

      /// Set the background color and axis thickness.
      style: GaugeAxisStyle(
        thickness: Dimens.space30,
        background: Palette.azureishWhite,
        cornerRadius: Radius.circular(Dimens.space16),
      ),

      /// Define the pointer that will indicate the progress (optional).
      pointer: GaugePointer.needle(
        borderRadius: Dimens.space40,
        width: Dimens.space20,
        height: Dimens.space100,
        color: Palette.newCar,
      ),

      /// Define the progress bar (optional).
      progressBar: const GaugeProgressBar.rounded(
        gradient: GaugeAxisGradient(
          colors: [
            Palette.lightCobaltBlue,
            Palette.persianBlue,
          ],
        ),
      ),

      /// Define axis segments (optional).
      // segments: const [
      //   GaugeSegment(
      //     from: 0,
      //     to: 33.3,
      //     color: Palette.azureishWhite,
      //     cornerRadius: Radius.circular(16),
      //   ),
      //   GaugeSegment(
      //     from: 33.3,
      //     to: 66.6,
      //     color: Palette.azureishWhite,
      //     cornerRadius: Radius.circular(16),
      //   ),
      //   GaugeSegment(
      //     from: 66.6,
      //     to: 100,
      //     color: Palette.azureishWhite,
      //     cornerRadius: Radius.circular(16),
      //   ),
      // ],
    ),
  );

  /// You can also, define the child builder.
  /// You will build a value label in the following way, but you can use the widget of your choice.
  ///
  /// For non-value related widgets, take a look at the [child] parameter.
  /// ```
  /// builder: (context, child, value) => RadialGaugeLabel(
  ///  value: value,
  ///  style: const TextStyle(
  ///    color: Colors.black,
  ///    fontSize: 46,
  ///    fontWeight: FontWeight.bold,
  ///  ),
  /// ),
  /// ```
  // );
}