Android studio 为什么android studio会在我已经清楚地使用了变量的情况下对未使用的变量发出警告

Android studio 为什么android studio会在我已经清楚地使用了变量的情况下对未使用的变量发出警告,android-studio,flutter,error-handling,warnings,Android Studio,Flutter,Error Handling,Warnings,我需要对来自android studio的警告感到恼火,警告我没有使用定义的变量,但实际上我已经使用了它。什么是问题?我的编码模式有问题吗 class CategoryProvider with ChangeNotifier { List<CategoryModel> _categories = []; int _currenPage = 1; int _lastPage = 1; int _perPage = 1; List<CategoryModel

我需要对来自android studio的警告感到恼火,警告我没有使用定义的
变量,但实际上我已经使用了它。什么是问题?我的编码模式有问题吗


class CategoryProvider with ChangeNotifier {
  List<CategoryModel> _categories = [];
  int _currenPage = 1;
  int _lastPage = 1;
  int _perPage = 1;

  List<CategoryModel> getCategories() => [..._categories];

  void setCategories(List<CategoryModel> _records) {
    _categories = _records;
    notifyListeners();
  }

  Future fetchCategories() async {
    try {
      ApiCall().getData(categoriesApi).then((data) {
        if (data['status'] == 'success') {
          _currenPage = data['collection']['current_page'];


带有ChangeNotifier的类CategoryProvider{
列表_类别=[];
int_currenPage=1;
int_lastPage=1;
每页整数=1;
列出getCategories()=>[…\u类别];
作废集合类别(列表记录){
_类别=_记录;
notifyListeners();
}
Future fetchCategories()异步{
试一试{
ApiCall().getData(categoriesApi).then((数据){
如果(数据['status']=='success'){
_currenPage=数据['collection']['current_page'];
在上面的代码中,我们可以清楚地看到,
\u当前页面
fetchCategories
函数中定义了
,并使用了
。那么为什么
android studio
也在哭呢

以上只是一个例子,还有更多类似的
变量
存在,我已经为所有人发出了
警告

对如何解决这个问题有什么建议吗

_currenPage = data['collection']['current_page'];
这意味着您正在声明
\u currenPage
变量,但您没有在任何地方使用它。 您可以像
打印(\u currenPage)
一样使用它,或者将其传递到某些函数中。
希望能有所帮助!

您正在声明变量并为其赋值,但之后您似乎没有使用它/对它做任何事情。它也可能从未被声明过-如果您删除了它的声明和对它所做的所有赋值,您的代码仍然可以工作。