This file contains hidden or 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
| abstract class Chargeable { | |
| charge(); // Abstract method | |
| fastCharge() { | |
| print('Gotta go fast'); | |
| charge(); // Call to child's implemented method | |
| } | |
| } |
This file contains hidden or 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
| // Creating a time duration of 1 minute | |
| const oneMinute = Duration(minutes: 1); | |
| // ... | |
| Future<void> printWithDelay(String msg) async { | |
| // Wait for one minute | |
| await Future.delayed(oneMinute); | |
| print(msg); | |
| } |
This file contains hidden or 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
| class Task { | |
| // Class properties | |
| // Underscore makes them private | |
| String _name; | |
| bool _completed; | |
| // Default constructor | |
| // this syntax means that it will accept a value and set it to this.name | |
| Task(this._name); |
This file contains hidden or 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
| // Importing the material library with common UI components | |
| import 'package:flutter/material.dart'; | |
| // Entry point for our application | |
| // It tells Flutter to run the app and use TODOApp widget as the entry point | |
| void main() => runApp(TODOApp()); | |
| // The root widget for our app | |
| // It is stateless, that is why it expends StatelessWidget | |
| class TODOApp extends StatelessWidget { |
This file contains hidden or 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 = [ |
This file contains hidden or 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'; | |
| import 'package:todo_app/task.dart'; | |
| void main() => runApp(TODOApp()); | |
| class TODOApp extends StatelessWidget { | |
| final List<Task> tasks = [ | |
| Task('Do homework'), | |
| Task('Laundry'), |
This file contains hidden or 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
| // The sole reason we keep this extra component is | |
| // because runApp will only take a StatelessWidget as its argument | |
| class TODOApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return TODO(); | |
| } | |
| } | |
| // Here we are defining a StatefulWidget |
This file contains hidden or 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'; | |
| import 'package:todo_app/task.dart'; | |
| void main() => runApp(TODOApp()); | |
| class TODOApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return TODO(); | |
| } |
This file contains hidden or 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
| class TODOState extends State<TODO> { | |
| final List<Task> tasks = []; | |
| void onTaskCreated(String name) { | |
| setState(() { | |
| tasks.add(Task(name)); | |
| }); | |
| } | |
This file contains hidden or 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'; | |
| import 'package:todo_app/task.dart'; | |
| class TODOList extends StatelessWidget { | |
| final List<Task> tasks; | |
| final onToggle; | |
| TODOList({@required this.tasks, @required this.onToggle}); |