Skip to content

Installation

Efra Espada edited this page Jan 30, 2024 · 1 revision

To use the Object library in your Flutter/Dart project, add it as a dependency in your pubspec.yaml file and configure it:

dependencies:
  object: ^1.0.0

object:
  baseProjectFolder: 'lib'
  outputFolder: 'model/generated'
  modelsFile: 'model.g.dart'
  generationClassSuffix: 'Gen'

Then, run flutter pub get to install the library.

Configuration

Configure the classes you will use with the object library.

import 'package:flutter/material.dart';
import 'package:object/object.dart';

import 'model/sample.dart';

void main() {
  /// From your pubspec.yaml configuration:
  /// 
  /// modelsFile: 'model.g.dart'
  /// 
  /// generates the [Model] class:
  Model().instancesForLoad();
  runApp(const MyApp());
}

You can include other classes with no @Field annotation but that implement the Object<T> contract of the library.

Model().instancesForLoad(
  additional: [
    OtherClass(),
  ],
);

Before importing this class you will have to run dart run object:build