Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- void main() => runApp(new MyApp());
- class MyApp extends StatelessWidget {
- // This widget is the root of your application.
- @override
- Widget build(BuildContext context) {
- return new MaterialApp(
- title: 'Contacts',
- theme: new ThemeData(
- primarySwatch: Colors.blue,
- ),
- home: new MyHomePage(title: 'Contacts App Flutter'),
- );
- }
- }
- class MyHomePage extends StatefulWidget {
- MyHomePage({Key key, this.title}) : super(key: key);
- final String title;
- @override
- _MyHomePageState createState() => new _MyHomePageState();
- }
- class _MyHomePageState extends State<MyHomePage> {
- User _newUser = User();
- List<User> _contacts = [];
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text(widget.title)
- ),
- body: Column(
- children: <Widget>[
- Form(
- child: Column(
- children: <Widget>[
- TextFormField(
- decoration: InputDecoration(
- hintText: 'Nome do contato',
- labelText: 'Nome'
- ),
- onSaved: (value) => setState(() => _newUser.name = value),
- ),
- TextFormField(
- keyboardType: TextInputType.numberWithOptions(),
- decoration: InputDecoration(
- hintText: '000000000',
- labelText: 'Número'
- ),
- onSaved: (value) => setState(() => _newUser.number = value as int),
- ),
- RaisedButton(
- child: Text('Add'),
- onPressed: () => submit()
- )
- ],
- ),
- ),
- Flexible(child: _buildList())
- ],
- )
- );
- }
- submit() {
- setState(() => _contacts.add(_newUser));
- }
- _buildList() {
- return ListView.builder(itemBuilder: (context, index){
- if (index < _contacts.length) {
- return ListTile(
- title: Text(_contacts[index].name),
- subtitle: Text(_contacts[index].number as String),
- );
- } //EndIf
- }
- );
- }
- }
- class User {
- String name;
- int number;
- }
Add Comment
Please, Sign In to add comment