Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
the-best-is-best opened this issue Oct 9, 2023 · 9 comments
Open

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

the-best-is-best opened this issue Oct 9, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@the-best-is-best
Copy link

the-best-is-best commented Oct 9, 2023

{
    "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 the-best-is-best added the bug Something isn't working label Oct 9, 2023
@i-asimkhan
Copy link
Contributor

i-asimkhan commented Oct 13, 2023

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"
              }
}
                                

@the-best-is-best
Copy link
Author

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

@i-asimkhan
Copy link
Contributor

i-asimkhan commented Oct 13, 2023

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 [
     ...
    ],
  );

@divyanshub024
Copy link
Contributor

@the-best-is-best Please keep an eye to this PR #213

@i-asimkhan
Copy link
Contributor

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

@the-best-is-best
Copy link
Author

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

@i-asimkhan
Copy link
Contributor

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

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

@divyanshub024
Copy link
Contributor

divyanshub024 commented Oct 16, 2023

Hey everyone,

This feature is currently a work in progress (See #213). This will be released in the upcoming v0.6. Until then kindly wait.
Note: MiraiFormCubit will be removed.

@the-best-is-best
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants