在 Flutter 应用程序中看不到输入

Cannot see input in Flutter app

我遵循了本教程:https://codelabs.developers.google.com/codelabs/flutter/index.html#4,但是在 运行 应用程序之后我看不到输入小部件。

main.dart

import 'package:flutter/material.dart';

void main() {
    runApp(new MaterialApp(
        title: "Friendlychat",
        home: new Scaffold(
            appBar: new AppBar(
                title: new Text("Friendlychat")
            )
        )
    ));
}

class FriendlyChatApp extends StatelessWidget {

    @override
    Widget build(BuildContext context) {
        return new MaterialApp(
            title: "Friendlychat",
            home: new ChatScreen()
        );
    }
}

class ChatScreen extends StatefulWidget {

    @override
    State createState() => new ChatScreenState();
}

class ChatScreenState extends State<ChatScreen> {

    final TextEditingController _textController = new TextEditingController();

    @override
    Widget build(BuildContext context) {
        return new Scaffold(
            appBar: new AppBar(
                title: new Text("Friendlychat")
            ),
            body: _buildTextComposer()
        );
    }

    Widget _buildTextComposer() {
        return new IconTheme(
            data: new IconThemeData(color: Theme
                .of(context)
                .accentColor),
            child: new Container(
                margin: const EdgeInsets.symmetric(horizontal: 8.0),
                child: new Row(
                    children: <Widget>[
                        new Flexible(
                            child: new TextField(
                                controller: _textController,
                                onSubmitted: _handleSubmitted,
                                decoration: new InputDecoration.collapsed(
                                    hintText: "Send a message"),
                            ),
                        ),
                        new Container(
                            margin: new EdgeInsets.symmetric(horizontal: 4.0),
                            child: new IconButton(
                                icon: new Icon(Icons.send),
                                onPressed: () =>
                                    _handleSubmitted(_textController.text)),
                        ),
                    ]
                ),
            )
        );
    }

    void _handleSubmitted(String text) {
        _textController.clear();
    }
}

您没有完成上一步的一部分。您的问题出在这段代码中:

void main() {
  runApp(new MaterialApp(
    title: "Friendlychat",
    home: new Scaffold(
      appBar: new AppBar(
        title: new Text("Friendlychat")
      )
    )
  ));
}

您应该将其替换为:

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