何在Flutter中更改ListView的过度滚动发光效果的颜色

何在Flutter中更改ListView的过度滚动发光效果的颜色

本文介绍了如何在Flutter中更改ListView的过度滚动发光效果的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Flutter中更改ListView的发光效果的颜色?

How do I change the color of the glow effect of a ListView in Flutter?

推荐答案

在此处阅读 GlowingOverscrollIndicator 似乎可以更改 ThemeData.accentColor 的值以更改过度滚动发光颜色.

Reading here for GlowingOverscrollIndicator seems like you can change the value of ThemeData.accentColor to change the overscroll glow color.

您可以尝试与此类似的操作,以将主题的更改限制为仅限 ListView

You could try with something similar to this to limit the Theme change to the ListView only

//store the current Theme to restore it later
final ThemeData defaultTheme = Theme.of(context);

Theme(
  //Inherit the current Theme and override only the accentColor property
  data: Theme.of(context).copyWith(
    accentColor: Colors.yellow
  ),
  child: ListView.builder(
      //suppose data it's an array of strings
      itemBuilder: (BuildContext context, int index) =>
          EntryItem(data[index], defaultTheme),
      itemCount: data.length,
  ),
);

//this is your class to render rows
class EntryItem extends StatelessWidget {
  const EntryItem(this.entry, this.defaultTheme);

  final String entry;
  final ThemeData defaultTheme;

  Widget _buildTiles(String entry) {
    return Theme(
      data: defaultTheme,
      child: Text(entry)
    );
  }

  @override
  Widget build(BuildContext context) {
    return _buildTiles(entry);
  }
}

这篇关于如何在Flutter中更改ListView的过度滚动发光效果的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 00:52