StringDropdownField<T extends DropdownModel> constructor

StringDropdownField<T extends DropdownModel>({
  1. Key? key,
  2. List<T>? data,
  3. bool isActive = true,
  4. TextStyle? errorStyle,
  5. Color? colorText,
  6. Color? colorBackground,
  7. String? textHint,
  8. FormFieldSetter<T>? onSaved,
  9. FormFieldValidator<T>? validator,
  10. T? initialValue,
  11. dynamic onSelected(
    1. T
    )?,
})

Implementation

StringDropdownField(
    {Key? key,
    this.data,
    this.isActive = true,
    this.errorStyle,
    this.colorText,
    this.colorBackground,
    this.textHint,
    FormFieldSetter<T>? onSaved,
    FormFieldValidator<T>? validator,
    T? initialValue,
    Function(T)? onSelected})
    : super(
          key: key,
          onSaved: onSaved,
          validator: validator,
          initialValue: initialValue,
          autovalidateMode: AutovalidateMode.onUserInteraction,
          builder: (FormFieldState<T> state) {
            return Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                MyDropdown<T>(
                  initialValue: initialValue,
                  colorText: colorText ?? Colors.black,
                  colorBackground: colorBackground ?? Color(0xffF6F7FB),
                  onSelected: (item) {
                    if (isActive) {
                      onSelected!(item);
                      state.didChange(item);
                    }
                  },
                  itemBuilder: (BuildContext context) {
                    return List<PopupMenuEntry<T>>.generate(
                        (data!.length * 2 - 1), (int index) {
                      if (index.isEven) {
                        final item = data[index ~/ 2];
                        return PopUpObject<T>(value: item);
                      } else {
                        return MyDropdownDivider();
                      }
                    });
                  },
                  child: state.value == null
                      ? Text(
                          textHint ?? 'Pilih',
                        )
                      : DropdownObject(state.value),
                ),
                if (state.hasError)
                  Container(
                    padding: EdgeInsets.fromLTRB(4, 12, 4, 0),
                    child: Text(
                      state.errorText!,
                      style: errorStyle ?? TextStyle(color: Colors.red),
                      textAlign: TextAlign.start,
                    ),
                  )
              ],
            );
          });