flutter_fit_utils 1.0.1 copy "flutter_fit_utils: ^1.0.1" to clipboard
flutter_fit_utils: ^1.0.1 copied to clipboard

A flutter package to easily manage data in and out of repositories. This package is the core of it's environement.

example/main.dart

import 'package:flutter_fit_utils/flutter_fit_utils.dart';

Future<void> main() async {
  // Create a service.
  final Service service = SharedPreferenceService("users", User.fromModel);

  const User newUser = User(name: "User", id: "1", userId: "u_1");

  // Write to your repository.
  await service.create(newUser);

  // Read from your repository.
  await service.getAll();
}

/// Example user class.
class User extends Modelable {
  static const String _nameKey = "name";

  /// User's last name.
  final String name;

  /// Creates a new user.
  const User({this.name = "", super.id, super.userId});

  /// Creates an invalid user.
  const User.invalid() : name = "", super.invalid();

  /// Creates a user from a [Model].
  User.fromModel(super.model) :
    name = model.data[_nameKey].toString(),
    super.fromModel();

  @override
  User copyWith({String? id, String? userId, String? name}) => User(
    name: name ?? this.name,
    id: id ?? this.id,
    userId: userId ?? this.userId,
  );

  @override
  Model toModel() => Model(
    id: id,
    userId: userId,
    data: {
      _nameKey: name,
    },
  );
}
3
likes
140
points
321
downloads

Publisher

unverified uploader

Weekly Downloads

A flutter package to easily manage data in and out of repositories. This package is the core of it's environement.

Homepage
Repository (GitHub)
View/report issues

Topics

#models #repositories #services #extensions

Documentation

API reference

License

MIT (license)

Dependencies

cloud_firestore, firebase_remote_config, flutter, intl, shared_preferences

More

Packages that depend on flutter_fit_utils