[英]How can I use main.dart variable in my JS file?
I'm trying to create a calling app using flutter and I've created the backend using a node.js.我正在尝试使用 flutter 创建一个调用应用程序,并且我已经使用 node.js 创建了后端。 This is how my main.dart file in flutter looks like:
这是我在 flutter 中的 main.dart 文件的样子:
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:flutter_dialpad/flutter_dialpad.dart';
import 'dart:js';
import 'package:js/js.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.black,
body: SafeArea(
child:
DialPad(
enableDtmf: true,
outputMask: "(000) 000-0000",
backspaceButtonIconColor: Colors.red,
makeCall: (number){
print(number);
}
)
),
),
);
}
}
I want to use this "number" variable in my app.js file which looks like this:我想在我的 app.js 文件中使用这个“数字”变量,如下所示:
const accountSid = '***';
const authToken = '***';
const client = require('twilio')(accountSid, authToken);
client.calls.create({
url: 'http://demo.twilio.com/docs/voice.xml',
to: '+10000000',
from: '+1000000',
}, function(err, call){
if (err) {
console.log(err);
} else {
console.log(call.sid);
}
})
I want to be able to use the "number" variable from my main.dart file in the "to" field in my app.js file.我希望能够在 app.js 文件的“to”字段中使用 main.dart 文件中的“number”变量。 Please help me out...
请帮帮我...
What you need is a way to pass data between applications, and the easiest way for that would be through a REST API You can use the HTTP module in NodeJS or a third-party package like Express and set up a POST Route to your NodeJS Server, where the number is sent as data.您需要的是一种在应用程序之间传递数据的方法,最简单的方法是通过 REST API 您可以使用 NodeJS 中的HTTP 模块或 Express 等第三方包,并设置到 NodeJS 服务器的 POST 路由,其中数字作为数据发送。 Once the data is received on your server, you can call your Twilio function, and send a response back.
在您的服务器上收到数据后,您可以调用您的 Twilio 函数,并发送回响应。 On Flutter, you can use the http package to make the API call.
在 Flutter 上,您可以使用http 包进行 API 调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.