简体   繁体   English

如何用flutter触发Azure function

[英]How to trigger Azure function with flutter

I created an azure function in c # and set up an HTTP trigger.我在 c # 中创建了一个 azure function # 并设置了一个 HTTP 触发器。 I'm interested in how to call this function from the flutter application.我对如何从 flutter 应用程序调用此 function 感兴趣。 I don't need to transfer any special data because everything is already in the link I use to call the function.I've created a simplified view of the function to demonstrate what I want.我不需要传输任何特殊数据,因为所有内容都已在我用来调用 function 的链接中。我创建了 function 的简化视图来演示我想要什么。

https://functionapp220220124204147.azurewebsites.net/api/Quercus?status=Off https://functionapp220220124204147.azurewebsites.net/api/Quercus?status=Off

When it calls this function all it needs to do is change the value of the variable from on to off当它调用这个 function 时,它需要做的就是将变量的值从 on 更改为 off

I know this is not the correct way to make a function and I should not have such variables, but this is just a simplified version我知道这不是制作 function 的正确方法,我不应该有这样的变量,但这只是一个简化版本

Here is a workaround given by Vikash Kumar in the Medium article regarding How to call Azure Functions API through Flutter App Code:这是 Vikash Kumar 在关于如何调用 Azure 函数 API 到 Flutter 应用程序代码的中篇文章中给出的解决方法:

  • Created Wordle Website which has a list of legit words and allows you to input a word only from that list where we validate if an input word is a legit English word.创建Wordle网站,其中包含一个合法单词列表,并允许您仅从该列表中输入一个单词,我们会在该列表中验证输入的单词是否为合法的英语单词。

  • First, he created the Azure Cosmos DB > container in it > added a few dates, word pairs like:首先,他创建了 Azure Cosmos DB > 在其中添加了容器 > 添加了一些日期、单词对,例如:在此处输入图像描述

  • Created the Azure Functions which has input binding with the Cosmos DB and gets a list of stored words on every request.创建了 Azure 函数,它具有与Cosmos DB的输入绑定,并在每次请求时获取存储的单词列表。

  • This functionality is broken into 3 segments:此功能分为 3 个部分:

  • Validate the input word (not null, same length, convert to uppercase both)验证输入的单词(不是null,长度相同,都转为大写)

  • Check if both words are the same检查两个词是否相同

  • Status of each letter in the input word.输入单词中每个字母的状态。

The deployed function app API will be in this format: https://wordle-api.azurewebsites.net/api/CheckWord?word=部署的 function 应用程序 API 将采用以下格式: https://wordle-api.azurewebsites.net/api/CheckWord?word=

Also created the flutter in the composition of the word_field component which creates an input widget that accepts a 5 letter word in 5 boxes (1 each) which is similar to the OTP field.还在word_field组件的组合中创建了 flutter,它创建了一个输入小部件,它在 5 个框(每个 1 个)中接受 5 个字母的单词,这类似于 OTP 字段。

  • And the home component builds a scaffold and puts together a page to accept 6 attempts for words.home component构建了一个脚手架并拼凑了一个页面来接受 6 次单词尝试。
  • The _checkWord handler calls the wordle-api , gets the color code, and updates the components accordingly. _checkWord处理程序调用wordle-api ,获取颜色代码,并相应地更新组件。
  • Calling the Function API in the above handler and writing the code about response status and the user-defined message to the response.在上述处理程序中调用 Function API 并将有关响应状态和用户自定义消息的代码写入响应。

var uri = Uri.https('wordle-api.azurewebsites.net', '/api/CheckWord', params);

For Complete Code, Please refer this article .完整代码请参考这篇文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM