[英]Send text from flutter to node js
當我按下按鈕時,我只想將一些文本從 flutter 發送到我的 node.js 應用程序。
我想使用 http.dart 將“text2”發送到 node.js 應用程序
當我按下凸起的按鈕時,我希望它向 node.js 應用程序發送一個帶有可變文本 2 的 http 字符串。
我想獲得教程的鏈接或只是一些幫助,因為我在 web 上找不到任何東西,謝謝。
我的 flutter 代碼:
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(){}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.