Dan*_*30c 11 dart flutter flutter-layout
有没有人在 Android for Flutter 中遇到过类似fadingEdgeLength这样的事情,这样当你向上滚动项目时,项目开始淡入屏幕顶部?
下面是我的由小部件组成的界面。
如果它有帮助,这些是我所指的属性:
android:fadingEdgeLength="10dp"
android:requiresFadingEdge="horizontal">
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('CMS Users'),
),
body: ListView.builder(
padding: EdgeInsets.only(top: 20.0, left: 4.0),
itemExtent: 70.0,
itemCount: data == null ? 0 : data.length,
itemBuilder: (BuildContext context, int index) {
return Card(
elevation: 10.0,
child: InkWell(
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (BuildContext context) =>
new PeopleDetails("Profile Page", profiles[index]),
));
},
child: ListTile(
leading: CircleAvatar(
child: Text(profiles[index].getInitials()),
backgroundColor: Colors.deepPurple,
radius: 30.0,
),
title: Text(
data[index]["firstname"] + "." + data[index]["lastname"]),
subtitle: Text(
data[index]["email"] + "\n" + data[index]["phonenumber"]),
),
),
);
}),
);
}
}
Run Code Online (Sandbox Code Playgroud)
小智 22
你可以ShaderMask在上面应用 aListView并使用BlendMode来获得你想要的。
Widget animationsList() {
return Expanded(
child: ShaderMask(
shaderCallback: (Rect bounds) {
return LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: <Color>[Colors.transparent,Colors.red],
).createShader(bounds);
},
child: Container(height: 200.0, width: 200.0, color: Colors.blue,),
blendMode: BlendMode.dstATop,
),
);
Run Code Online (Sandbox Code Playgroud)
Kri*_*dor 16
正如其他人所提到的,您可以将 ListView 放在 ShaderMask 下,但是通过少量的额外参数化,您可以获得更好的结果 - 至少如果您想实现我想要的。
您可以选择为 LinearGradient 设置 [stops] 列表:
[stops] 列表(如果指定)必须与 [colors] 具有相同的长度。它为每种颜色指定从开始到结束的矢量分数,介于 0.0 和 1.0 之间。
另外:有混合模式,其中源的颜色通道被忽略,只有不透明度有影响。BlendMode.dstOut 在下面的示例中也是如此。正如您在屏幕截图中看到的,紫色没有具体使用,仅用于矢量的分数。
您可以使用不同的 [blendMode] 设置,其中有很多。
void main() {
runApp(
MaterialApp(
home: Scaffold(
body: FadingListViewWidget(),
),
),
);
}
class FadingListViewWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Container(
height: 320,
child: ShaderMask(
shaderCallback: (Rect rect) {
return LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.purple, Colors.transparent, Colors.transparent, Colors.purple],
stops: [0.0, 0.1, 0.9, 1.0], // 10% purple, 80% transparent, 10% purple
).createShader(rect);
},
blendMode: BlendMode.dstOut,
child: ListView.builder(
itemCount: 100,
itemBuilder: (BuildContext context, int index) {
return Card(
color: Colors.orangeAccent,
child: ListTile(
title: Text('test test test test test test'),
),
);
},
),
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
Mik*_*kin 11
我有类似的请求,所以我为此任务创建了一个库。您可以在这里找到它:fading_edge_scrollview
要使用它,您需要添加一个ScrollController到您的ListView,然后将其ListView作为子级传递给FadingEdgeScrollView.fromScrollView构造函数
用 Stack 包裹 Listview,将 Listview 添加为第一个子视图,第二个是带有 LinearGradient 的 Positioned Container。我的代码示例:
堆:
return Stack(
children: <Widget>[
ListView(
scrollDirection: Axis.horizontal,
children: _myListOrderByDate,
),
FadeEndListview(),
],
);
Run Code Online (Sandbox Code Playgroud)
覆盖类:
class FadeEndListview extends StatelessWidget {
const FadeEndListview({
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Positioned(
right: 0,
width: 8.0,
height: kYoutubeThumbnailsHeight,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerRight,
end: Alignment.centerLeft,
stops: [0.0, 1.0],
colors: [
Theme.of(context).scaffoldBackgroundColor,
Theme.of(context).scaffoldBackgroundColor.withOpacity(0.0),
],
),
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
它看起来像这样:
尝试使用
Text(
'This is big text, I am using Flutter and trying to fade text',
overflow: TextOverflow.fade,
maxLines: 1,
),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10358 次 |
| 最近记录: |