FormRatingBar<TValue> constructor

FormRatingBar<TValue>({
  1. FormController<TValue>? form,
  2. FormStyle? style,
  3. bool keepAlive = true,
  4. TextEditingController? controller,
  5. int iconCount = 5,
  6. double iconSize = 40.0,
  7. bool readOnly = false,
  8. void onChanged(
    1. double? value
    )?,
  9. Color? activeColor,
  10. Color? inactiveColor,
  11. double? min,
  12. double? max,
  13. Widget iconBuilder(
    1. BuildContext context,
    2. int index
    )?,
  14. bool allowHalfRating = true,
  15. bool tapOnlyMode = false,
  16. Axis direction = Axis.horizontal,
  17. bool showLabel = false,
  18. Widget? icon,
  19. String format = "0.#",
  20. Key? key,
  21. String? emptyErrorText,
  22. TValue onSaved(
    1. double value
    )?,
  23. String validator(
    1. double? value
    )?,
  24. num? initialValue,
  25. bool enabled = true,
})

Widget to display & edit by number of stars by passing double.

Can be used to evaluate users and articles.

iconCount allows you to specify the number of icons. The icon widget itself can be specified with icon, and the design can be changed by specifying iconSize, activeColor, and inactiveColor. Also, if iconBuilder is specified, the icon can be created in a callback.

The minimum and maximum values can be specified with min and max.

You can specify whether to allow half stars with allowHalfRating.

Normally, the value can be changed by dragging, but tapOnlyMode allows the value to be specified only by tapping.

If showLabel is specified, the actual value can be displayed as a numerical value.

Place under the Form that gave FormController.key, or pass FormController to form.

When FormController is passed to form, onSaved must also be passed together. The contents of onSaved will be used to save the data.

Enter the initial value given by FormController.value in initialValue.

Each time the content is changed, onChanged is executed.

If FormController.validate is executed, validation and data saving are performed.

Only when emptyErrorText is specified, emptyErrorText will be displayed as an error if no characters are entered.

Other error checking is performed by specifying validator. If a string other than Null is returned in the callback, the string is displayed as an error statement. If Null is returned, it is processed as no error.

If enabled is false, the text is deactivated.

If readOnly is set to true, it will show enabled, but the value cannot be changed.

doubleを渡して星の数で表示&編集するためのウィジェット。

ユーザーや記事の評価に使用可能です。

iconCountを使用するとアイコンの数を指定できます。iconでアイコンウィジェットそのものを指定でき、iconSizeactiveColorinactiveColorを指定するとデザインを変更することができます。また、iconBuilderを指定するとコールバックでアイコンを作成可能です。

minmaxで値の最小値、最大値を指定できます。

allowHalfRatingで半分の星を許可するかどうかを指定できます。

通常はドラッグで値を変更できますが、tapOnlyModeでタップのみで値を指定可能にします。

showLabelを指定すると実際の値を数値として表示することが可能です。

FormController.keyを与えたForm配下に配置、もしくはformFormControllerを渡します。

formFormControllerを渡した場合、一緒にonSavedも渡してください。データの保存はonSavedの内容が実行されます。

initialValueFormController.valueから与えられた初期値を入力します。

内容が変更される度onChangedが実行されます。

FormController.validateが実行された場合、バリデーションとデータの保存を行ないます。

emptyErrorTextが指定されている時に限り、文字が入力されていない場合emptyErrorTextがエラーとして表示されます。

それ以外のエラーチェックはvalidatorを指定することで行ないます。 コールバック内でNull以外を返すようにするとその文字列がエラー文として表示されます。Nullの場合はエラーなしとして処理されます。

enabledfalseになるとテキストが非有効化されます。

readOnlytrueになっている場合は、有効化の表示になりますが、値が変更できなくなります。

Implementation

FormRatingBar({
  this.form,
  this.style,
  this.keepAlive = true,
  this.controller,
  this.iconCount = 5,
  this.iconSize = 40.0,
  this.readOnly = false,
  this.onChanged,
  this.activeColor,
  this.inactiveColor,
  this.min,
  this.max,
  this.iconBuilder,
  this.allowHalfRating = true,
  this.tapOnlyMode = false,
  this.direction = Axis.horizontal,
  this.showLabel = false,
  this.icon,
  this.format = "0.#",
  super.key,
  this.emptyErrorText,
  TValue Function(double value)? onSaved,
  String Function(double? value)? validator,
  num? initialValue,
  super.enabled,
})  : assert(
        (form == null && onSaved == null) ||
            (form != null && onSaved != null),
        "Both are required when using [form] or [onSaved].",
      ),
      super(
        builder: (state) {
          return const SizedBox.shrink();
        },
        onSaved: (value) {
          if (value == null) {
            return;
          }
          final res = onSaved?.call(value);
          if (res == null) {
            return;
          }
          form!.value = res;
        },
        validator: (value) {
          if (emptyErrorText.isNotEmpty && value == null) {
            return emptyErrorText;
          }
          return validator?.call(value);
        },
        initialValue: initialValue?.toDouble(),
      );