Created
December 4, 2019 14:25
-
-
Save r3dm1ke/f6d460d91e475b4d1f334f392ad7eb59 to your computer and use it in GitHub Desktop.
Rendering dummy tasks in Flutter
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'; | |
// Importing our Task class | |
import 'package:todo_app/task.dart'; | |
void main() => runApp(TODOApp()); | |
class TODOApp extends StatelessWidget { | |
// Creating a list of tasks with some dummy values | |
final List<Task> tasks = [ | |
Task('Do homework'), | |
Task('Laundry'), | |
Task('Finish this tutorial') | |
]; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'TODO app', | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text('TODO app'), | |
), | |
// Using ListView.builder to render a list of tasks | |
body: ListView.builder( | |
// How many items to render | |
itemCount: tasks.length, | |
// Functions that accepts an index and renders a task | |
itemBuilder: (context, index) { | |
return ListTile( | |
title: Text(tasks[index].getName()), | |
); | |
} | |
) | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment