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

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

相关推荐
码力引擎2 分钟前
【零基础学MySQL】第十二章:DCL详解
数据库·mysql·1024程序员节
消失的旧时光-19431 小时前
webView 的canGoBack/goBack 回退栈
android·webview
SHEN_ZIYUAN1 小时前
Flow 责任链模式图解
android
沐怡旸3 小时前
【底层机制】LeakCanary深度解析:从对象监控到内存泄漏分析的完整技术体系
android·面试
又菜又爱coding3 小时前
Android + Flutter打包出来的APK体积太大
android·flutter
LiuYaoheng3 小时前
【Android】Drawable 基础
android·java
QuantumLeap丶5 小时前
《Flutter全栈开发实战指南:从零到高级》- 10 -状态管理setState与InheritedWidget
flutter·前端框架·dart
Pedro5 小时前
Flutter - 日志不再裸奔:pd_log 让打印有型、写盘有序
前端·flutter
Jerry5 小时前
构建 Compose 界面
android
QuantumLeap丶5 小时前
《Flutter全栈开发实战指南:从零到高级》- 09 -常用UI组件库实战
flutter·ios·dart