0

When i press a butoon i just want to send some text from flutter to my node js app.

I want to send "text2" to a node js app using http.dart

When i press my raised button i want it to send an http string with the variable text 2 to a node js app.

i'd like to get a link of a tutorial do that or just some help, bc i don't find anything on the web, thx.

My flutter code :

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(){}

}
4

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.