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

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

相关推荐
朝星42 分钟前
Android开发[2]:Flow
android·kotlin
MonkeyKing44 分钟前
InheritedWidget 原理与性能
flutter
zzb15801 小时前
Android Activity 与 Intent 学习笔记
android·笔记·学习
studyForMokey1 小时前
【Android面试】动画 & Bitmap
android·面试·职场和发展
liulian09161 小时前
【Flutter For OpenHarmony】Flutter 三方库 flutter_secure_storage 的鸿蒙化适配指南
flutter·华为·学习方法·harmonyos
黑牛儿1 小时前
面试高频问题:从浏览器请求到PHP响应:完整流程拆解
android·后端·面试·php
liulian09162 小时前
【Flutter For OpenHarmony】Flutter 三方库 flutter_local_notifications 的鸿蒙化适配指南
flutter·华为·学习方法·harmonyos
IntMainJhy2 小时前
【Flutter 三方库 Provider 】flutter for open harmony的鸿蒙化适配与实战指南✨
flutter·华为·harmonyos
y小花3 小时前
安卓USB服务概述
android·usb
weixin_443478513 小时前
Flutter学习之自定义组件
javascript·学习·flutter