Flutter Tabs "Horizontal viewport was given unbounded height" - flutter

I use standard tabs after a few of my blocks. The content in the tabs is styled using a container. The main parent element is Column in which I build all my blocks. I have tried various options using Expanded.
The error sometimes changes to "RenderFlex children have non-zero flex but incoming height constraints are unbounded." This only happens when i try to add tabs, any other block is displayed correctly in my main Column.
body: SafeArea(
child: SingleChildScrollView(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/background.png"),
fit: BoxFit.fill,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: < Widget > [
SizedBox(height: 20),
Container(
margin: EdgeInsets.symmetric(horizontal: 15),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(32),
),
child: TextField(
decoration: InputDecoration(
hintStyle: TextStyle(fontSize: 14),
hintText: 'Найти услугу...',
suffixIcon: Icon(Icons.search),
border: InputBorder.none,
contentPadding:
EdgeInsets.symmetric(horizontal: 20, vertical: 15),
),
),
),
SizedBox(height: 20),
Container(
height: 450,
padding: EdgeInsets.only(top: 35),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/ps-bg.png"),
fit: BoxFit.cover,
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: < Widget > [
SvgPicture.asset(
'assets/ps-logo.svg',
),
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * 0.35,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color.fromRGBO(6, 85, 152, 0),
Color(0xFF084A82),
],
)
),
child: CarouselSlider(
options: CarouselOptions(
autoPlay: false,
aspectRatio: 16 / 10,
enlargeCenterPage: true,
viewportFraction: 0.6,
),
items: imgList.map((item) => LayoutBuilder(builder: (context, constraints) {
return ClipRRect(
borderRadius: BorderRadius.all(
Radius.circular(20.0),
),
child: Stack(
children: < Widget > [
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(20.0),
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: < Widget > [
Image.asset(
'assets/psplus-1month.png',
fit: BoxFit.cover,
width: constraints.maxWidth,
height: constraints.maxHeight / 2,
),
SizedBox(height: 23),
Text(
'Playstation Plus',
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xFF4F4F4F),
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 5),
Text(
'1 месяц',
style: TextStyle(
color: const Color(0xFFA5ABC8),
fontSize: 12,
),
),
SizedBox(height: 5),
Text(
'1 500 рублей',
style: TextStyle(
color: const Color(0xFF789EEB),
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
SizedBox(height: 5),
],
),
),
Positioned(
bottom: constraints.maxHeight / 2 - 18,
left: 0.0,
right: 0.0,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: < Widget > [
Container(
decoration: BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
blurRadius: 7,
color: Colors.black.withOpacity(0.10),
spreadRadius: 2)
],
),
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 18,
child: Icon(Icons.add),
),
)
],
),
),
],
),
);
}, ), ).toList()
)
),
]
),
),
SizedBox(height: 20),
DefaultTabController(
length: 3,
child: Column(
children: [
Container(
margin: EdgeInsets.symmetric(horizontal: 15.0),
child: TabBar(
indicator: BoxDecoration(
borderRadius: BorderRadius.circular(50), // Creates border
color: const Color(0xFF62A6E9)
),
labelColor: Colors.white,
unselectedLabelColor: Colors.grey,
labelStyle: TextStyle(fontSize: 13.0),
tabs: [
Tab(text: 'Инструкция'),
Tab(text: 'Оплаты'),
Tab(text: 'Информация'),
],
),
),
TabBarView(
children: [
Container(
margin: EdgeInsets.all(15.0),
padding: EdgeInsets.all(20.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(30))
),
child: Text(
'Text',
textAlign: TextAlign.left,
style: TextStyle(
color: const Color(0xFF4F4F4F),
height: 1.5,
fontSize: 15,
fontFamily: 'Montserrat',
fontWeight: FontWeight.w500,
),
),
),
Container(
margin: EdgeInsets.all(15.0),
padding: EdgeInsets.all(20.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(30))
),
child: Text(
'Text',
textAlign: TextAlign.left,
style: TextStyle(
color: const Color(0xFF4F4F4F),
height: 1.5,
fontSize: 15,
fontFamily: 'Montserrat',
fontWeight: FontWeight.w500,
),
),
),
Container(
margin: EdgeInsets.all(15.0),
padding: EdgeInsets.all(20.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(30))
),
child: Text(
'Text',
textAlign: TextAlign.left,
style: TextStyle(
color: const Color(0xFF4F4F4F),
height: 1.5,
fontSize: 15,
fontFamily: 'Montserrat',
fontWeight: FontWeight.w500,
),
),
),
],
),
]
)
),
GridView.count(
crossAxisCount: 2,
shrinkWrap: true,
physics: ScrollPhysics(),
scrollDirection: Axis.vertical,
children: List.generate(10, (index) {
return Container(
child: Container(
margin: EdgeInsets.all(15.0),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(30.0)),
child: Stack(
children: < Widget > [
Image.network(
'https://images.unsplash.com/photo-1519125323398-675f0ddb6308?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=94a1e718d89ca60a6337a6008341ca50&auto=format&fit=crop&w=1950&q=80',
fit: BoxFit.cover,
width: 1000.0),
Positioned(
bottom: 0.0,
left: 0.0,
right: 0.0,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: < Widget > [
Container(
decoration:
BoxDecoration(color: Colors.white),
padding: EdgeInsets.only(
top: 15.0,
bottom: 15.0
),
child: Text(
'PUBG',
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xFF4F4F4F),
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
Positioned(
bottom: 40.0,
left: 0.0,
right: 0.0,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment:
CrossAxisAlignment.stretch,
children: < Widget > [
CircleAvatar(
backgroundColor: Colors.white,
radius: 15,
child: Icon(Icons.add),
),
],
),
),
],
)),
),
);
}),
),
]
)
)
))

