-
Notifications
You must be signed in to change notification settings - Fork 59
For review PR #7
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: main
Are you sure you want to change the base?
Conversation
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.
Overall, it's very good code for a beginner. Of course, there's some experience with other technologies that can make some of the decisions look exotic.
import 'package:path_provider/path_provider.dart'; | ||
import 'package:surf_flutter_study_jam_2023/views/ticket_open_view.dart'; | ||
|
||
void main() async { |
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.
General comment for the entire code:
- There are a lot of errors in the linter. You need to keep an eye on them.
- There are some commented lines of code that need to be removed.
} | ||
|
||
class _TicketListViewState extends State<TicketListView> { | ||
void _showModalBottomSheet(BuildContext context) {} |
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.
The _showModalBottomSheet
method is defined but not used. If you don't need it, you should remove it to avoid confusion.
Ticket ticket = snapshot.data![index]; | ||
return Card( | ||
child: ListTile( | ||
leading: Icon(Icons.file_present), |
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.
You can use the const
keyword to create some of the widgets that have constant properties, such as AppBar
and ElevatedButton
also, to improve performance.
@@ -0,0 +1,28 @@ | |||
import 'dart:io'; |
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.
The file name should be in snake case.
import '../services/fileDownloader.dart'; | ||
|
||
class TicketController { | ||
final downloader = FileDownloader(); |
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.
To better comply with the Dependency Inversion Principle (DIP), this dependency should be extracted as a parameter of the class.
} | ||
|
||
// ignore: use_build_context_synchronously | ||
showModalBottomSheet( |
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.
-
Remove
BuildContext
from here. -
Remove
showModalBottomSheet
. -
Your controller should instead say "Hey, view, something has happened. Can you display the bottom sheet with that data?"
@@ -0,0 +1,19 @@ | |||
import 'observer.dart'; | |||
|
|||
abstract class Observable { |
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.
There is already an implemented class in Flutter called ChangeNotifier
(and Listenable
contract).
|
||
import '../services/observable.dart'; | ||
|
||
class Ticket extends Observable { |
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.
This is a pretty exotic decision for model organization.
In Flutter, we are used to thinking about models as immutable entities. Because of this, all fields in models are immutable. And when one of the parameters changes, a new instance of the model is sent to the UI.
import 'package:flutter/material.dart'; | ||
|
||
class FileStatusTraillingWidget extends StatefulWidget { | ||
final bool isLoading; |
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.
Using an enum may be more useful here.
enum FileStatus {
loading,
readyToLoad,
finished,
}
), | ||
ElevatedButton( | ||
onPressed: () { | ||
widget.ticketController |
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.
That's not a good solution. It's better not to call setState in external callbacks, as there is a risk of causing a memory leak. If you really want to do this, you can check if the widget is still mounted using the mounted property:
if (mounted) {
setState(() {
// ...
});
}
No description provided.