createNew method

void createNew(
  1. String label
)

Implementation

void createNew(String label) async {
  return showDialog<void>(
    context: this.context,
    barrierDismissible: true,
    builder: (BuildContext context) {
      return Dialog(
        insetPadding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
        backgroundColor: widget.colorPrimary,
        child: Container(
          margin: EdgeInsets.only(top: 10),
          width: double.infinity,
          height: 220,
          child: SingleChildScrollView(
            child: Column(
              children: [
                Text(
                  'Novo ' + label,
                  style: TextStyle(fontSize: 16),
                ),
                SizedBox(height: 10),
                Divider(),
                Container(
                  margin: EdgeInsets.all(10),
                  child: Form(
                    key: keyFormNew,
                    child: Column(
                      children: [
                        OmegaTextField(
                          autofocus: true,
                          hint: 'Informe o $label',
                          keyboardType: TextInputType.text,
                          label: label,
                          labelColor: widget.colorWhite,
                          showRequiredLabel: true,
                          validator: (value) {
                            if (value == null || value.length < 1) {
                              return 'O Campo $label é requerido';
                            } else {
                              return null;
                            }
                          },
                          onSaved: (value) {
                            resolveSelectedValue(new SearchFieldSource(
                              label: value ?? '',
                              value: 0,
                            ));
                          },
                        )
                      ],
                    ),
                  ),
                ),
                Align(
                  alignment: Alignment.bottomCenter,
                  child: Container(
                    margin: EdgeInsets.only(right: 8, left: 8),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        OmegaButton(
                          height: 40,
                          width: MediaQuery.of(context).size.width * 0.40,
                          color: Colors.red,
                          text: 'Cancelar',
                          onPressed: () {
                            Navigator.pop(context);
                          },
                        ),
                        OmegaButton(
                          height: 40,
                          width: MediaQuery.of(context).size.width * 0.45,
                          color: Colors.green,
                          text: 'Confirmar',
                          onPressed: () {
                            FocusManager.instance.primaryFocus?.unfocus();

                            if (keyFormNew.currentState?.validate() ??
                                false) {
                              keyFormNew.currentState?.save();
                              Navigator.pop(context);
                            }
                          },
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      );
    },
  );
}