flutter开发实战-为ListView去除Android滑动波纹

flutter开发实战-为ListView去除Android滑动波纹

在之前的flutter聊天界面上,由于使用ScrollBehavior时候,当时忘记试试了,今天再试代码发现不对。这里重新记录一下为ListView去除Android滑动波纹的方式。

一、ScrollBehavior

ScrollBehavior是用来描述可滚动Scrollable小部件的行为。

通常使用ScrollConfiguration来为子Widget。

这里我们可以定义它的子类来实现去除Android滑动波纹

定义子类重写buildOverscrollIndicator

复制代码
import 'package:flutter/material.dart';

class ChatScrollBehavior extends ScrollBehavior {
  MenuScrollBehavior();

  @override
  Widget buildOverscrollIndicator(
      BuildContext context, Widget child, ScrollableDetails details) {
    return child;
  }
}

二、为ListView去除Android滑动波纹

ScrollConfiguration为ListView添加ScrollBehavior

示例代码如下

复制代码
	ScrollConfiguration(
          behavior: ChatScrollBehavior(),
          child: ListView.builder(
            controller: scrollController,
            physics: ClampingScrollPhysics(),
            itemBuilder: (context, index) {
              return ChatListCard(
                index: index,
                onPressed: (idx) {
                  widget.onCardPressed(menuModel.deviceObjectDo!, appConfigDo);
                },
              );
            },
            itemCount: 50,
          ),
        ),

三、小结

flutter开发实战-为ListView去除Android滑动波纹

学习记录,每天不停进步。

相关推荐
大鹏说大话12 小时前
PHP 异步处理方案:队列使用场景与 RabbitMQ 实操
android
molihuan12 小时前
最新 Paddle-Lite Android平台编译
android·ocr·paddle·推理·端侧·paddle lite
小肝一下12 小时前
多态(上)
android·开发语言·c++·vscode·多态·面向对象·伊蕾娜
三少爷的鞋13 小时前
Android 面试系列:Retrofit 的 suspend 是如何实现的?
android
solo_991 天前
用 LSPosed 模拟录屏音频编码器卡顿:从思路到落地
android
zzq77971 天前
别把大模型 API Key 写进 APK:移动 AI 应用接口防盗刷实践
android·人工智能·安全·app加固·御盾安全·安卓加固
xiaopang1 天前
RK3568 AOSP 编译与快速部署实战
android
程序员正茂1 天前
Android工程中使用ncnn进行yolo识别
android·yolo·ncnn
码农coding1 天前
android12 SystemUI之通知
android