![](/img/trans.png)
[英]Flutter) I want to know how to apply the same scroll to the child widget list within ListView
[英]How to scroll widget in same time with grid Flutter
我如何同時滾動小部件
Flutter
截屏
這是此屏幕的代碼
return Scaffold(
appBar: CustomAppBar(
scaffoldKey: widget.scaffoldKey,
// icon: AppIcon.settings,
// onActionPressed: onSettingIconPressed,
onSearchChanged: (text) {
setState(() {
if (text.length > 0) {
searching = true;
} else {
searching = false;
}
});
state.filterByUsername(text);
},
),
backgroundColor: Colors.white,
body: new RefreshIndicator(
backgroundColor: Colors.white,
onRefresh: () async {
HapticFeedback.selectionClick();
setState(() {
list3 = state2.getPostList(authstate.userModel);
list3.shuffle();
onlyImages.shuffle();
});
state.getDataFromDatabase();
return Future.value(true);
},
// mesto povise greed, i ispod search boxa
child: new Column(
children: <Widget>[
searching
? ListView.separated(
addAutomaticKeepAlives: false,
physics: BouncingScrollPhysics(),
itemBuilder: (context, index) =>
_UserTile(user: list[index]),
separatorBuilder: (_, index) => Divider(
color: Colors.orange,
height: 0,
),
itemCount: list?.length ?? 0,
)
: slider(),
searching
? ListView.separated(
addAutomaticKeepAlives: false,
physics: BouncingScrollPhysics(),
itemBuilder: (context, index) =>
_UserTile(user: list[index]),
separatorBuilder: (_, index) => Divider(
color: Colors.orange,
height: 0,
),
itemCount: list?.length ?? 0,
)
: Container(
height: 32,
margin: EdgeInsets.only(top: 5, bottom: 5),
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
_tagItem(Icon(Icons.dehaze, color: Colors.orange),
'DAJGI', null, Colors.black, () {
Navigator.pushNamed(
context, '/PhoneConfirmCode');
}),
_tagItem(null, 'Nature', null,
Colors.greenAccent.withOpacity(0.3), null),
_tagItem(
null, 'Animal', null, Colors.brown, null),
_tagItem(null, 'Travel', null, Colors.teal, null),
_tagItem(
null, 'Happy', null, Colors.orange, null),
_tagItem(null, 'Art', null, Colors.blue, null),
_tagItem(
null, 'Night', null, Colors.blueGrey, null),
]),
),
// Grid List
_listOfPosts(),
// Expanded(
// child: GridView.count(
// crossAxisCount: 3,
// children: List.generate(onlyImages.length, (index) {
// return GestureDetector(
// onTap: () {
// FeedModel model = onlyImages[index];
// onPostPressed(context, model);
// },
// // onLongPress: () {
// // _createPopupContext;
// // FeedModel model = onlyImages[index];
// // onPostPressed(context, model);
// // },
// child: Container(
// child: Card(
// child: onlyImages
// .elementAt(index)
// .imagesPath
// .length >
// 0
// ? CachedNetworkImage(
// imageUrl: onlyImages
// .elementAt(index)
// .imagesPath[0],
// fit: BoxFit.cover,
// )
// :
// // Container()
// Center(
// child: Text(onlyImages
// .elementAt(index)
// .description),
// )),
// ));
// }
// ),
// ),
// ),
],
)));
當我現在開始滾動時,只有網格滾動但小部件不動,我希望當用戶開始滾動時這個小部件會上升。誰能告訴我問題出在哪里以及如何解決?
按照評論中的要求更新了完整的代碼。
首先, Column
是不可滾動的,因此要使小部件可滾動是用ListView
而不是Column
包裝這些小部件。 所以你可以做這樣的事情來使小部件可滾動:
RefreshIndicator(
backgroundColor: Colors.white,
onRefresh: (_){},
child: new ListView(
children: <Widget>[
// widget 1,
// widget 2,
// widget 3,
],
),
如果ListView
使小部件可滾動,當ListView
包裝在另一個ListView
中時會發生什么? 可滾動內的可滾動? (嗯,有些情況下你想這樣做,但這里不是這樣,所以是的)。 會有錯誤。
所以為了避免錯誤,只需添加shrinkWrap: true
和physics: ClampingScrollPhysics()
你就可以使用go,如下所示:
RefreshIndicator(
backgroundColor: Colors.white,
onRefresh: (_){},
child: new ListView(
children: <Widget>[
// listview
ListView.separated(
shrinkWrap: true, // <--- add this
physics: ClampingScrollPhysics(), // <--- and this
...
),
// gridview
GridView.builder(
shrinkWrap: true, // <--- add this
physics: ClampingScrollPhysics(), // <--- and this
...
),
],
),
),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.