作者:萱筱璧 | 来源:互联网 | 2022-12-02 18:18
如何在Flutter中更改ListView的发光效果的颜色?
1> diegoveloper..:
不使用主题的另一种选择可能是:
1-将您的ListView包裹在一个 GlowingOverscrollIndicator
2- GlowingOverscrollIndicator
用新的滚动行为将您的ScrollConfiguration 包装在 内部
这里您有:
ScrollConfiguration(
behavior: ScrollBehavior(),
child: GlowingOverscrollIndicator(
axisDirection: AxisDirection.down,
color: Colors.yellow,
child: ListView.builder(
physics: ClampingScrollPhysics(),
itemCount: 15,
itemBuilder: (context, index) {
return ListTile(
title: Text("testing :$index"),
);
},
),
),
),
2> MatPag..:
在这里阅读GlowingOverscrollIndicator似乎可以更改的值ThemeData.accentColor
以更改过度滚动发光颜色。
您可以尝试与此类似的操作以将Theme
更改限制为ListView
唯一
//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);
}
}
您可以在此处了解更多有关如何设置样式的Theme
信息