简体   繁体   English

如何在我的 JS 文件中使用 main.dart 变量?

[英]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.

相关问题 如何使用php文件中的GET获取在.js文件中声明的变量? - How can I use a GET from my php file, to get a variable that I declared in my .js file? 如何声明我以后可以在我的 js 文件中使用的 node.js 变量? - How to declare a node.js variable that i can later use in my js file? 如何在HTML中使用外部.js文件中的变量? - How can I use a variable from an external .js file in my HTML? 我可以在 JS 中为我的 html 使用变量吗? - Can I use a variable in JS for my html? 如何在我的js文件中使用脚本参数? - How can i use script parameters into my js file? 如何在我的 js 代码中使用此 local.txt 文件? - How can I use this local .txt file in my js code? 如何在我的Jade文件中的.js文件中使用函数? - How can I use my function from my .js file in my jade file? 如何在node.js-Backend和前端中的单独js文件中使用函数? - How can I use a function in a separate js file in my node.js-Backend as well as in my frontend? 在这种情况下可以使用JS变量吗?如何使用? - Can I use a JS variable in this case and how? 如何在Jquery中访问变量并在另一个外部.js文件中使用它的值? 变量为$ generationP - How can I access a variable in Jquery and use its value in another external .js file ? The variable is $generatedP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM