本文介绍了Flutter-Sliver列表内的Sliver Layout水平滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试在银条列表(CustomScrollview-SliverList)中制作水平可滚动列表
I try to make horizontal scrollable list inside Sliver List (CustomScrollview - SliverList)
这是我的代码:
import 'package:flutter/material.dart';
class DetailScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
DetailAppBar(),
SliverPadding(
padding: EdgeInsets.all(16.0),
sliver: SliverList(
delegate: SliverChildListDelegate(
[
Card(child: Text('data'),),
Card(child: Text('data'),),
Card(child: Text('data'),),
Card(child: Text('data'),),
// Scrollable horizontal widget here
],
),
),
),
],
),
bottomNavigationBar: NavigationButton());
}
}
您能为我提供这种情况的示例或解决方案吗?我真的需要一些帮助.
Can you give me example or solution to this case? i really need some help.
推荐答案
在SliverToBoxAdapter
内使用ListView
.
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverPadding(
padding: EdgeInsets.all(16.0),
sliver: SliverList(
delegate: SliverChildListDelegate(
[
Card(
child: Text('data'),
),
Card(
child: Text('data'),
),
Card(
child: Text('data'),
),
Card(
child: Text('data'),
),
],
),
),
),
SliverToBoxAdapter(
child: Container(
height: 100.0,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 10,
itemBuilder: (context, index) {
return Container(
width: 100.0,
child: Card(
child: Text('data'),
),
);
},
),
),
),
],
),
);
}
这篇关于Flutter-Sliver列表内的Sliver Layout水平滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!