mirai icon indicating copy to clipboard operation
mirai copied to clipboard

fix: i can't send data to api and get data value

Open the-best-is-best opened this issue 1 year ago • 9 comments

{
    "type": "padding",
    "padding": {
        "left": 12,
        "right": 12,
        "top": 12,
        "bottom": 12
    },
    "child": {
        "type": "scrollView",
        "child": {
            "type": "form",
            "child": {
                "type": "column",
                "children": [
                    {
                        "type": "textFormField",
                        "id": "name",
                        "maxLines": 1,
                        "keyboardType": "text",
                        "textInputAction": "done",
                        "textAlign": "start",
                        "textCapitalization": "none",
                        "textDirection": "ltr",
                        "textAlignVertical": "top",
                        "decoration": {
                            "hintText": "What do people call you?",
                            "filled": true,
                            "icon": {
                                "type": "icon",
                                "iconType": "cupertino",
                                "icon": "person_solid",
                                "size": 24
                            },
                            "labelText": "Name*"
                        },
                        "inputFormatters": [
                            {
                                "type": "allow",
                                "rule": "[a-zA-Z]"
                            }
                        ],
                        "validatorRules": [
                            {
                                "rule": "isName",
                                "message": "Enter a valid name"
                            }
                        ],
                        "autovalidateMode": "onUserInteraction",
                        "readOnly": false,
                        "enabled": true
                    },
                    {
                        "type": "sizedBox",
                        "height": 24
                    },
                    {
                        "type": "textFormField",
                        "id": "password",
                        "compareId": "confirmPassword",
                        "maxLines": 1,
                        "keyboardType": "text",
                        "textInputAction": "done",
                        "textAlign": "start",
                        "textCapitalization": "none",
                        "textDirection": "ltr",
                        "textAlignVertical": "top",
                        "obscureText": true,
                        "decoration": {
                            "filled": true,
                            "icon": {
                                "type": "icon",
                                "iconType": "material",
                                "icon": "password",
                                "size": 24
                            },
                            "suffixIcon": {
                                "type": "icon",
                                "iconType": "cupertino",
                                "icon": "eye",
                                "size": 24
                            },
                            "labelText": "Password*"
                        },
                        "validatorRules": [
                            {
                                "rule": "isPassword",
                                "message": "Enter a valid password"
                            }
                        ],
                        "autovalidateMode": "onUserInteraction",
                        "readOnly": false,
                        "enabled": true
                    },
                    {
                        "type": "sizedBox",
                        "height": 24
                    },
                    {
                        "type": "formField",
                        "child": {
                            "type": "elevatedButton",
                            "child": {
                                "type": "text",
                                "data": "Submit",
                                "style": {
                                    "color": "#ffffff"
                                }
                            },
                            "style": {
                                "padding": {
                                    "top": 8,
                                    "left": 24,
                                    "right": 24,
                                    "bottom": 8
                                }
                            },
                            "onPressed": {
                                "actionType": "request",
                                "url": "xxxxx/Login",
                                "method": "post",
                                "data": {
                                    "name": "{name}",
                                    "password": "{password}"
                                }
                            }
                        }
                    }
                ]
            }
        }
    }
}

I can't send the value text form field and get the result can help me or solve that thanks

the-best-is-best avatar Oct 09 '23 13:10 the-best-is-best

Thank you for creating this @the-best-is-best At the moment we cannot pass values from values dynamically and recreate an API payload, though it is under process and very soon it will get released in the next version of Mirai.

At the moment requesting a response from the server using MiraiRequest is only possible with statically defined defines values in the JSON like this:

"onPressed":  {
  "actionType": "request",
  "url": "xxxxx/Login",
  "method": "post",
  "data": {
             "name": "name",
             "password": "password"
              }
}
                                

i-asimkhan avatar Oct 13 '23 07:10 i-asimkhan

i want send data user name and password after user added it so how can get value from form and get error to display or new page to go

the-best-is-best avatar Oct 13 '23 11:10 the-best-is-best

i want send data user name and password after user added it so how can get value from form and get error to display or new page to go

Greetings @the-best-is-best Since taking the value from the form-fields (text-fields) is under the build process, the existing stable version of Mirai unfortunately cannot support this, although there is always a workaround we do not recommend this because in the next release, we are going to push major updates in this regard, including form-values and calling an API.

Workaround:

Create a custom parser just like any action parsers in MIrai let's say, FormExtractor

class FormExtractorParser extends MiraiActionParser<Map<String, dynamic>> {
  ... 
  
   @override
  FutureOr<dynamic> onCall(BuildContext context, Map<String, dynamic> model) {
    try {
      final values = context.read<MiraiFormCubit>().state.values;
    } catch (e) {}
    
  }
  
  ... 

}

Now pass this FormExtractorParser onto your custom parsers in Mirai.initialize like this:

await Mirai.initialize(
    actionParsers: [
      FormExtractorParser()
    ],
    parsers: const [
     ...
    ],
  );

i-asimkhan avatar Oct 13 '23 11:10 i-asimkhan

@the-best-is-best Please keep an eye to this PR https://github.com/Securrency-OSS/mirai/pull/213

divyanshub024 avatar Oct 13 '23 11:10 divyanshub024

Please don't forget to check the Mirai parsers from here -> Parsers or don't hesitate to ask further.

i-asimkhan avatar Oct 13 '23 11:10 i-asimkhan

MiraiFormCubit not found i can't access it or import it

the-best-is-best avatar Oct 15 '23 10:10 the-best-is-best

try { final values = context.read<MiraiFormCubit>().state.values; } catch (e) {}

@the-best-is-best #228 should fix this.

i-asimkhan avatar Oct 16 '23 05:10 i-asimkhan

Hey everyone,

This feature is currently a work in progress (See https://github.com/Securrency-OSS/mirai/pull/213). This will be released in the upcoming v0.6. Until then kindly wait. Note: MiraiFormCubit will be removed.

divyanshub024 avatar Oct 16 '23 06:10 divyanshub024

until now don't understand how make button call request with data and re render new ui

the-best-is-best avatar Oct 16 '23 12:10 the-best-is-best