What causes "'RefreshIndicator' isn't a function" error?

92 Views Asked by At
if (subStatuses.isEmpty) {
  // No second tab bar needed if subStatuses is empty
  return RefreshIndicator(
    child: ListView.builder(
      physics: const BouncingScrollPhysics(),
      shrinkWrap: true,
      itemCount: applicants.length,
      itemBuilder: (context, index) {
        final applicant = applicants[index];
        return listViewItem_new(
          context,
          applicant,
          true,
          statuses,
          profilemodel.id != null
              ? profilemodel.id!.toInt()
              : 467,
          index,
        );
      },
    ),
  );
}

I'm trying to use RefreshIndicator, but I'm getting this error:

'RefreshIndicator' isn't a function.
Try correcting the name to match an existing function, or define a method or function named 'RefreshIndicator'.

Why is this happening?

2

There are 2 best solutions below

3
Future Internet On

Try adding the on Refresh Method

return RefreshIndicator(
  onRefresh: () {
    //write the call to method you want to run on refreshing
  },
  child: ListView.builder(
    physics: const BouncingScrollPhysics(),
    shrinkWrap: true,
    itemCount: applicants.length,
    itemBuilder: (context, index) {
      final applicant = applicants[index];
      return listViewItem_new(
        context,
        applicant,
        true,
        statuses,
        profilemodel.id != null ? profilemodel.id!.toInt() : 467,
        index,
      );
    },
  ),
);
0
Dhafin Rayhan On

Seems like the problem is that you imported package:flutter/material.dart and package:pull_to_refresh/pull_to_refresh.dart, which both export a RefreshIndicator class. If you're going to use RefreshIndicator from the Flutter framework, you need to hide RefreshIndicator from the pull_to_refresh import like this:

import 'package:pull_to_refresh/pull_to_refresh.dart' hide RefreshIndicator;

Or if you're not using that package, just remove the import.