Ok i found solution, TabBarView need height, Expanded not help.
Container(
height: MediaQuery.of(context).size.height,
child: TabBarView(
children: [
Icon(Icons.directions_car),
Icon(Icons.directions_car),
Icon(Icons.directions_car)
],
),
)

Wrap in LayoutBuilder:
LayoutBuilder(
builder: (_, BoxConstraints viewportConstraints) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: viewportConstraints.maxHeight,
),
child: Column(),
);
},
),

Related

Flutter can't render an Expanded Widget inside a SingleChildScrollView

So i have this build method:
#override
Widget build(BuildContext context) {
return Scaffold(
body: _createBody(),
);
}
Widget _createBody(){
return SafeArea(
child: Column(
children: [
Container(
margin: const EdgeInsets.only(top: 5, left: 10, right: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"xOrder HD",
style: TextStyle(
color: Colors.blue[900],
fontSize: 36
),
),
Container(
padding: const EdgeInsets.only(left: 13, top: 13),
alignment: Alignment.bottomLeft,
child: Text(AppVersion.xOrderVersion()),
)
],
)
),
Container(
margin: const EdgeInsets.symmetric(horizontal: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.solutionFor,
textAlign: TextAlign.start,
),
],
)
),
Expanded(
child: Container(
margin: const EdgeInsets.only(left: 25, right: 25, top: 20, bottom: 10),
child: Row(
children: [
Expanded(
child: Container(
child: Column(
children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.companyList,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
)
),
],
),
decoration: BoxDecoration(
color: mainColor,
borderRadius: const BorderRadius.only(topLeft: Radius.circular(4), topRight: Radius.circular(4))
),
),
_loadedAziende.isEmpty ?
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.noCompanyFound,
style: const TextStyle(
color: Colors.black54,
fontSize: 16
)
),
const SizedBox(height: 50,),
GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => QrCodeScanner(delegate: this,)));
},
child: Material(
elevation: 5,
borderRadius: const BorderRadius.all(Radius.circular(5)),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.add, color: Colors.white,),
const SizedBox(width: 10,),
Text(
AppLocalizations.of(context)!.newCompany,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white,
)
),
],
),
decoration: BoxDecoration(
color: mainColor,
borderRadius: const BorderRadius.all(Radius.circular(5))
),
),
)
)
],
)
)
:
Expanded(
child: Stack(
children: [
ListView.separated(
itemCount: _aziendeToShow.length,
itemBuilder: (ctx, index) {
return InfoCell(
info: _aziendeToShow[index],
delegate: this,
);
},
separatorBuilder: (ctx, index) => const Divider(height: 1,),
),
Positioned(
bottom: 15,
right: 15,
child: GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => QrCodeScanner(delegate: this,)));
},
child: Container(
padding: const EdgeInsets.all(10),
child: const Icon(Icons.qr_code_scanner, color: Colors.white, size: 28),
decoration: BoxDecoration(
color: mainColor,
shape: BoxShape.circle
),
)
)
)
],
)
)
],
),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border.all(color: Colors.grey[500]!),
borderRadius: const BorderRadius.all(Radius.circular(5))
),
),
),
if(_loadedAziende.isNotEmpty)
const SizedBox(width: 25,),
if(_loadedAziende.isNotEmpty)
Expanded(
child: Container(
child: Column(
children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.login,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
)
),
],
),
decoration: BoxDecoration(
color: mainColor,
borderRadius: const BorderRadius.only(topLeft: Radius.circular(4), topRight: Radius.circular(4))
),
),
isEmptyOrNull(_selectedAzienda) ?
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.selectAcompany,
style: const TextStyle(
color: Colors.black54,
fontSize: 16
)
),
],
)
)
:
Expanded(
child: Column(
children: [
Container(
height: 150,
margin: const EdgeInsets.symmetric(vertical: 20, horizontal: 10),
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color: Colors.grey[400]!),
image: DecorationImage(
image: Image.network(_selectedAzienda!.aziendaLogo).image,
fit: BoxFit.contain
)
),
),
Text(
_selectedAzienda!.aziendaCode,
style: const TextStyle(
color: Colors.black,
fontSize: 25,
fontWeight: FontWeight.bold
),
),
Container(
margin: const EdgeInsets.symmetric(vertical: 30, horizontal: 15),
child: const TextField(
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
icon: Icon(Icons.person),
border: OutlineInputBorder(),
labelText: 'Username',
),
)
),
Container(
margin: const EdgeInsets.only(bottom: 30, left: 15, right: 15),
child: const TextField(
obscureText: true,
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
icon: Icon(Icons.password),
border: OutlineInputBorder(),
labelText: 'Password',
),
)
),
const Spacer(),
Container(
margin: const EdgeInsets.symmetric(vertical: 15, horizontal: 15),
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.login, color: Colors.white,),
const SizedBox(width: 15,),
Text(
AppLocalizations.of(context)!.login,
style: const TextStyle(
fontSize: 22,
color: Colors.white,
fontWeight: FontWeight.bold
),
)
],
),
decoration: BoxDecoration(
color: mainColor,
borderRadius: const BorderRadius.all(Radius.circular(5))
),
)
],
)
)
],
),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border.all(color: Colors.grey[500]!),
borderRadius: const BorderRadius.all(Radius.circular(5))
)
),
)
],
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
margin: const EdgeInsets.all(10),
height: 82,
width: 135,
decoration: BoxDecoration(
image: DecorationImage(
image: Image.asset("assets/images/logo-axentya-inv.png").image,
fit: BoxFit.fill
)
),
)
],
)
],
),
);
}
And this is the final result:
The problem presents when i click on the TextField and the keyboard shows up going above the TextFields and showing up the black and yellow banner:
I don't know why in this screenshot the keyboard doesn't show up, but i swear that is opened.
If i try to put the main Column container inside a SingleChildScrollView, the compiler tells me it cannot render it cause I'm not specifying the height dimensions.
How should i fix this.
You cannot use Expanded inside SingleChildScrollView. However, you can use CustomScrollView along with SliverFillRemaining widget to achieve that:
class TestPage extends StatelessWidget {
const TestPage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: [
SliverFillRemaining(
hasScrollBody: true,
child: _createBody(),
)
],
),
);
}
Widget _createBody(){
return SafeArea(
child: Column(
children: [
Container(
margin: const EdgeInsets.only(top: 5, left: 10, right: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"xOrder HD",
style: TextStyle(
color: Colors.blue[900],
fontSize: 36
),
),
Container(
padding: const EdgeInsets.only(left: 13, top: 13),
alignment: Alignment.bottomLeft,
child: Text(AppVersion.xOrderVersion()),
)
],
)
),
Container(
margin: const EdgeInsets.symmetric(horizontal: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.solutionFor,
textAlign: TextAlign.start,
),
],
)
),
Expanded(
child: Container(
margin: const EdgeInsets.only(left: 25, right: 25, top: 20, bottom: 10),
child: Row(
children: [
Expanded(
child: Container(
child: Column(
children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.companyList,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
)
),
],
),
decoration: BoxDecoration(
color: mainColor,
borderRadius: const BorderRadius.only(topLeft: Radius.circular(4), topRight: Radius.circular(4))
),
),
_loadedAziende.isEmpty ?
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.noCompanyFound,
style: const TextStyle(
color: Colors.black54,
fontSize: 16
)
),
const SizedBox(height: 50,),
GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => QrCodeScanner(delegate: this,)));
},
child: Material(
elevation: 5,
borderRadius: const BorderRadius.all(Radius.circular(5)),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.add, color: Colors.white,),
const SizedBox(width: 10,),
Text(
AppLocalizations.of(context)!.newCompany,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white,
)
),
],
),
decoration: BoxDecoration(
color: mainColor,
borderRadius: const BorderRadius.all(Radius.circular(5))
),
),
)
)
],
)
)
:
Expanded(
child: Stack(
children: [
ListView.separated(
itemCount: _aziendeToShow.length,
itemBuilder: (ctx, index) {
return InfoCell(
info: _aziendeToShow[index],
delegate: this,
);
},
separatorBuilder: (ctx, index) => const Divider(height: 1,),
),
Positioned(
bottom: 15,
right: 15,
child: GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => QrCodeScanner(delegate: this,)));
},
child: Container(
padding: const EdgeInsets.all(10),
child: const Icon(Icons.qr_code_scanner, color: Colors.white, size: 28),
decoration: BoxDecoration(
color: mainColor,
shape: BoxShape.circle
),
)
)
)
],
)
)
],
),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border.all(color: Colors.grey[500]!),
borderRadius: const BorderRadius.all(Radius.circular(5))
),
),
),
if(_loadedAziende.isNotEmpty)
const SizedBox(width: 25,),
if(_loadedAziende.isNotEmpty)
Expanded(
child: Container(
child: Column(
children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.login,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
)
),
],
),
decoration: BoxDecoration(
color: mainColor,
borderRadius: const BorderRadius.only(topLeft: Radius.circular(4), topRight: Radius.circular(4))
),
),
isEmptyOrNull(_selectedAzienda) ?
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.selectAcompany,
style: const TextStyle(
color: Colors.black54,
fontSize: 16
)
),
],
)
)
:
Expanded(
child: ListView(
children: [
Container(
height: 150,
margin: const EdgeInsets.symmetric(vertical: 20, horizontal: 10),
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color: Colors.grey[400]!),
image: DecorationImage(
image: Image.network(_selectedAzienda!.aziendaLogo).image,
fit: BoxFit.contain
)
),
),
Text(
_selectedAzienda!.aziendaCode,
style: const TextStyle(
color: Colors.black,
fontSize: 25,
fontWeight: FontWeight.bold
),
),
Container(
margin: const EdgeInsets.symmetric(vertical: 30, horizontal: 15),
child: const TextField(
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
icon: Icon(Icons.person),
border: OutlineInputBorder(),
labelText: 'Username',
),
)
),
Container(
margin: const EdgeInsets.only(bottom: 30, left: 15, right: 15),
child: const TextField(
obscureText: true,
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
icon: Icon(Icons.password),
border: OutlineInputBorder(),
labelText: 'Password',
),
)
),
const Spacer(),
Container(
margin: const EdgeInsets.symmetric(vertical: 15, horizontal: 15),
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.login, color: Colors.white,),
const SizedBox(width: 15,),
Text(
AppLocalizations.of(context)!.login,
style: const TextStyle(
fontSize: 22,
color: Colors.white,
fontWeight: FontWeight.bold
),
)
],
),
decoration: BoxDecoration(
color: mainColor,
borderRadius: const BorderRadius.all(Radius.circular(5))
),
)
],
)
)
],
),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border.all(color: Colors.grey[500]!),
borderRadius: const BorderRadius.all(Radius.circular(5))
)
),
)
],
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
margin: const EdgeInsets.all(10),
height: 82,
width: 135,
decoration: BoxDecoration(
image: DecorationImage(
image: Image.asset("assets/images/logo-axentya-inv.png").image,
fit: BoxFit.fill
)
),
)
],
)
],
),
);
}
}
Add this resizeToAvoidBottomPadding: false to the Scaffold.
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
body: _createBody(),
);
}
EDIT:
If you use de flutter_keyboard_visibility to reduce the logo image when the soft Keyboard is shown would be something like this:
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
#override
Widget build(BuildContext context) {
return KeyboardVisibilityBuilder(builder: (context, isKeyboardVisible) {
return Scaffold(
resizeToAvoidBottomInset: false,
body: _createBody(isKeyboardVisible),
);
});
}
Widget _createBody(bool isKeyboardVisible) {
...
Expanded(
child: Column(
children: [
Container(
height: isKeyboardVisible ? 50 : 150, <<--- HERE
margin: const EdgeInsets.symmetric(
vertical: 20, horizontal: 10),
decoration: BoxDecoration(
shape: BoxShape.circle,
border:
Border.all(color: Colors.grey[400]!),
image: DecorationImage(...
),
}
The answer is in the error itself. When the column is inside a view that is scrollable, the column is trying to shrink-wrap its content but since you used Expanded as a child of the column it is working opposite to the column trying to shrink-wrap its children. This is causing this error because these two directives are completely opposite to each other.
As mentioned in the error logs try the following:
Consider setting mainAxisSize to MainAxisSize.min (for column) and using FlexFit.loose fits for the flexible(use Flexible rather than Expanded).

how to insert backround image in one row (whole row)

I want to insert background image in one row in flutter
when I insert background image does not take up the entire row, only is displayed in one container
you can see this issue below image (I insert black background image for to be seen better):
Widget getBody() {
var size = MediaQuery.of(context).size;
return Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10)),
color: Colors.red),
child: SingleChildScrollView(
child: Column(
children: [
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Container(
height: 1,
decoration:
BoxDecoration(color: Colors.grey.withOpacity(0.2)),
),
),
SizedBox(
width: 10,
),
Text(
"درصد تخفیف برای 30 عدد",
style: TextStyle(color: Colors.black54),
),
SizedBox(
width: 10,
),
Flexible(
child: Container(
height: 1,
decoration:
BoxDecoration(color: Colors.grey.withOpacity(0.2)),
),
),
],
),
SizedBox(
height: 15,
),
Column(
children: List.generate(nardeban_data.length, (index) {
return Column(
children: [
Padding(
padding: const EdgeInsets.only(right: 20, left: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/images/bg.png"),
fit: BoxFit.cover,
),
),
width: (size.width - 40) * 0.68,
child: Row(
children: [
Container(
width: 40,
decoration: BoxDecoration(
color: Colors.blue,
border: Border.all(color: Colors.blue),
borderRadius:
BorderRadius.circular(40.0)),
child: Padding(
padding: EdgeInsets.all(10.0),
child: Text("14",
style: TextStyle(
fontSize: 13.0,
fontWeight: FontWeight.bold,
color: Colors.white)))),
SizedBox(
width: 10,
),
Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
nardeban_data[index]['name'],
style: TextStyle(
fontSize: 14,
color: Colors.black54,
fontWeight: FontWeight.w400),
overflow: TextOverflow.ellipsis,
),
Text(
nardeban_data[index]['takhfif'],
style: TextStyle(
fontSize: 12,
color: Colors.blue,
),
overflow: TextOverflow.ellipsis,
),
],
),
)
],
),
),
Container(
width: (size.width - 90) * 0.32,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.green)),
child: Padding(
padding: const EdgeInsets.only(
right: 10, bottom: 4, left: 10, top: 4),
child: Row(
children: [
SizedBox(
width: 25,
height: 25,
child: TextField(
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: '4%',
border: InputBorder.none,
contentPadding: EdgeInsets.only(
bottom: 8,
top: 3,
),
),
),
)
],
),
),
),
Icon(
Icons.notifications,
size: 22,
color: Colors.blue.withOpacity(0.7),
)
],
),
)
],
),
),
SizedBox(
height: 5,
),
Divider()
],
);
})),
],
),
),
);
}
wrap Row with Container and add decoration in container
like this:
Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/images/bg.png"),
fit: BoxFit.cover,
),),
child: Row(
........
)
Full code:
Widget getBody() {
var size = MediaQuery.of(context).size;
return Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10)),
color: Colors.red),
child: SingleChildScrollView(
child: Column(
children: [
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Container(
height: 1,
decoration:
BoxDecoration(color: Colors.grey.withOpacity(0.2)),
),
),
SizedBox(
width: 10,
),
Text(
"درصد تخفیف برای 30 عدد",
style: TextStyle(color: Colors.black54),
),
SizedBox(
width: 10,
),
Flexible(
child: Container(
height: 1,
decoration:
BoxDecoration(color: Colors.grey.withOpacity(0.2)),
),
),
],
),
SizedBox(
height: 15,
),
Column(
children: List.generate(5, (index) {
return Column(
children: [
Padding(
padding: const EdgeInsets.only(right: 20, left: 20),
child: Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/images/bg.png"),
fit: BoxFit.cover,
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: (size.width - 40) * 0.68,
child: Row(
children: [
Container(
width: 40,
decoration: BoxDecoration(
color: Colors.blue,
border: Border.all(color: Colors.blue),
borderRadius:
BorderRadius.circular(40.0)),
child: Padding(
padding: EdgeInsets.all(10.0),
child: Text("14",
style: TextStyle(
fontSize: 13.0,
fontWeight: FontWeight.bold,
color: Colors.white)))),
SizedBox(
width: 10,
),
Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Name",
style: TextStyle(
fontSize: 14,
color: Colors.black54,
fontWeight: FontWeight.w400),
overflow: TextOverflow.ellipsis,
),
Text(
' nardeban_data',
style: TextStyle(
fontSize: 12,
color: Colors.blue,
),
overflow: TextOverflow.ellipsis,
),
],
),
)
],
),
),
Container(
width: (size.width - 90) * 0.32,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.green)),
child: Padding(
padding: const EdgeInsets.only(
right: 10, bottom: 4, left: 10, top: 4),
child: Row(
children: [
SizedBox(
width: 25,
height: 25,
child: TextField(
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: '4%',
border: InputBorder.none,
contentPadding: EdgeInsets.only(
bottom: 8,
top: 3,
),
),
),
)
],
),
),
),
Icon(
Icons.notifications,
size: 22,
color: Colors.blue.withOpacity(0.7),
)
],
),
)
],
),)
),
SizedBox(
height: 5,
),
Divider()
],
);
})),
],
),
),
);
}
Add this code
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("filename")// or networkImage() or anything,
),),
to the row's container

how to set value style in center (at TextField Flutter)

how I can handle value in TextField in flutter?
in this picture, you can see this value is up in Textfield and I want to this value be center in box:
I want this hintText value be center I don't know how I can do that.
and I have another problem that is how I can remove underline on this box but it isn't necessary, my first question is important.
this is my code:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:project/data/data_nardeban.dart';
class ResultLadder extends StatefulWidget implements PreferredSizeWidget {
class _ResultLadderState extends State<ResultLadder> {
Widget getBody() {
var size = MediaQuery.of(context).size;
return Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10)),
color: Colors.white),
child: SingleChildScrollView(
child: Column(
children: [
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Container(
height: 1,
decoration:
BoxDecoration(color: Colors.grey.withOpacity(0.2)),
),
),
SizedBox(
width: 10,
),
Text(
"درصد تخفیف برای 30 عدد",
style: TextStyle(color: Colors.black54),
),
SizedBox(
width: 10,
),
Flexible(
child: Container(
height: 1,
decoration:
BoxDecoration(color: Colors.grey.withOpacity(0.2)),
),
),
],
),
SizedBox(
height: 15,
),
Column(
children: List.generate(nardeban_data.length, (index) {
return Column(
children: [
Padding(
padding: const EdgeInsets.only(right: 20, left: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: (size.width - 40) * 0.68,
child: Row(
children: [
Container(
width: 40,
decoration: BoxDecoration(
color: Colors.blue,
border: Border.all(color: Colors.blue),
borderRadius: BorderRadius.circular(40.0)
),
child: Padding(
padding: EdgeInsets.all(10.0),
child: Text("14", style: TextStyle(fontSize: 13.0, fontWeight: FontWeight.bold,color: Colors.white))
)
),
SizedBox(
width: 10,
),
Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
nardeban_data[index]['name'],
style: TextStyle(
fontSize: 14,
color: Colors.black54,
fontWeight: FontWeight.w400),
overflow: TextOverflow.ellipsis,
),
Text(
nardeban_data[index]['takhfif'],
style: TextStyle(
fontSize: 12,
color: Colors.blue,
),
overflow: TextOverflow.ellipsis,
),
],
),
)
],
),
),
Container(
width: (size.width - 40) * 0.32,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.green)),
child: Padding(
padding: const EdgeInsets.only(
right: 10, bottom: 4, left: 10, top: 4),
child: Row(
children: [
SizedBox(
height: 25,
width: 25,
child: TextField(
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: '4%',
),
),
)
],
),
),
),
Icon(
Icons.notifications,
size: 16,
color: Colors.blue.withOpacity(0.7),
)
],
),
)
],
),
),
SizedBox(
height: 5,
),
Divider()
],
);
})),
],
),
),
);
}
}
SizedBox(
width: 25,
height: 25,
child: TextField(
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: '4%',
border: InputBorder.none,
contentPadding: EdgeInsets.only(bottom: 10, top:2, ),
),
),
)
just remove height from sizeBox and make textAlign: TextAlign.center in TextField.
to remove underline from Textfield border: InputBorder.none,
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.green)),
child: Padding(
padding: const EdgeInsets.only(
right: 10, bottom: 4, left: 10, top: 4),
child: Row(
children: [
SizedBox(
width: 25,
child: TextField(
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: '4%',
border: InputBorder.none,
),
),
)
],
),
),
),
Icon(
Icons.notifications,
size: 16,
color: Colors.blue.withOpacity(0.7),
)
],
),
)

