Flutter学习七:TextField练习

TextField相当于Android中的EditText

代码如下:

import 'package:flutter/material.dart';

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

class SampleApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Sample App',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text("Sample App"),
        ),
        body: new SampleAppPage(),
      ),
    );
  }
}

class SampleAppPage extends StatefulWidget {
  SampleAppPage({Key key}) : super(key: key);

  @override
  _SampleAppPageState createState() => new _SampleAppPageState();
}

class _SampleAppPageState extends State {
  @override
  Widget build(BuildContext context) {
    return new TextField(
        //相当于Android属性hint
        decoration: new InputDecoration(
      hintText: "用户名",
    ));
  }
}

运行图如下:

Flutter学习七:TextField练习_第1张图片

 

你可能感兴趣的:(Flutter)