TextField相当于Android中的EditText:
TextField(
decoration: new InputDecoration(hintText: "This is a hint"),// 提示语
)
获取TextField的值:
= TextEditingController();
TextField(
controller: _name,// 控制器
decoration: new InputDecoration(hintText: "This is a hint"),
onChanged: (value){// 双向绑定
this.setState(() {
this._name.text = value;
});
},
),
示例:
import 'dart:convert';
import 'dart:isolate';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() => runApp(DemoApp());
class DemoApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: '导航演示1',
home: new MyAppHome(),
);
}
}
class MyAppHome extends StatefulWidget {
@override
_MyAppHomeState createState() => _MyAppHomeState();
}
class _MyAppHomeState extends State<MyAppHome> {
TextEditingController _name = TextEditingController();
@override
Widget build(BuildContext context) {
return new Scaffold(
body: Center(
child: new TextField(
controller: _name,
decoration: new InputDecoration(hintText: "This is a hint"),
onChanged: (value){
this.setState(() {
this._name.text = value;
});
},
),
),
);
}
}