Xuuan Thuc
Xuuan Thuc

Reputation: 2521

"androidOverscrollIndicator" is deprecated and shouldn't be used

I am applying stretch effect to Listview , I use androidOverscrollIndicator

ScrollBehavior(
   androidOverscrollIndicator: AndroidOverscrollIndicator.stretch
),

I work perfectly but i see a warning at androidOverscrollIndicator

'androidOverscrollIndicator' is deprecated and shouldn't be used. Use ThemeData.useMaterial3 or override ScrollBehavior.buildOverscrollIndicator. This feature was deprecated after v2.13.0-0.0.pre.. (Documentation) Try replacing the use of the deprecated member with the replacement.

How can i fix this?

This is my code:

ScrollConfiguration(
   behavior: const ScrollBehavior(
      androidOverscrollIndicator: AndroidOverscrollIndicator.stretch
   ),
   child: GlowingOverscrollIndicator(
       axisDirection: AxisDirection.down,
       color: Colors.white,
       child: ListView(
          physics: const ClampingScrollPhysics(),
          children: [ 
              //some widget
          ],
         ),
       ),
    ),

enter image description here

Upvotes: 1

Views: 1391

Answers (3)

nouvist
nouvist

Reputation: 1182

We can still modify the MaterialScrollBehavior to change overscroll indicator globally, but we need to modify the class directly. If you see the class definition, there is a method called buildOverscrollIndicator. We can then override this method with the preferred indicator, with StretchingOverscrollIndicator in my case. But it is up to you actually, you can even do if conditions, check the platform, or something.

Here's the snippet.

class StretchScrollBehavior extends MaterialScrollBehavior {
  // needed so the object can be instantiated as a const
  const StretchScrollBehavior();

  @override
  Widget buildOverscrollIndicator(
    BuildContext context,
    Widget child,
    ScrollableDetails details,
  ) {
    // choose and build the overscroll indicator
    return StretchingOverscrollIndicator(
      axisDirection: details.direction,
      child: child,
    );
  }
}

Then we can use it in the ScrollConfiguration.

ScrollConfiguration(
  behavior: const StretchScrollBehavior(),
  child: child,
);

And also, you can implement the indicator by your own, by using NotificationListener<OverscrollNotification>. And then, animate the child whatever you want.

Upvotes: 0

Ozan Taskiran
Ozan Taskiran

Reputation: 3552

For future readers: Simplest solution is to use Material3

      MaterialApp(
        home: HomePage(),
        theme: ThemeData(
          useMaterial3: true,
        ),
      ),

This is the default behavior.

Upvotes: 1

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63594

I think you are looking from this

child: StretchingOverscrollIndicator(
  axisDirection: AxisDirection.down,
  child: ListView.builder(
    itemCount: 12,
    itemBuilder: (context, index) {
      return ListTile(
        title: Text("item $index"),
      );
    },
  ),
),

Upvotes: 2

Related Questions