-
Notifications
You must be signed in to change notification settings - Fork 110
Update Chapter6 #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| export 'plan.dart'; | ||
| export 'task.dart'; | ||
| export 'task.dart'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,17 @@ | ||
| import '../repositories/repository.dart'; | ||
| import 'package:flutter/foundation.dart'; | ||
| import './task.dart'; | ||
|
|
||
| class Plan { | ||
| final int id; | ||
| String name = ''; | ||
| String name; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought this assignment might be redundant as we are assigning it in the constructor on line 9. |
||
| List<Task> tasks = []; | ||
|
|
||
| Plan({@required this.id, this.name = ''}); | ||
| Plan({required this.id, this.name = ''}); | ||
|
|
||
| Plan.fromModel(Model model) | ||
| : id = model.id, | ||
| name = model?.data['name'], | ||
| tasks = model?.data['task'] | ||
| name = model.data['name'] ?? '', | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was getting |
||
| tasks = model.data['tasks'] | ||
| ?.map<Task>((task) => Task.fromModel(task)) | ||
| ?.toList() ?? | ||
| <Task>[]; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,13 +4,15 @@ import 'controllers/plan_controller.dart'; | |
| class PlanProvider extends InheritedWidget { | ||
| final _controller = PlanController(); | ||
|
|
||
| PlanProvider({Key key, Widget child}) : super(key: key, child: child); | ||
|
|
||
| @override | ||
| bool updateShouldNotify(InheritedWidget oldWidget) => false; | ||
| bool updateShouldNotify(covariant InheritedWidget oldWidget) => false; | ||
|
|
||
| PlanProvider({Key? key, required Widget child}) | ||
| : super(key: key, child: child); | ||
|
|
||
| static PlanController of(BuildContext context) { | ||
| PlanProvider provider = context.dependOnInheritedWidgetOfExactType<PlanProvider>(); | ||
| final provider = context.dependOnInheritedWidgetOfExactType<PlanProvider>() | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I specify |
||
| as PlanProvider; | ||
| return provider._controller; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ import '../repositories/in_memory_cache.dart'; | |
| import '../repositories/repository.dart'; | ||
|
|
||
| class PlanServices { | ||
| Repository _repository = InMemoryCache(); | ||
| final Repository _repository = InMemoryCache(); | ||
|
|
||
| Plan createPlan(String name) { | ||
| final model = _repository.create(); | ||
|
|
@@ -28,7 +28,10 @@ class PlanServices { | |
| } | ||
|
|
||
| void addTask(Plan plan, String description) { | ||
| final id = plan.tasks.last?.id ?? 0 + 1; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initially, I had this conflict There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. have you found any solution to this issue?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @amkfat lines 31 to 34 are the solution I came up with |
||
| int id = 0; | ||
| if (plan.tasks.isNotEmpty) { | ||
| id = plan.tasks.last.id + 1; | ||
| } | ||
| final task = Task(id: id, description: description); | ||
| plan.tasks.add(task); | ||
| savePlan(plan); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I leave it as
String description, then I have a conflict oncontroller.createNewTask(plan);in_buildAddTaskButtonfunction because we are not sending description in there, so that's I made this to be optional. However, I think there might be better way to handle this.