model_interfaces 0.3.4 copy "model_interfaces: ^0.3.4" to clipboard
model_interfaces: ^0.3.4 copied to clipboard

Common interfaces for your models that have IDs, titles, etc.

example/main.dart

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

// Define multiple classes using similar model interfaces.

class Product implements WithIdTitle<int> {
  @override
  final int id;

  @override
  final String title;

  final double price;

  Product({required this.id, required this.title, required this.price});
}

class Category extends WithIdTitle<String> {
  Category(String id, String title) : super(id, title);
}

// Create widgets that can show models of any classes.

class ItemCard<I> extends StatelessWidget {
  final WithIdTitle<I> item;
  final ValueChanged<I> onTap;

  ItemCard({required this.item});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => onTap(item.id),
      child: Text(item.title),
    );
  }
}
8
likes
160
points
159
downloads

Publisher

verified publisherainkin.com

Weekly Downloads

Common interfaces for your models that have IDs, titles, etc.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT-0 (license)

Dependencies

meta

More

Packages that depend on model_interfaces