0

This is my first flutter app - it's an Expenses splitter. Passing around callbacks was getting very complex, so I switched to Provider - but was getting errors which I think are because of my data model having dependencies (see snippet below). Note: I've assumed that change notifiers on the dependent classes is a better approach than just having one change-notifier for any change.

So I'm now switching to a ProxyProvider setup. Which is all feeling a bit too complex for what I thought would be quite a simple app.

Question: is there a simpler way to set-up the data model so I can use a simple provider pattern - or is ProxyProvder and the model (as it already is) the best approach?

class DBModel with ChangeNotifier {
  List<TripModel> _trips; // all the trips
  List<PersonModel> _addressBook; // Addressbook of people

...etc


class TripModel with ChangeNotifier {

   final String id;
   String destination;
   DateTime startDate;
   DateTime endDate;
   List<String> memberIDs;
   List<ExpenseModel> _expenses;

  TripModel ({this.id, this.destination, this.startDate, this.endDate, this.memberIDs, this.expenses});


  List<ExpenseModel> get expenses {
    return [..._expenses];
  }
Kai
  • 15
  • 3

1 Answers1

0

According to providers documentation, you only need to use the ProxyProvider when you need to pass variables that change over time to your object

e.g:

int count;

ProxyProvider0(
    update: (_, __) => new MyModel(count),
    child: ...
)
Johhn
  • 979
  • 17
  • 24