Created
December 7, 2019 22:26
-
-
Save cnruby/78d90b589b103f5102afa2a23f2f4a21 to your computer and use it in GitHub Desktop.
Flutter App 34: Clearing the field after the text message is sent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(new FriendlychatApp()); | |
} | |
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 Container( | |
margin: const EdgeInsets.symmetric(horizontal: 20.0), | |
child: new TextField( | |
controller: _textController, | |
onSubmitted: _handleSubmitted, | |
decoration: new InputDecoration.collapsed(hintText: "Send a message"), | |
), | |
); | |
} | |
void _handleSubmitted(String text) { | |
_textController.clear(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment