Advertisement
joaopaulofcc

Untitled

Sep 2nd, 2020
1,208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.30 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() => runApp(new TodoApp());
  4.  
  5. class TodoApp extends StatelessWidget {
  6.   @override
  7.   Widget build(BuildContext context) {
  8.     return new MaterialApp(title: 'Todo List', home: new TodoList());
  9.   }
  10. }
  11.  
  12. class TodoList extends StatefulWidget {
  13.   @override
  14.   createState() => new TodoListState();
  15. }
  16.  
  17. class TodoListState extends State<TodoList>
  18. {
  19.   List<String> _todoItems = [];
  20.  
  21.   void _addTodoItem()
  22.   {
  23.     setState(()
  24.     {
  25.       int index = _todoItems.length;
  26.       _todoItems.add('Item ' + index.toString());
  27.     });
  28.   }
  29.  
  30.   Widget _buildTodoList()
  31.   {
  32.     return new ListView.builder
  33.     (
  34.       itemBuilder: (context, index)
  35.       {
  36.         if (index < _todoItems.length)
  37.         {
  38.           return _buildTodoItem(_todoItems[index]);
  39.         }
  40.       },
  41.     );
  42.   }
  43.  
  44.   Widget _buildTodoItem(String todoText)
  45.   {
  46.     return new ListTile(title: new Text(todoText));
  47.   }
  48.  
  49.   @override
  50.   Widget build(BuildContext context)
  51.   {
  52.     return new Scaffold
  53.     (
  54.       appBar: new AppBar(title: new Text('Todo List')),
  55.       body: _buildTodoList(),
  56.       floatingActionButton: new FloatingActionButton
  57.       (
  58.           onPressed: _addTodoItem,
  59.           tooltip: 'Add task',
  60.           child: new Icon(Icons.add)),
  61.     );
  62.   }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement