I am using a tab bar in my app and want to resize the widget inorder to fit the text and have the font size be bigger. I also don't want the tab bar to be scrollable. Is there a way to reduce the padding, or margins or whatever is being used?
Attached is a screenshot of what it currently looks like. The green background was for me to visualize the size. (https://i.stack.imgur.com/WdrHS.png)
Here is my code for the tab bar.
TabBar(
controller: _tabController,
labelPadding: const EdgeInsets.symmetric(horizontal: 35),
indicatorColor: CustomColors.wrkioBlue,
isScrollable: false,
onTap: (index) {
pageController.jumpToPage(index);
},
tabs: const <Widget>[
Tab(//child: SizedBox(width: MediaQuery.of(context).size.width/6,
child: SizedBox(width: 80, child: AutoSizeText('Connections', maxLines: 1, style: TextStyle(fontSize: 16,
color: CustomColors.wrkioBlue)))),
Tab(//child: SizedBox(width: MediaQuery.of(context).size.width/6,
child: SizedBox(width: 80, child: AutoSizeText('Network', maxLines: 1, style: TextStyle(fontSize: 16,
color: CustomColors.wrkioBlue)))),
Tab(//child: SizedBox(width: MediaQuery.of(context).size.width/6,
child: SizedBox(width: 80, child: AutoSizeText('Chats', maxLines: 1, style: TextStyle(fontSize: 16,
color: CustomColors.wrkioBlue)))),
],
),
I have tried using a sized box. Adding padding to the tab child. A few other things I can't remember.
Set isScrollable: true
TabBar(
controller: _tabController,
labelPadding: const EdgeInsets.symmetric(horizontal: 35),
indicatorColor: CustomColors.wrkioBlue,
isScrollable: true, //this
Related
My TabBar Buttons are working fine until I wrap them inside Container with transform property.
However, TabBarView is still working.
I believe something is going wrong with this line : transform: Matrix4.translationValues();
But I need, to include transform the property in my code.
My OverAll Widget Tree is as follows:
Scaffold --> Stack --> GestureDetector --> ListView --> Container -- > Column --> TabBar --> TabBarView.
'''
Container(
// If this property is removed they are working fine.
transform: Matrix4.translationValues(0.0, -50.0, 0.0,),
child: Padding(
padding: const EdgeInsets.all(2.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Card(
clipBehavior: Clip.antiAlias,
margin: const EdgeInsets.only(left: 8.0, right: 8.0),
child: TabBar(
controller: _tabController,
labelColor: Colors.white,
splashBorderRadius: BorderRadius.circular(8.0),
indicatorColor: Colors.white,
indicatorPadding: EdgeInsets.all(AppSizes.size4),
tabs: [
Tab(
text: 'Text 1'
),
Tab(
text: 'Text 2'
),
Tab(
text: 'Text 3',
),
],
),
),
SizedBox(
height: 600,
child: TabBarView(
controller: _tabController,
children: [
// first tab bar view widget
Container1(),
Container2(),
Container3(),
],
),
),
]
),
),
)
'''
Currently i have this structure SingleChildScrollView -> Column, my TabBar is inside the column
Here is my script
SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TabBar(
controller: _tabController,
labelColor: Colors.black,
unselectedLabelColor: Colors.black,
indicatorColor: CustomColors.mainRed,
tabs: [
Tab(text: 'Deskripsi Produk'),
Tab(text: 'Daftar isi'),
],
),
TabBarView(
controller: _tabController,
children: <Widget>[
Html(
data: widget.product.description!,
style: {
// tables will have the below background color
"p": Style(padding: EdgeInsets.all(2.w)),
},
),
GetBuilder<ProductDetailController>(
init: ProductDetailController(),
builder: (data) => ListView.builder(
shrinkWrap: true,
controller: scrollController,
padding: EdgeInsets.all(5.w),
physics: NeverScrollableScrollPhysics(),
itemCount: data.videos.length,
itemBuilder: (context, index) {
return ListTile(
dense: true,
leading: Icon(
Icons.check,
color: CustomColors.mainRed,
size: 12.sp,
),
title: Text(
data.videos[index].video!.title!.toString(),
style: TextStyle(
fontSize: 12.sp,
),
),
);
},
),
),
],
),
],
),
),
I got this error
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during performResize():
Horizontal viewport was given unbounded height.
Viewports expand in the cross axis to fill their container and constrain their children to match
their extent in the cross axis. In this case, a horizontal viewport was given an unlimited amount of
vertical space in which to expand.
I don't set the height because, my tab 1 and my tab 2 will have dynamic content (so, the height cannot fixed) and below the tabbar i want to add another content too. How can i solve this ?
Try this, and remember to use a TabController and a PageController.
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children:[
DefaultTabController(
length: 2,
initialIndex: 0,
child: Column(
children: [
TabBar(
controller: _tabController,
labelColor: Colors.black,
unselectedLabelColor: Colors.black,
indicatorColor: CustomColors.mainRed,
tabs: [
Tab(text: 'Deskripsi Produk'),
Tab(text: 'Daftar isi'),
],
),
ExpandablePageView(
onScoll: (index) {
controller.animateTo(index);
},
controller: _pageController,
children: [
Html(
data: widget.product.description!,
style: {
// tables will have the below background color
"p": Style(padding: EdgeInsets.all(2.w)),
},
),
GetBuilder<ProductDetailController>(
init: ProductDetailController(),
builder: (data) => ListView.builder(
shrinkWrap: true,
controller: scrollController,
padding: EdgeInsets.all(5.w),
physics: NeverScrollableScrollPhysics(),
itemCount: data.videos.length,
itemBuilder: (context, index) {
return ListTile(
dense: true,
leading: Icon(
Icons.check,
color: CustomColors.mainRed,
size: 12.sp,
),
title: Text(
data.videos[index].video!.title!.toString(),
style: TextStyle(
fontSize: 12.sp,
),
),
);
},
),
),
],
),
],
),
),
],
);
Am implementing this plugin here and in the body i create a screen that uses SingleChildScrollView to show some text fields,
Like the documentation says
Body: The Widget that lies underneath the sliding panel. This Widget
automatically sizes itself to fill the screen.
The problem is that when I give focus to one of the text fields the keyboard appears and hides what I am writing,
I use the plugin passing a the widget i want to show behind
SlidingUpPanel(
...
body: Padding(
padding: EdgeInsets.only(top: 160 + padding!.top),
child: behindWidget,
),
...
)
then this
I was trying to enclose my SingleChildScrollView inside a scaffold to use this: resizeToAvoidBottomInset: true, but that doesn't seem to make any difference, does anyone have any idea what I can do? and if there is a way to do it directly from the TextFormField would it be better?
I also have to say that I am using a DefaultTabController and in the first tab I enclose my SingleChildScrollView
like this:
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Padding(
padding: EdgeInsets.only(top: 10),
child: DefaultTabController(
initialIndex: 0,
length: myTabs.length,
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
bottom: TabBar(
labelColor: Colors.black,
labelStyle: smallTextBoldBlack,
unselectedLabelColor: unselectedColor,
unselectedLabelStyle: smallTextUnselectedSecondary,
indicatorColor: Colors.black,
controller: _tabController,
tabs: myTabs,
),
title: Text(
'Create a new Event',
style: subTitle,
),
),
body: TabBarView(
physics: BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
controller: _tabController,
children: [
_buildCreateEventView(),
Text("b"),
],
),
),
),
),
);
}
_buildCreateEventView()
Widget _buildCreateEventView() {
return ExpandableCalendar(
eventList: [],
padding: EdgeInsets.only(top: 20),
onDateSelected: (DateTime selectedDate) => {
if (this.mounted)
setState(() {
currentDate = selectedDate;
})
},
behindWidget: Scaffold(
resizeToAvoidBottomInset: true,
body: Container(
padding: EdgeInsets.only(left: 10, top: 20, right: 10, bottom: 10),
color: Colors.white,
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: SingleChildScrollView(
physics: BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
child: ConstrainedBox(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width,
maxHeight: MediaQuery.of(context).size.height,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.only(top: 10, bottom: 10, left: 5),
child: TextFormField(
controller: eventNameController,
decoration: InputDecoration(
border: UnderlineInputBorder(),
labelText: 'Enter Event Summary',
),
),
),
Container(
padding: EdgeInsets.only(top: 10, bottom: 10, left: 5),
child: TextFormField(
controller: eventDescriptionController,
decoration: InputDecoration(
border: UnderlineInputBorder(),
labelText: 'Enter Event Description',
),
),
),
],
),
),
),
),
));
}
I'm not sure how your ExpandableCalendar class works but I suspect it's what is preventing Flutter from resizing the Scaffold body to move the text fields above the keyboard. If you try temporarily removing ExpandableCalendar and you see the widgets moving above your keyboard that should give you a clue to the underlying issue.
Add One more Container inside SingleChildScrollView and remove Scaffold
Container
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
SingleChildScrollView
Container
ConstrainedBox
I have a SingleChildScrollView and I want to use ScrollController for it. because I want to when the scroll, Reached the top of the page, physics become NeverScrollView .
I want to scroll my list and when I reached the top of the page, can scroll all pages.
and by the way, I use the tab bar for it.
:
Container(
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey, width: 0.3))),
child: TabBar(
indicatorColor: Colors.transparent,
labelColor: Colors.red,
unselectedLabelColor: Colors.black,
tabs: <Widget>[
Tab(
text: "list1",
),
Tab(
text: "list2",
),
Tab(
text: "list",
),
]),
);
here is body :
Container(
height: 2 * pageWidth,
width: pageWidth,
child: TabBarView(
physics: NeverScrollableScrollPhysics(),
children: <Widget>[
SingleChildScrollView(
child: Html(
shrinkWrap: true,
data: resultEp!['Description'],
),
),
SingleChildScrollView(
controller: scrollBarController,
child: ShowCommentEpisodes(
podId: resultEp!['podcast']['Pod_ID'].toString(),
epId: resultEp!['Ep_ID'].toString(),
),
),
SingleChildScrollView(
child: QueuePlaying(
podId: resultEp!['podcast']['Pod_ID'].toString(),
),
),
],
),
),
TabBarView can scroll and when reached the top, all screens can scroll.
I am using TabBarView with tabs in flutter. My tab bar view contains input form. Now when the keyboard opens the widgets overflows
I tried using Listview and SingleChildScrollView to avoid this issue but its not working for me. When using ListView or SingleChildScrollView the screen goes blank.
#override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
return new Scaffold(
resizeToAvoidBottomPadding: true,
body: SafeArea(
child: DefaultTabController(
length: 2,
child: Column(
children: <Widget>[
Expanded(
flex: 0,
child: TabBar(
tabs: [
Tab(text: 'Sign In'),
Tab(text: 'Sign Up'),
],
labelColor: Theme.of(context).primaryColor,
unselectedLabelColor: Colors.grey,
indicatorPadding: const EdgeInsets.symmetric(horizontal: 16.0),
labelPadding: const EdgeInsets.symmetric(vertical: 4.0),
),
),
Expanded(
flex: 1,
child: TabBarView(
children: [_buildSignInForm(), _buildSignupForm()]),
)
],
),
),
),
backgroundColor: Colors.white,
);
}
Wrap your Column inside a Container widget and set the height to match the screen height by :
`height: MediaQuery.of(context).size.height,`