Flutter - Insert a Listview between two fixed containers

This particular screen is composed of a large container (Height of screen) : This container is composed of three parts : A header (fixed container : 10% of screen size), a footer (fixed container : 10% of screen size) and a middle part : container : height of 80% of screen size.
I would like the middle container to be scrollable : so I inserted a LISTVIEW as the child of this container... but it keeps telling me I get a RenderFlex overflowed.... Why doesn't the content of the middle container scroll in between the header and the footer ??
Here is the code :
Scaffold(
backgroundColor: Colors.indigo[900],
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0,
automaticallyImplyLeading: false,
leading: IconButton(
icon: Icon(Icons.arrow_back_ios_rounded,
color: Colors.red[400], size: 25.0),
onPressed: () {
uD.clearSearchList();
Navigator.pushReplacementNamed(context, StudentHomeScreen.id);
}),
title: Text(
'ETAPE 1 - Découverte',
style: TextStyle(color: Colors.indigo[900], fontSize: 22),
),
actions: [
Container(
margin: const EdgeInsets.only(right: 10),
child: Icon(Icons.memory, size: 45, color: Colors.red[900]),
),
],
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Container(
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
color: Colors.orange[50],
borderRadius: BorderRadius.circular(10.0),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
height: (MediaQuery.of(context).size.height) * 0.12,
padding: const EdgeInsets.fromLTRB(12, 12, 12, 0),
decoration: BoxDecoration(
color: Colors.orange[100],
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Activité 1',
style: TextStyle(
color: Colors.red[900],
fontSize: 30,
fontWeight: FontWeight.bold),
),
Text(
'Mot n°1/24',
style: TextStyle(
color: Colors.indigo[900],
fontSize: 17.0,
),
),
],
),
SleekCircularSlider(
appearance: CircularSliderAppearance(
infoProperties: InfoProperties(
modifier: (reussite) {
return '${reussite.toInt()} / 5';
},
bottomLabelText: 'Réussite',
bottomLabelStyle:
TextStyle(fontSize: 12, color: Colors.red[900]),
),
size: 90,
customColors: CustomSliderColors(
progressBarColor: Colors.green[900]),
customWidths:
CustomSliderWidths(progressBarWidth: 8)),
min: 0,
max: 5,
initialValue: reussite <= 5 ? reussite : 5,
)
],
),
),
Container(
height: (MediaQuery.of(context).size.height) * 0.8,
child: ListView(
shrinkWrap: true,
children: [
Container(
padding: EdgeInsets.all(12.0),
margin: const EdgeInsets.only(top: 8),
child: Text(
'Ecoute et répète 5 fois le mot en anglais.',
style:
TextStyle(color: Colors.indigo[700], fontSize: 17),
),
),
Container(
margin: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
width: 1.0,
),
borderRadius: BorderRadius.circular(10.0),
),
padding: const EdgeInsets.only(top: 16),
child: Row(
children: [
Container(
height: 200,
child: Image.asset(
'images/avatar_teacher.jpeg',
),
),
Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
child: Text(
'An adult',
style: TextStyle(
color: Colors.red[900],
fontSize: 23,
),
),
),
Container(
margin: const EdgeInsets.only(bottom: 60),
child: Text(
'Un adulte',
style: TextStyle(
color: Colors.indigo[900],
fontSize: 15,
),
),
),
GestureDetector(
child: Container(
height: 45,
margin:
EdgeInsets.fromLTRB(0, 5.0, 0, 15.0),
alignment: Alignment.topRight,
child: Icon(
Icons.volume_up,
color: Colors.indigo[500],
size: 55.0,
),
),
onTap: () {
Tts.speak(
phrase: 'little',
langue: Language.english);
},
),
Container(
alignment: Alignment.topRight,
child: Text('/adult/'),
),
],
),
),
],
),
),
Container(
height: 80,
margin: const EdgeInsets.symmetric(vertical: 20),
alignment: Alignment.center,
child: IconButton(
icon: Icon(
Icons.mic,
color: Colors.red[900],
size: 50,
),
onPressed: () async {
uD.checkSpokenWords('adult', reussite);
}),
),
Container(
alignment: Alignment.center,
child: Text(
'Clique sur le micro et répète le mot',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.black45,
fontSize: 15.0,
),
),
),
SizedBox(
height: 50.0,
),
Container(
width: double.infinity,
alignment: Alignment.centerLeft,
margin: const EdgeInsets.only(top: 12),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
width: 1.0,
),
borderRadius: BorderRadius.circular(10.0),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Text('Voici ce que j\'ai compris : '),
Text(uD.spokenWords),
],
),
),
),
],
),
),
Container(
height: (MediaQuery.of(context).size.height) * 0.08,
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.orange[100],
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10),
),
),
margin: const EdgeInsets.only(top: 8),
child: RoundedProgressBar(
milliseconds: 1000,
childLeft: Text(
'Réussite de l\'activité : ',
style: TextStyle(color: Colors.indigo[900]),
),
childRight: Text("$reussite%",
style: TextStyle(color: Colors.red[900])),
percent: reussite,
theme: RoundedProgressBarTheme.blue),
),
],
),
),
),
);
You should replace the middle Container (the one with the 0.8 * MediaQuery height) with Expanded so it will take the available space between the 2 other Containers.

