Incorrect use of ParentDataWidget using TabBarView inside DraggableScrolledScheet - flutter

What I want to achieve
I tried to create a sticky TabBar using StickyHeader plugin inside DraggableScrollSheet.
I try to achieve scrolling like this.
The Problem
But everytime I scrolled, there is "Incorrect use of ParentDataWidget." error.
I have tried to move the TabBar (wrapped by Container) and TabBarView (wrapped by Expanded) outside the StickyHeader and wrapped it with Column, but it doesn't works.
This is my minimal code
return Scaffold(
body: Stack(
children: [
Container(
height: double.infinity,
width: width,
decoration: BoxDecoration(
color: redMain,
),
),
DraggableScrollableSheet(
initialChildSize: 0.82,
minChildSize: 0.82,
builder: (BuildContext context, myScrollController) {
return Column(
children: [
Expanded(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20)),
color: Colors.white,
),
child: ListView(
controller:
myScrollController, // assign controller here
children: [
Column(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Padding(padding: EdgeInsets.only(top: 34)),
Container(
margin: EdgeInsets.only(
left: 16, right: 16, bottom: 8),
child: Text('Featured', style: Title1),
),
Container(
color: Colors.yellow,
height: 100,
),
],
),
StickyHeader(
header: Container(
margin:
EdgeInsets.only(top: 22, bottom: 22),
child: TabBar(
controller: _tabController,
labelColor: Colors.red,
unselectedLabelColor: Colors.grey,
tabs: [
Tab(
child: Text(
"All",
),
),
Tab(
child: Text(
"News",
),
),
],
),
),
content: Container(
height: 2000,
child: Expanded(
child: TabBarView(
controller: _tabController,
children: <Widget>[
Container(
width: double.infinity,
color: Colors.green,
height: height,
),
Container(
width: double.infinity,
color: Colors.blue,
height: height,
),
],
),
),
),
),
],
),
],
)),
),
],
);
},
),
],
),
);
I wrap Expanded with Container and give it "dummy" fixed height because if I only use Expanded, error occured. But actually what I want is infinite scrolling without fixed height.
content: Container(
height: 2000,
child: Expanded(
child: TabBarView(
controller: _tabController,
children: <Widget>[
Column(
The question
How to get rid of "Incorrect use of ParentDataWidget."? And how to make TabBarView infinity scroll without fixed height?

use Positioned widget inside Stack widget

Related

ListViewBuiler inside Row flutter

i am trying to add a listview inside a row , but i got this Error
I have in the row Two widgets the first one with a column , the second widget is the listview builder that return another widget .
I am trying to make the row look like below picture
this is my code
body: SingleChildScrollView(
child: Column(
children: [
Row(
children: [
Column(
children: [
Stack(
children: [
Container(
height: 60,
width: 60,
decoration: const BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
image: DecorationImage(
image: AssetImage("assets/images/meee.jpg"))),
),
Positioned(
bottom: 0,
right: 0,
child: Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.blue, shape: BoxShape.circle),
child: Text(
"+",
style: TextStyle(color: Colors.white),
),
),
)
],
),
const SizedBox(
height: 7,
),
const Text(
"Your Story",
style: TextStyle(color: Colors.white, fontSize: 13),
)
],
),
ListView.builder(
itemCount: 3,
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context, int index) {
return __buildStory();
},
),
],
),
],
),
),
Did you try changing this line
ListView.builder(
with this line
ListView.builder(shrinkWrap: true,
If it does not work, consider wrapping your ListView.builder widget in a Flexible widget
Flexible(child:
Since ListView need all the remaining space in Row, wrap the ListView.builder with a Expanded. Also use shrinkWrap:true in ListView.
Add mainAxisSize: MainAxisSize.min to Column.
body: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: [
Stack(
children: [
Container(
height: 60,
width: 60,
decoration: const BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
image: DecorationImage(
image: AssetImage("assets/images/meee.jpg"))),
),
Positioned(
bottom: 0,
right: 0,
child: Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.blue, shape: BoxShape.circle),
child: Text(
"+",
style: TextStyle(color: Colors.white),
),
),
)
],
),
const SizedBox(
height: 7,
),
const Text(
"Your Story",
style: TextStyle(color: Colors.white, fontSize: 13),
)
],
),
Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: 3,
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context, int index) {
return __buildStory();
},
),
),
],
),
],
),
),

how to create a container without giving it a height in Flutter

have tried to wrapp the tabbarview with expanded but its not working.
I do not want to give the height as the items displayed there can be many.
I want the height to increase the number of items available to be scrolled.
The issue at hand is i do not want to add any height to that container.
Any help
this here is the code in the body where i have my tabbar
child: Column(
children: <Widget>[
Container(
margin: const EdgeInsets.only(left: 20),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Let the party begin!",
style: titleStyle1.copyWith(fontSize: 28.0),
),
]),
),
SizedBox(height: 30.0),
InkWell(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => SlideInRight(
duration: Duration(seconds: 2),
child: Search(),
),
),
);
},
child: Container(
margin: EdgeInsets.only(
right: 20.0, left: 20.0, bottom: 20.0),
height: 45.0,
width: double.infinity,
decoration: BoxDecoration(
color: background,
borderRadius: BorderRadius.all(Radius.circular(5.0)),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
blurRadius: 5.0,
spreadRadius: 0.0)
]),
child: Padding(
padding: const EdgeInsets.only(left: 15.0, right: 15.0),
child: Row(
children: <Widget>[
Text(
'Search...',
style: TextStyle(fontSize: 20, color: grey),
textAlign: TextAlign.left,
),
],
),
),
),
),
TabBar(
controller: _tabController,
physics: ClampingScrollPhysics(),
indicatorColor: authlink,
labelColor: authlink,
unselectedLabelColor: grey,
isScrollable: true,
labelStyle: TextStyle(fontSize: 18.0),
labelPadding: EdgeInsets.symmetric(horizontal: 25),
indicatorSize: TabBarIndicatorSize.label,
tabs: [
Tab(text: "All"),
Tab(text: "Trending"),
Tab(text: "Live"),
Tab(text: "Happening Today"),
]),
Container(
//without this height i get this problem
// height: 580.0,
child: new TabBarView(
controller: _tabController,
children: <Widget>[
Container(
margin: const EdgeInsets.only(top: 25.0),
child: Column(
children: <Widget>[
Container(
child: buildAllComingEventList(),
),
Container(
child: buildNearbyEventList(),
),
Container(
child: moreConcerts(),
),
],
),
),
Container(
child: trendingConcerts(),
),
Container(
height: MediaQuery.of(context).size.height,
child: getStories(),
),
Container(
child: happeningTodayConcerts(),
),
],
),
),
],
),
),```
What if you change other way to layout your page:
Scaffold(
appBar: AppBar(
actions: //your button
flexibleSpace: //your search bar
bottom: //your tab bar
),
body: // your tab view
),

Flutter: Cut widget edges according it's parents

I made this widget :
Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
width: 200,
height: 200,
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.grey,
),
child: GridView.count(
crossAxisCount: 2,
crossAxisSpacing: 4.0,
mainAxisSpacing: 2.0,
children: <Widget>[
Container(
color: Colors.red,
),
Container(
color: Colors.red,
),
Container(
color: Colors.red,
),
Container(
color: Colors.red,
),
],
))
],
),
and this result is:
Now how can cut 4 square's edges according it's parent shape?
You can achieve this using ClipOval.
Wrap your grey container with it :
ClipOval(
child:Container(
//Your grey container
),
),

How to scroll only the tabbarview and set tabbar as fixed in top using SingleChildScrollView

when I am not giving the height property in a container of tabBarView it is giving an error and when wrapping with SingleChildScrollView it is not scrollable and the bottom gets overflowed when input keyboard is raised. But, when I place SingleChildScrollView above the tabBar, it is working and both the tabBar and tabview is scrolling but I want only the tabBarView should be scrolled and not the bar
My code
import 'package:copackd/screens/Shipment.dart';
import 'package:flutter/material.dart';
class TrackingPage extends StatefulWidget {
#override
_TrackingPageState createState() => _TrackingPageState();
}
class _TrackingPageState extends State<TrackingPage> {
#override
Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height;
return Scaffold(
body: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Color.fromRGBO(247, 68, 78, .9),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 80,),
Padding(
padding: EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("Track Your Shipment",style: TextStyle(color: Colors.white,fontSize: 25,fontWeight: FontWeight.bold),),
SizedBox(height: 10,),
Row(
children: <Widget>[
new Expanded(
flex: 8,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [BoxShadow(
color: Color.fromRGBO(247, 68, 78, .3),
blurRadius: 20,
offset: Offset(0,10)
)]
),
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(10, 0, 0, 0),
child: TextField(
decoration: InputDecoration(
hintText: "Enter tracking id",
hintStyle: TextStyle(color: Colors.grey),
border: InputBorder.none
),
),
),
],
),
),
),
Spacer(),
new Expanded(
flex: 2,
child: Container(
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: BorderRadius.circular(10),
boxShadow: [BoxShadow(
color: Color.fromRGBO(247, 68, 78, .3),
blurRadius: 20,
offset: Offset(0,10)
)]
),
child: IconButton(
icon: Icon(Icons.search),
iconSize: 25,
color: Colors.white,
onPressed: () {},
)
),
)
],
),
],
),
),
Expanded(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(topLeft: Radius.circular(60),topRight: Radius.circular(60))
),
child: Padding(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
DefaultTabController(
length: 2,
initialIndex: 0,
child: Column(
children: <Widget>[
TabBar(
indicatorColor: Colors.blue,
labelColor: Colors.black,
labelStyle: TextStyle(fontSize: 15,fontWeight: FontWeight.bold),
tabs: [Tab(text: "Sending"),Tab(text: "Receiving",)]
),
SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
height: height * 0.5,
child: TabBarView(
children: <Widget>[
Sending(),
Receiving(),
],
),
),
],
),
)
],
),
)
],
),
),
),
)
],
),
),
);
}
}
Thanks in advance
add a you code ListView, it resolver you problem, example:
Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height;
return ListView(
Scaffold(
body: Container(
i hope resolver you problem!

TabBarView which in column in SingleChildScrollView needs to wrap in a specified height container

I have a page which contains a TabBar, some other widgets and a TabBarView releated to the above TabBar. The build implementation is like the following.
#override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(color: defaultBackgroundColor),
child: Stack(children: [
Image.asset(
'assets/background/around.jpg',
width: MediaQuery.of(context).size.width,
height: 400,
fit: BoxFit.fill,
),
SingleChildScrollView(
child: Column(
children: <Widget>[
AroundHeader(),
TabBar(
controller: _tabController,
unselectedLabelColor: Colors.white,
indicatorSize: TabBarIndicatorSize.tab,
labelColor: Colors.blue,
indicator: BoxDecoration(
color: Colors.transparent,
border:
Border(bottom: BorderSide(color: Colors.blue, width: 3)),
),
tabs: [
...data.map(
(item) => Tab(
child: Container(
child: Align(
alignment: Alignment.center,
child: Text(item, style: titleStyle),
),
),
),
),
],
),
SizedBox(height: 10),
Padding(
padding: const EdgeInsets.symmetric(vertical: commonMargin),
child: Container(
height: MediaQuery.of(context).size.height + 300,
width: MediaQuery.of(context).size.width - 2 * commonMargin,
child: TabBarView(
controller: _tabController,
children: <Widget>[
AroundRecommend1(),
AroundRecommend2(),
AroundRecommend3(),
AroundRecommend4(),
],
),
),
),
],
),
),
]),
);
}
Because the contents in TabBarView may variable height, AroundRecommend for example is build from a Column.
Now I have to manual calculate the maximum height of the height of children of TabBarView.
I tried to replace the constrained container with a Explanded or SizedBox.expand or IntrinsicHeight and so on, but all of them failed with exception like height is not provided.
You want to wrap the widgets inside the column in Expanded not the Column itself
Column(
children: <Widget>[
Expanded(
child: Container(
height: 200,
color: Colors.redAccent,
),
),
],
);