Use Riverpod as state management tool
ref: #27
Codecov Report
Merging #28 (08286cf) into master (deca900) will not change coverage. The diff coverage is
100.00%.
:exclamation: Current head 08286cf differs from pull request most recent head 11d5e1d. Consider uploading reports for the commit 11d5e1d to get more accurate results
@@ Coverage Diff @@
## master #28 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 6 6
Lines 84 84
=========================================
Hits 84 84
| Impacted Files | Coverage Ξ | |
|---|---|---|
| lib/models/task.dart | 100.00% <100.00%> (ΓΈ) |
|
| lib/screens/completed_tasks/completed_tasks.dart | 100.00% <100.00%> (ΓΈ) |
:mega: Weβre building smart automated test selection to slash your CI/CD build times. Learn more
@LuchoTurtle can you please pick this up after you have looked into: https://github.com/dwyl/flutter-todo-list-tutorial/issues/27#issuecomment-1307025552 π
I'm taking this up as part of https://github.com/dwyl/product-roadmap/issues/40. This PR is a bit outdated so I had some trouble having to get it working with newer Flutter versions. Had to work on upgrading the dependencies, changing Podfiles, gradle and AndroidManifest.xml.
The tests don't work on my computer, though.
I'm looking at doing a semi-overhaul to this repo, to update it and using Riverpod for state management, drift to save local files and, according to https://github.com/dwyl/product-roadmap/issues/40, add a Phoenix backend. I'll be using Riverpod here but for the mvp we should consider Bloc -> check my comment https://github.com/dwyl/flutter-todo-list-tutorial/issues/27#issuecomment-1329590333
Though we ought to discuss this further on tomorrow's standup.
Still, there is work to be done until then so I'll be doing this.
@nelsonic
I fixed some bugs where the user couldn't create todos and properly check them. The tests weren't working and I got one fixed, which took too much time for what it was worth.
It feels like I'm fighting an uphill battle with this because I'm dealing with outdated specs and generated files on both Android and Apple, so there is a lot of unexpected behavior with this. This PR deals with an outdated version of Riverpod and the widgets and providers are built using ChangeNotifierProvider, which is not recommended by the library creators. Getting this to run was quite painful as it was still using Android Embedded v1 and older Flutter components. The Riverpod version was outdated as well, it's already on 2.x.x and these changes had a 0.x.x version.
Getting a single integration test to run was time-consuming, having resulted in lots of workarounds just to get it working. For example, here's a snippet testing a simple widget so it was workable when calling tester.pumpWidget().
Widget testWidget = Localizations(
locale: const Locale('en', 'US'),
delegates: const <LocalizationsDelegate<dynamic>>[
DefaultWidgetsLocalizations.delegate,
DefaultMaterialLocalizations.delegate,
],
child: MediaQuery(
data: new MediaQueryData(),
child: Material(
child: ProviderScope(
overrides: [
todolistProvider.overrideWith((ref) {
return todoList;
})
],
// Our application, which will read from todoListProvider to display the todo-list.
// You may extract this into a MyApp widget
child: Scaffold(body: TodoListWidget())))));
I feel like this is not sustainable if I want to get this out quickly. I'm bringing this up in tomorrow's standup but I feel like I should revamp this repo with a newly-generated project and follow Riverpods updated recommendations. I don't want any code to go to waste, so I'll borrow some styling and code from this PR. But I don't think continuing this PR with the current outdated project is the way to go.
Additionally, I think this repo gains importance as it is related to the mvp.
It's up to you though, this is my recommendation as I feel like I'm wasting more time than what it's worth. If you give me the green light, I'll continue to work on this PR but "start from scratch" (not really but you get my point).
Thank you for this very insightful comment on Flutter project maintainability. π
Please go for it if you need to nuke the project and start from scratch. π₯
Going to go ahead and start from scratch but using the same pieces of code written by @SimonLab on the new one so his efforts don't go to waste π
@LuchoTurtle Thanks for sharing your progress + plans. Very insightful. π‘ Good luck on your quest. π
Just finished creating a basic todo app with Riverpod that is fully tested and now fully documented with a guide to get it done.
Of course, I need to get started on the API part which will be included in the readme later on.
I had a greater emphasis on setting up and explainingRiverpod concepts and providers, and how they can be used. Overall, I delved deeper into shared data and data management instead of styling, as I feel we have such info in the flutter-stopwatch-tutorial, learn-flutter and flutter-counter-tutorial repos.
@LuchoTurtle nice one. thanks for the update. hope you have a great weekend. βοΈ π
I will now resume this task, following the creation of https://github.com/dwyl/phoenix-todo-list-tutorial/pull/60. Even though it's not merged yet, I'll run it on localhost to try and get it properly working.
I'm basically finished with this when it comes to implementation. I have tests on my local change but I haven't committed them because they are falling and I'm pulling my hair as to why. I shall continue tomorrow.
I'm also finishing the README to make use of the API.
Had to fix the tests that were failing. Took a while to figure out how I could mock HTTP requests when using providers from Riverpod. I had to change a bit how I was using providers.
For this, I had to create a repositoryProvider which exposes the repository (the service used to make HTTP calls) and use it on other providers. This was the only way I could find to minimize code change and be able to mock HTTP requests when testing.
All these changes were reflected in the README as well, which is basically finalized at this point.
Now I'm going to be focusing on finishing the tests so I get back to 100% coverage and push the changes.
This should be ready for review. Added the tests, fixed typos and re-wrote the README according to changes needed.