首页 > 解决方案 > 将文本从颤振发送到节点 js

问题描述

当我按下按钮时,我只想将一些文本从颤振发送到我的节点 js 应用程序。

我想使用 http.dart 将“text2”发送到节点 js 应用程序

当我按下我的凸起按钮时,我希望它将带有变量文本 2 的 http 字符串发送到节点 js 应用程序。

我想获得一个教程的链接,或者只是一些帮助,因为我在网上找不到任何东西,谢谢。

我的颤振代码:

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

void main() {
  runApp(new MyApp());
}

var text2;

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Bot Discord App',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
        primaryColor: const Color(0xFF2196f3),
        accentColor: const Color(0xFF2196f3),
        canvasColor: const Color(0xFFfafafa),
      ),
      home: new MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);
  @override
  _MyHomePageState createState() => new _MyHomePageState();
}


class _MyHomePageState extends State<MyHomePage> {
  final myController = TextEditingController();
  @override
  void dispose() {
    // Clean up the controller when the widget is disposed.
    myController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Bot Discord App'),
      ),
      body:
      new Column(
          mainAxisAlignment: MainAxisAlignment.start,
          mainAxisSize: MainAxisSize.max,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            new SizedBox(
              width: 100.0,
              height: 100.0,
              child:
              new Padding(
                child:
                new Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    mainAxisSize: MainAxisSize.max,
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    children: <Widget>[
                      new Text(
                        "Precense",
                        style: new TextStyle(fontSize:19.0,
                            color: const Color(0xFF000000),
                            fontWeight: FontWeight.w200,
                            fontFamily: "Roboto"),
                      ),

                      new TextField(
                        style: new TextStyle(fontSize:12.0,
                            color: const Color(0xFF000000),
                            fontWeight: FontWeight.w200,
                            fontFamily: "Roboto"),
                      )
                    ]

                ),

                padding: const EdgeInsets.all(10.0),
              ),

            ),

            new SizedBox(
              width: 100.0,
              height: 50.0,
              child:
              new Padding(
                child:
                new RaisedButton(key:null,
                    onPressed: () {
                      return
                        text2 = Text(myController.text) as String;
                    },
                    color: const Color(0xFFe0e0e0),
                    child:
                    new Text(
                      "UPDATE",
                      style: new TextStyle(fontSize:23.0,
                          color: const Color(0xFF000000),
                          fontWeight: FontWeight.w200,
                          fontFamily: "Roboto"),
                    )
                ),

                padding: const EdgeInsets.fromLTRB(6.0, 6.0, 7.0, 6.0),
              ),

            )
          ]

      ),

    );
  }
  void buttonPressed(){}

}

标签: node.jsflutterhttp

解决方案


我认为解决方案是在颤振中调用 JS 变量作为参数,并为它们分配你想要使用的值......有关更多详细信息,请查看给定的链接,希望这会对你有所帮助...... [1]:https ://fireship.io/snippets/using-js-with-flutter-web/


推荐阅读