我是Flutter
的新手,正在尝试向codelabs - flutter学习。 TextField小部件不会显示。我在这里停留了一个小时。
我最终复制了代码方法,但仍然使我的应用程序为空。
这是我的代码:
class ChatScreen extends StatefulWidget{
// @override
// State createState() => new ChatScreenState();
@override
State<StatefulWidget> createState() {
return new ChatScreenState();
}
}
//STATE OF CHAT SCREEN
class ChatScreenState extends State<ChatScreen>{
//NEW COMPONENT EDIT TEXT INPUT LAYOUT
final TextEditingController _textController = new TextEditingController();
//WIDGET METHOD
Widget _buildTextComposer() {
return new Container(
margin: const EdgeInsets.symmetric(horizontal: 8.0),
child: new TextField(
controller: _textController,
onSubmitted: _handleSubmitted,
decoration: new InputDecoration.collapsed(hintText: "Send a message"),
),
);
}
//METHOD FOR CLEARING
void _handleSubmitted(String text){
_textController.clear();
}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: _buildTextComposer(),
);
}
}
我已经包括了脚手架中的尸体:_buildTextComposer()
。
答案 0 :(得分:0)
来自codelabs教程
codelabs-flutter #3,我没有注意到它们对runApp()
发件人:
import 'package:flutter/material.dart';
void main() {
runApp(
new MaterialApp(
title: "Friendlychat",
home: new Scaffold(
appBar: new AppBar(
title: new Text("Friendlychat"),
),
),
),
);
}
收件人:
void main() {
runApp(new FriendlychatApp()); //THERE IS NO COMMENT INDICATING THIS IS MODIFIED
}
他们在某些页面中指出了这一点。右边的评论
// Modify the ChatScreen class definition to extend StatefulWidget.
class ChatScreen extends StatefulWidget { //modified
@override //new
State createState() => new ChatScreenState(); //new
}