Skip to content

Conversation

ankogit
Copy link

@ankogit ankogit commented Apr 12, 2023

No description provided.

@mpkander mpkander self-requested a review April 19, 2023 09:00
@mpkander mpkander assigned mpkander and ankogit and unassigned mpkander Apr 19, 2023
Copy link

@mpkander mpkander left a 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 {

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) {}

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),

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';

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();

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(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Remove BuildContext from here.

  2. Remove showModalBottomSheet.

  3. 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 {

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 {

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;

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

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(() {
    // ...
  });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants