Skip to main content

Classes

MUST extend all classes with equatable

Equatable is designed to only work with immutable objects so all member variables must be final.

info
```dart{1,3,15,16} title="1. model having the variables and constructor for the list of movies"
import 'package:equatable/equatable.dart';

class MovieModel extends Equatable {
String movieId;
String movieName;
bool isFavorite;
String posterUrl;

MovieModel( {required this.movieId, required this.movieName, required this.posterUrl, this.isFavorite = false} );

void toggleFavorite() {
isFavorite = !isFavorite;
}

@override
List<Object?> get props => [movieId, movieName, isFavorite, posterUrl]; // returns a `List<dynamic>` containing all the 'final' variables of this class
}

creating objects of class

if 'Constructor' NOT is written for the class
Rectangle obj = Rectangle();

if 'Constructor' IS WRITTEN for the class
class Rectangle {
var width = 10;
var height = 2;

Rectangle({required this.width, required this.height}); // Constructor with Named Parameters
}

void main() {
Rectangle hell = Rectangle(height: 9, width: 8); // creating object `obj` for the class `Rectangle`
}