To implement separation of concerns for views and models, follow these steps:
- The best place to start is the data layer. This will give you a clear view of your app, without going into the details of your user interface. In the models folder, create a file called task.dart and create the Task class. This should have a description string and a complete Boolean, as well as a constructor. This class will hold the task data for our app. Add the following code:
class Task {
String description;
bool complete;
Task({
this.complete = false,
this.description = '',
});
}
- We also need a plan that will hold all our tasks. In the models folder, create plan.dart and insert this simple class:
import './task.dart';
class Plan {
String name = '';
final List<Task> tasks = [];
}
- We can wrap up our data layer by adding a file that will export both models. That way, our imports will not get too bloated as the app grows...