A RenderFlex overflowed Flutter

Trying use Positioned with Stack and Column, getting errors:
"A RenderFlex overflowed by 72 pixels on the bottom."
"A RenderFlex overflowed by 46 pixels on the bottom." etc...
Part of my block just disappears into the slider, i tried to use only Stacked and several Positioned pressed to the bottom of the picture, but then part of the picture is closed.
My dart:
final List<Widget> imageSliders = imgList.map((item) => Container(
child: Container(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(30.0)),
child: Stack(
children: <Widget>[
Container(
alignment: Alignment.bottomCenter,
decoration: BoxDecoration(color: Colors.white),
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Image.asset('assets/psplus-1month.png', fit: BoxFit.cover, width: 1000.0),
Container(
decoration: BoxDecoration(color: Colors.white),
padding: EdgeInsets.only(top: 20.0),
child: Text(
'Playstation Plus',
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xFF4F4F4F),
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
Container(
decoration: BoxDecoration(color: Colors.white),
padding: EdgeInsets.only(bottom: 5.0, top:5.0),
child: Text(
'1 месяц',
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xFFA5ABC8),
fontSize: 12,
),
),
),
Container(
decoration: BoxDecoration(color: Colors.white),
padding: EdgeInsets.only(bottom: 10.0),
child: Text(
'1 500 рублей',
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xFF789EEB),
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
)
],
),
),
Positioned(
bottom: 35.0,
left: 0.0,
right: 0.0,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
boxShadow: [BoxShadow(blurRadius: 10, color: Colors.black.withOpacity(0.10), spreadRadius: 5)],
),
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 15,
child: Icon(Icons.add),
),
)
],
),
),
],
)
),
),
)).toList();
CarouselSlider(
options: CarouselOptions(
autoPlay: false,
aspectRatio: 2.0,
enlargeCenterPage: true,
viewportFraction: 0.6,
),
items: imageSliders,
)
Screenshot for visual example:
If I understood you clear, i'd suggest you to use LayoutBuilder widget to get constraints of parent widget which is CarouselSlider.
Output
Full code
class MyHomePage extends StatefulWidget {
final Function onItemPressed;
MyHomePage({
Key key,
this.onItemPressed,
}) : super(key: key);
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<String> imgList = [
'assets/veg.png',
'assets/veg.png',
'assets/veg.png',
'assets/veg.png',
];
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blue,
body: Padding(
padding: const EdgeInsets.only(top: 50),
child: CarouselSlider(
options: CarouselOptions(
autoPlay: false,
enlargeCenterPage: true,
aspectRatio: 16 / 10,
viewportFraction: 0.6,
),
items: imgList
.map(
(item) => LayoutBuilder(
builder: (context, constraints) {
return ClipRRect(
borderRadius: BorderRadius.all(
Radius.circular(20.0),
),
child: Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(20.0),
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Image.asset(
'$item',
fit: BoxFit.cover,
width: constraints.maxWidth,
height: constraints.maxHeight / 2,
),
SizedBox(height: 23),
Text(
'Playstation Plus',
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xFF4F4F4F),
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 5),
Text(
'1 месяц',
style: TextStyle(
color: const Color(0xFFA5ABC8),
fontSize: 12,
),
),
SizedBox(height: 5),
Text(
'1 500 рублей',
style: TextStyle(
color: const Color(0xFF789EEB),
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
SizedBox(height: 5),
],
),
),
Positioned(
bottom: constraints.maxHeight / 2 - 18,
left: 0.0,
right: 0.0,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
blurRadius: 7,
color: Colors.black.withOpacity(0.10),
spreadRadius: 2)
],
),
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 18,
child: Icon(Icons.add),
),
)
],
),
),
],
),
);
},
),
)
.toList(),
),
),
);
}
}