我正在尝试在gridview上方显示一个搜索栏(来自流构建器).我想像搜索栏一样向上滚动gridview.我已经尝试了很多方法将它们包装在扩展/灵活的小部件中,但我总是遇到错误.有人管理过吗?
这就是我现在所拥有的,它将滚动但搜索栏保持在顶部.
new Column( children: <Widget>[ new Flexible( child: new Column( children: <Widget>[ new Container( margin: new EdgeInsets.only(left: 4.0,right: 4.0),color: Colors.white,child: new Row( children: <Widget>[ new Container( margin: new EdgeInsets.only(left: 8.0,right: 8.0,top: 8.0,bottom: 8.0),child: Icon(Icons.search),),new Container( child: Flexible( child: new TextField( onChanged: (String text) { setState(() { _searchController.text = text; }); },decoration: new Inputdecoration.collapsed(hintText: 'Search...'),controller: _searchController,) ),],new Flexible( child: new StreamBuilder( stream: stgDocument.collection('people').orderBy('scroll').snapshots(),builder: (context,snapshot) { if (!snapshot.hasData) return const Text('Loading...'); _getMembers(snapshot); return new GridView.builder( //itemCount: snapshot.data.documents.length,itemCount: _searchedMemberList.length,gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),itemBuilder: (context,index) => _buildPeopleCards(context,_searchedMemberList[index]),//_buildPeopleCards(context,snapshot.data.documents[index]) ); } ) ),)
解决方法
您可以使用下面的结构创建一个包含多个子项的可滚动
ListView,其中一个为
GridView.要为ListView中的所有元素启用滚动,需要将其参数物理设置为
NeverScrollablePhysics.
- ListView - Container // your searchbar would go here - GridView // physics: NeverScrollablePhysics - Children
import 'package:Flutter/material.dart'; import 'package:cached_network_image/cached_network_image.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData(),home: Scaffold( body: ListView( children: <Widget>[ Container( color: Colors.red,height: 50.0,GridView.count( physics: NeverScrollableScrollPhysics(),crossAxisCount: 3,shrinkWrap: true,children: generateNumbers().map((int i) { return Text(i.toString()); }).toList(),) ],); } List<int> generateNumbers() => List<int>.generate(30,(i) => i + 1); }
结果如下:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。