gonuit / gauge_indicator

MIT License
29 stars 12 forks source link

Assertion Error for circle pointer to have color or gradient #9

Open kyeshmz opened 1 year ago

kyeshmz commented 1 year ago

The error

_AssertionError ('package:gauge_indicator/src/radial_gauge/pointers/circle_pointer.dart': Failed assertion: line 36 pos 11: '(color != null && gradient == null) ||
              (gradient != null && color == null)': Either color or gradient must be provided.)

can we make color required and pass a gradient to that?

The code

import 'package:flutter/material.dart';
import 'package:gauge_indicator/gauge_indicator.dart';

class AttendanceGauge extends StatelessWidget {
  const AttendanceGauge({super.key});

  @override
  Widget build(BuildContext context) {
    // Create animated radial gauge.
    // All arguments changes will be automatically animated.
    return SizedBox(
      width: 200,
      height: 200,
      child: AnimatedRadialGauge(
        /// The animation duration.
        duration: const Duration(seconds: 1),
        curve: Curves.elasticOut,

        /// Gauge value.
        value: 0.3,

        /// Optionally, you can configure your gauge, providing additional
        /// styles and transformers.
        axis: GaugeAxis(
          max: 100,

          pointer: GaugePointer.circle(radius: 0),

          // pointer: const GaugePointer.(
          //   width: 100,
          //   height: 100,
          //   color: Colors.red,
          //   // size: Size(16, 100),
          //   // borderRadius: 16,
          //   // backgroundColor: Color(0xFF193663),
          // ),

          /// Set the background color and axis thickness.
          style: const GaugeAxisStyle(
            background: Color(0xFFDFE2EC),
            segmentSpacing: 4,
          ),

          /// Define the progress bar (optional).
          progressBar: const GaugeProgressBar.rounded(
            color: Color(0xFFB4C2F8),
          ),

          /// Define axis segments (optional).
          segments: [
            GaugeSegment(
              from: 0,
              to: 33.3,
              color: Theme.of(context).colorScheme.primary,
            ),
            GaugeSegment(
              from: 33.3,
              to: 66.6,
              color: Theme.of(context).colorScheme.error,
            ),
            const GaugeSegment(
              from: 66.6,
              to: 100,
              color: Color(0xFFD9DEEB),
            ),
          ],

          /// 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,
          ///  ),
          /// ),
          /// ```
          ///
        ),
      ),
    );
  }
}
gonuit commented 1 year ago

The problem with your code is that you use the GaugePointer class, but you don't give it a color or gradient, so it can't draw the pointer correctly. If you don't want a pointer, just pass a null value to the pointer argument.

Let me know if this solves your problem.