如何解决无法在颤振的单个滚动视图中添加不同的小部件
所以,我有一个容器,高度为屏幕高度,singlechildscrollview 作为其子项。
代码:-
Stack(
children: [
Container(
alignment: Alignment.center,height: MediaQuery.of(context).size.height,decoration: Boxdecoration(
image: decorationImage(
image: Assetimage('assets/coverPhoto.jpg'),fit: BoxFit.cover,colorFilter: new ColorFilter.mode(Colors.black.withOpacity(opacity),BlendMode.srcATop),)
),child: nestedScrollView(
controller: controller,headerSliverBuilder: (BuildContext context,bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
expandedHeight: MediaQuery.of(context).size.height*2/3,floating: false,elevation: 0.0,backgroundColor: Colors.transparent,flexibleSpace: FlexibleSpaceBar(
centerTitle: true,title: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,mainAxisAlignment: MainAxisAlignment.center,children: [
Text(
"Some text",textAlign: TextAlign.center,style: TextStyle(
fontSize: 20,fontWeight: FontWeight.w500,color: Colors.white,),SizedBox(height: 25,Text(
"Some heading",style: TextStyle(
fontSize: 40,fontWeight: FontWeight.bold,],];
},body: Center(
child: SingleChildScrollView(
child: Column(
children: [
SizedBox(height: MediaQuery.of(context).size.height*3/4,Container(
width: MediaQuery.of(context).size.width*7/10,color: const Color(0xff262626),padding: EdgeInsets.symmetric(vertical: 40,horizontal: 100),child: Column(
children: [
Text(
"heading",style: TextStyle(
fontSize: 50,SizedBox(height: 80,Text(
"a content of 3-4 lines",style: TextStyle(
fontSize: 20.0,)
],SizedBox(height: MediaQuery.of(context).size.height/4,abcWidget(),)
abcWidget() 的代码:-
class abcWidget extends StatefulWidget {
const abcWidget({Key key}) : super(key: key);
@override
_abcWidgetState createState() => _abcWidgetState();
}
class _abcWidgetState extends State<abcWidget> with SingleTickerProviderStateMixin{
TabController _tabController;
@override
void initState() {
_tabController = new TabController(length: 4,vsync: this);
super.initState();
}
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
Container serviceTile({String serviceName,String content,String fileName,double width})
{
return Container(
color: const Color(0xff171717),padding: EdgeInsets.fromLTRB(5,20,5,10),child: Column(
children: [
Image.asset('assets/services/$fileName.png',height: width/3.5,Text(
serviceName,style: TextStyle(
color: Colors.white,fontSize: 22.0,SizedBox(height: 10,Text(
content,fontSize: 16.0,fontWeight: FontWeight.w400,);
}
@override
Widget build(BuildContext context) {
return Container(
height: MediaQuery.of(context).size.height,// if i remove this height
padding: EdgeInsets.symmetric(horizontal: 200),width: double.infinity,color: const Color(0xff000000),child: Column(
children: [
Container(
decoration: Boxdecoration(
border: Border(
bottom: BorderSide(
color: const Color(0xff0974b3),width: 2.0,child: Text(
"OUR SERVICES",style: TextStyle(
fontSize: 50.0,SizedBox(height: 30,Text(
"We design & build brands,campaigns & digital projects for businesses large & small.",Text(
"Outstanding Service is Our Duty.",SizedBox(
height: 50,width: MediaQuery.of(context).size.width*1.1/3,child: TabBar(
controller: _tabController,unselectedLabelColor: Colors.grey,indicatorColor: Colors.white,labelColor: Colors.white,tabs: [
Tab(text: "Show All",Tab(text: "Design",Tab(text: "Marketing",Tab(text: "Development",SizedBox(height: 15,Expanded(
child: TabBarView(
physics: NeverScrollableScrollPhysics(),controller: _tabController,children: List.generate(4,(index) => GridView.count(
physics: NeverScrollableScrollPhysics(),shrinkWrap: true,crossAxisCount: 3,mainAxisspacing: 15.0,crossAxisspacing: 15.0,children: [
serviceTile(
serviceName: "Web Development",content: "Web development is the building and maintenance of websites; it’s the work that happens behind the scenes to make a website look great,work fast and perform well with a seamless user experience.",fileName: "web development",width: MediaQuery.of(context).size.width/4,serviceTile(
serviceName: "Web Development",);
}
}
如果我按照代码中的注释从容器中删除上述小部件的高度,则会出现以下错误:-
错误:-
RenderFlex children have non-zero flex but incoming height constraints are unbounded.
如果我不这样做,我就不会在这个小部件中滚动。
解决方法
因为您不能将 Expanded
用于 Column
中,即 Scrollview
内。想想看:扩展成列使用所有可能的垂直空间,所以需要一个有高度的父级才能正常工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。