import 'package:flutter/material.dart';


class FutureProviderTemplate<T> extends ChangeNotifier {
  FutureProviderTemplate({required this.loader});

  final Future<T> Function() loader;

  T? _data;
  bool _isLoading = false;
  String? _error;

  T? get data => _data;
  bool get isLoading => _isLoading;
  String? get error => _error;

  Future<void> load() async {
    _isLoading = true;
    _error = null;
    notifyListeners();

    try {
      _data = await loader();
    } catch (e) {
      _error = e.toString();
    }

    _isLoading = false;
    notifyListeners();
  }
}
