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

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

相关推荐
黄林晴5 小时前
Google Play 发版链路全面重构:合规前置、审核自动化、生态全面收紧
android·google
通玄6 小时前
Jetpack Compose 入门系列(四):动画基本使用
android
杉氧6 小时前
Kotlin 协程深度解析②:生存指南——掌握结构化并发的生命线
android·kotlin
故渊at6 小时前
第四板块:Android 输入系统与触控事件 | 第十五篇:InputReader 与 InputDispatcher 的触控流水线
android·anr·输入系统·inputdispatcher·inputreader·触控事件·inputevent
方白羽6 小时前
Vibe Coding 四个核心阶段
android·前端·app
潘潘潘8 小时前
Android网络结构分析——有线网络
android
踏雪羽翼9 小时前
Android OpenGL实现十几种美颜功能
android
Android小码家10 小时前
BootAnimation+SE+开机MP4动画播放
android·framework
加农炮手Jinx10 小时前
Flutter for OpenHarmony:pub_updater 命令行工具自动更新专家(DevOps 运维必备) 深度解析与鸿蒙适配指南
android·运维·网络·flutter·华为·harmonyos·devops