Reputation: 77
so I have this simple code:
import 'package:provider/provider.dart';
class DataModel with ChangeNotifier{
bool _isLoading = true;
set isLoading(bool value){
_isLoading = value;
notifyListeners();
}
get isLoading => _isLoading;
}
ChangeNotifier and notifyListeners() aren't recognized.
My dependencies:
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
provider: ^4.3.3
I'm very confused as to why is it happening, this is the exact setup in the installation page (and it worked in other projects).
This project is also connected to a git lab project, I don't know if it is related.
btw, it's not like that with other keywords that are in the provider package - it perfectly recognizes ChangeNotifierProvider i.e
Upvotes: 1
Views: 748
Reputation:
You are importing an incorrect package, the correct one is package:flutter/foundation.dart
or alternatively package:flutter/material.dart
, try with:
import 'package:flutter/material.dart';
class DataModel with ChangeNotifier{
bool _isLoading = true;
set isLoading(bool value){
_isLoading = value;
notifyListeners();
}
get isLoading => _isLoading;
}
package:provider/provider.dart
is used in the files where the calls to the provider are made, not where it is defined.
See the example from the docs: https://github.com/flutter/samples/blob/master/provider_shopper/lib/models/cart.dart
A hint, in VS Code if you right click on ChangeNotifier
and select Go to Definition, the definition can be traced to the foundation package.
Upvotes: 5