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滑动波纹

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

相关推荐
alexhilton2 小时前
Android XR 开发入门完全指南
android·kotlin·android jetpack
GitLqr4 小时前
玩转 Flutter 项目依赖:从 pubspec.yaml 到实战包管理
flutter·面试·全栈
云贝贝贝5 小时前
OceanBase认证体系介绍与备考指南
运维·服务器·oceanbase·1024程序员节
2501_915909066 小时前
全面解析iOS应用上架到App Store的完整流程与关键注意事项
android·macos·ios·小程序·uni-app·cocoa·iphone
淡淡的香烟8 小时前
AndroidAI使用心得
android
chjif9 小时前
Android 设备管控开发实战:无障碍如何准确识别当前前台 App?
android
chjif9 小时前
Android 设备管控开发实战:企业受控终端的 DNS 域名策略实现
android·华为·harmonyos
u01030552710 小时前
Java图像处理实战指南
人工智能·1024程序员节
程序员老刘10 小时前
Qwen 3.8 max干了20分钟没干完,免费模型3分17秒搞定,问题出在哪?
flutter·ai编程
c2385611 小时前
MySQL 基础用法(下):查询进阶与核心特性
android·c语言·c++·mysql