Flutter RenderFlex overflowed error on AlertDialog when keyboard appear - flutter

i have the following AlertDialog widget that behaves as following :
and here is my code :
showDialog(
context: context,
builder: (context) {
return StatefulBuilder(
builder: (context, setState) {
return AlertDialog(
title: Text(
"Information sur le client $code",
),
content: Container(
height: mobileHeight * 0.75,
width: mobileWidth * 0.9,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
child: IconButton(
icon: Icon(
Icons.edit,
color: Colors.blue,
size: mobileWidth * 0.05,
),
onPressed: () {
setState(() => modifyNom = !modifyNom);
_textNameController.text = snapshot.data.nom;
},
),
),
modifyNom
? Flexible(
child: TextField(
textAlign: TextAlign.center,
style: TextStyle(
fontSize: mobileWidth * 0.05,
),
controller: _textNameController,
decoration: InputDecoration(),
),
)
: Flexible(
child: Text(
'${snapshot.data.nom}',
style: TextStyle(
fontSize: mobileWidth * 0.05,
),
),
),
],
),
Row(
children: [
Container(
child: IconButton(
onPressed: () {
setState(() => modifyContact = !modifyContact);
_textContactController.text = snapshot.data.contact;
},
),
),
Text(
'Contact : ',
),
modifyContact
? Flexible(
child: TextField(
textAlign: TextAlign.center,
controller: _textContactController,
decoration: InputDecoration(),
),
)
: Flexible(
child: Text(
'${snapshot.data.contact}',
),
),
],
),
],
),
),
actions: [
FlatButton(
child: Text("Annuler"),
onPressed: () {
Navigator.of(context).pop(); // dismiss dialog
},
),
],
);
},
);
the issue is when i edit the TextField and the keyboard is shown i get this error :
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during layout:
A RenderFlex overflowed by 211 pixels on the bottom.
The relevant error-causing widget was:
Column file:///C:/Users/asmou/AndroidStudioProjects/flutter_app/lib/Alerts/showAlertInfo.dart:49:28
The overflowing RenderFlex has an orientation of Axis.vertical.
The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and
black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the
RenderFlex to fit within the available space instead of being sized to their natural size.
This is considered an error condition because it indicates that there is content that cannot be
seen. If the content is legitimately bigger than the available space, consider clipping it with a
ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
like a ListView.
The specific RenderFlex in question is: RenderFlex#a3d43 OVERFLOWING:
needs compositing
creator: Column ← FutureBuilder<Client> ← ConstrainedBox ← Container ← DefaultTextStyle ← Padding ←
Flexible ← Column ← IntrinsicWidth ← DefaultTextStyle ← AnimatedDefaultTextStyle ←
_InkFeatures-[GlobalKey#50b4d ink renderer] ← ⋯
parentData: <none> (can use size)
constraints: BoxConstraints(w=283.4, h=173.1)
size: Size(283.4, 173.1)
direction: vertical
mainAxisAlignment: spaceBetween
mainAxisSize: max
crossAxisAlignment: center
verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤

Wrap the Container Widget with ListView or SingleChildScrollView.
showDialog(
context: context,
builder: (context) {
return StatefulBuilder(
builder: (context, setState) {
return AlertDialog(
title: Text(
"Information sur le client $code",
),
content: SingleChildScrollView(
child: Container(
height: mobileHeight * 0.75,
width: mobileWidth * 0.9,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
child: IconButton(
icon: Icon(
Icons.edit,
color: Colors.blue,
size: mobileWidth * 0.05,
),
onPressed: () {
setState(() => modifyNom = !modifyNom);
_textNameController.text = snapshot.data.nom;
},
),
),
modifyNom
? Flexible(
child: TextField(
textAlign: TextAlign.center,
style: TextStyle(
fontSize: mobileWidth * 0.05,
),
controller: _textNameController,
decoration: InputDecoration(),
),
)
: Flexible(
child: Text(
'${snapshot.data.nom}',
style: TextStyle(
fontSize: mobileWidth * 0.05,
),
),
),
],
),
Row(
children: [
Container(
child: IconButton(
onPressed: () {
setState(() => modifyContact = !modifyContact);
_textContactController.text = snapshot.data.contact;
},
),
),
Text(
'Contact : ',
),
modifyContact
? Flexible(
child: TextField(
textAlign: TextAlign.center,
controller: _textContactController,
decoration: InputDecoration(),
),
)
: Flexible(
child: Text(
'${snapshot.data.contact}',
),
),
],
),
],
),
),
),
actions: [
FlatButton(
child: Text("Annuler"),
onPressed: () {
Navigator.of(context).pop(); // dismiss dialog
},
),
],
);
},
);

My whole scaffold body was a Column widget, and I had a similar render overflow error when using AlertDialogs;
Based on the flutter error message ...or using a scrollable container rather than a Flex, like a ListView - I replaced Column for ListView and now I get no render overflow errors when using AlertDialog.
Inside build();
return Scaffold(
body: ListView( // formerly a Column()
// your remaining UI
),
),

Related

Columns shift when SingleChildScrollView is added Flutter

Need help. I have created a column on the page inside which there are 2 more columns, so I moved the buttons that are at the bottom to the very bottom so that they are always at the bottom of the screen. But when I add a SingleChildScrollView to make the page scroll, the space between the columns disappears and the bottom buttons move under other widgets. How can I solve the problem so that when adding a SingleChildScrollView, there is an empty space and the buttons remain at the very bottom of the screen?
body
Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
children: [
const SizedBox(height: 121.0),
BackStepWidget(
text: 'Balance: $coins',
textStyle: constants.Styles.largeHeavyTextStyleWhite,
),
const Text(
'Buy JoinCoins',
style: constants.Styles.bigHeavyTextStyleWhite,
),
const Image(
image: AssetImage('assets/images/image.png'),
),
const Text('I Want To Buy',
style: constants.Styles.smallBoldTextStyleWhite),
const SizedBox(height: 10),
const CoinsCounterWidget(),
const SizedBox(height: 10),
const Text('JoynCoins',
style: constants.Styles.smallBoldTextStyleWhite),
],
),
Column(
children: [
Padding(
padding: const EdgeInsets.only(bottom: 24),
child: DefaultButtonGlow(
text: 'Buy me JoynCoins for 100% battery.',
color: constants.Colors.greyLight.withOpacity(0.4),
textStyle: constants.Styles.buttonTextStyle,
shadowColor: Colors.transparent,
borderColor: constants.Colors.purpleMain,
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return const DefaultAlertDialog(
text:
'Please set a payment method for buying JoynCoins.',
);
},
);
},
),
),
Padding(
padding: const EdgeInsets.only(bottom: 47),
child: DefaultButtonGlow(
text: 'Buy Now ',
color: constants.Colors.purpleMain,
textStyle: constants.Styles.buttonTextStyle,
shadowColor: constants.Colors.purpleMain,
borderColor: constants.Colors.purpleMain,
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return const DefaultAlertDialog(
text: "You'r about to buy",
isText2: true,
text2: '2500 JoynCoins',
);
});
},
),
)
],
)
],
),
));
Added SingleChildScrollView
Without SingleChildScrollView
You can simplify this code to understand the issue. MainAxisAlignment.spaceBetween will provide maximum spaces between widgets.
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("top"),
Text("bottom"),
],
),
Once you wrapped with SingleChildScrollView, Column takes minimum height for its children and become,
You can use SizedBox to provide space between items. You can use LayoutBuidler that I've posted on your previous question. For this I am using MediaQuery
body: SingleChildScrollView(
child: Column(
children: [
Text("top"),
SizedBox(
height: MediaQuery.of(context).size.height * .4,
), // you custom height
Text("bottom"),
],
),
),
Use SizedBox in between Columns or use the following inside Singlechildscrollview
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,

bottom overflowed by 125 pixcels

i want when the user click to float action button, then a bottom sheet opened. the bottom sheet includes input text field and three radios. when i click on input text field, this error occurs:
The overflowing RenderFlex has an orientation of Axis.vertical.
The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and
black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the
RenderFlex to fit within the available space instead of being sized to their natural size.
This is considered an error condition because it indicates that there is content that cannot be
seen. If the content is legitimately bigger than the available space, consider clipping it with a
ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
like a ListView.
The specific RenderFlex in question is: RenderFlex#86450 OVERFLOWING:
needs compositing
creator: Column ← DecoratedBox ← ConstrainedBox ← Container ←
NotificationListener ← DefaultTextStyle ←
AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#39284 ink renderer] ←
NotificationListener ← PhysicalModel ← AnimatedPhysicalModel ←
Material-[GlobalKey#6e766 BottomSheet child] ← ⋯
parentData: (can use size)
constraints: BoxConstraints(w=360.0, h=185.0)
size: Size(360.0, 185.0)
direction: vertical
mainAxisAlignment: start
mainAxisSize: max
crossAxisAlignment: center
verticalDirection: down
the code is:
floatingActionButton: InkWell(
onTap: () {
// Sizer
// Navigator.of(context).
// Navigator.of(context)
// .push(MaterialPageRoute(builder: (context) => const AddNote()));
// scaffoldKey.currentState!.showBottomSheet((context) => null)
_scaffoldKey.currentState!.showBottomSheet(
(context) => Container(
height: 70.h,
width: double.infinity,
// Sizer
decoration: const BoxDecoration(
// shape: BoxShape.rectangle,
color: Color(pagesBackgroundColor),
boxShadow: [BoxShadow(color: Color(pagesBackgroundColor))],
borderRadius: BorderRadius.only(
topRight: Radius.circular(15),
topLeft: Radius.circular(15),
),
),
// DraggableScrollableSheet(
// builder: (context,scrollableController) {
// return
child: Column(
children: [
Container(
width: 15.w,
// clipBehavior: Clip.antiAliasWithSaveLayer,
height: 1.5.w,
margin: EdgeInsets.only(top: 2.h),
decoration: const BoxDecoration(
// shape: BoxShape.rectangle,
borderRadius:
BorderRadius.all(Radius.circular(2.0)),
color: Color(greyColor),
// boxShadow:[ BoxShadow(color: )],
),
// child: const Divider(
// thickness: 3,
// ),
),
Padding(
padding: EdgeInsets.only(left: 2.w),
child: Align(
alignment: Alignment.bottomLeft,
child: Text(
"Add new note",
style: Theme.of(context).textTheme.headline1,
// strutStyle: ,
),
),
),
],
),
),
//TODO make note text
//max line == 4
//using package AutoSizeText
SingleChildScrollView(
child: Column(
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 1.h),
child: AutoSizeTextField(
textAlign: TextAlign.justify,
cursorRadius: Radius.circular(2.w),
// scrollPadding: EdgeInsets.all(0),
cursorColor: const Color(accentColor),
controller: _textEditingController,
minLines: 1,
maxLength: 150,
maxLines: 4,
// smartDashesType: ,
// wrapWords: true,
),
),
ListTile(
title:
Text(AppLocalizations.of(context)!.homeTodayTap),
leading: Radio(
value: 1,
groupValue: 1,
onChanged: (value) {
// setState(() {
// _site = value;
// });
},
),
),
ListTile(
title: Text(
AppLocalizations.of(context)!.homeTomorowTap),
leading: Radio(
value: 2,
groupValue: 1,
onChanged: (value) {
// setState(() {
// _site = value;
// });
},
),
),
ListTile(
title: Text(
AppLocalizations.of(context)!.homeSomeDayTap),
leading: Radio(
value: 2,
groupValue: 1,
onChanged: (value) {
// setState(() {
// _site = value;
// });
},
),
),
],
),
),
// ],
// );
// }
]),
),
);
},
// for icon shape
child: Container(
clipBehavior: Clip.antiAliasWithSaveLayer,
height: 11.h,
width: 10.h,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.all(Radius.circular(1.w)),
color: const Color(accentColor),
),
// add note icone
child: Icon(
Icons.add,
color: Colors.white,
size: 9.h,
),
),
),
Put SingleChildScrollView under Expanded widget
return Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
children: [
TextFormField(...),
],
),
),
),
],
);

A RenderFlex overflowed by 1.9 pixels on the bottom

I am getting a A RenderFlex overflowed by 1.9 pixels on the bottom error in my flutter app.
I wrapped all the ROW's in Expanded and I wrapped the main Column in a SingleChildScrollView but still have the issue. As you can see from the screenshots the view on the bottom scrolls up. The item on the top squishes down as it goes off screen. I am not even sure which Row is causing the issue?
UPDATE:
Seeing this now.
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.
The ParentDataWidget Expanded(flex: 2) wants to apply ParentData of type FlexParentData to a RenderObject, which has been set up to accept ParentData of incompatible type ParentData.
Usually, this means that the Expanded widget has the wrong ancestor RenderObjectWidget. Typically, Expanded widgets are placed directly inside Flex widgets.
The offending Expanded is currently placed inside a Semantics widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
Column ← Expanded ← Semantics ← Align ← ConstrainedBox ← Container ← LayoutBuilder ← DefaultTextStyle ← Align ← Transform ← ⋯
.enter image description here
CODE:
import 'package:animation_wrappers/animation_wrappers.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:qvid/BottomNavigation/Explore/explore_page.dart';
import 'package:qvid/Components/profile_page_button.dart';
import 'package:qvid/Components/row_item.dart';
import 'package:qvid/Components/sliver_app_delegate.dart';
import 'package:qvid/Components/tab_grid.dart';
import 'package:qvid/Locale/locale.dart';
import 'package:qvid/Routes/routes.dart';
import 'package:qvid/BottomNavigation/MyProfile/followers.dart';
import 'package:qvid/Theme/colors.dart';
import 'package:qvid/BottomNavigation/MyProfile/following.dart';
class UserProfilePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return UserProfileBody();
}
}
class UserProfileBody extends StatefulWidget {
#override
_UserProfileBodyState createState() => _UserProfileBodyState();
}
class _UserProfileBodyState extends State<UserProfileBody> {
bool isFollowed = false;
var followText;
final key = UniqueKey();
#override
Widget build(BuildContext context) {
var locale = AppLocalizations.of(context);
return Scaffold(
backgroundColor: darkColor,
body: DefaultTabController(
length: 2,
child: SafeArea(
child: NestedScrollView(
headerSliverBuilder:
(BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
expandedHeight: 400.0,
floating: false,
actions: <Widget>[
PopupMenuButton(
color: backgroundColor,
icon: Icon(
Icons.more_vert,
color: secondaryColor,
),
shape: OutlineInputBorder(
borderRadius: BorderRadius.circular(12.0),
borderSide: BorderSide.none),
itemBuilder: (BuildContext context) {
return [
PopupMenuItem(
child: Text(locale!.report!),
value: locale.report,
textStyle: TextStyle(color: secondaryColor),
),
PopupMenuItem(
child: Text(locale.block!),
value: locale.block,
textStyle: TextStyle(color: secondaryColor),
),
];
},
)
],
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
title: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Column(
children: <Widget>[
Spacer(flex: 10),
FadedScaleAnimation(
child: CircleAvatar(
radius: 28.0,
backgroundImage:
AssetImage('assets/user/user1.png'),
),
),
Spacer(),
Expanded(
flex: 2,
child: Row(
children: [
Spacer(flex: 12),
Text(
'Emili Williamson',
style: TextStyle(fontSize: 16),
),
Spacer(),
Image.asset(
'assets/icons/ic_verified.png',
scale: 4,
),
Spacer(flex: 8),
],
),
),
Text(
'#emilithedancer',
style:
TextStyle(fontSize: 10, color: disabledTextColor),
),
Spacer(),
FadedScaleAnimation(
child: Expanded(
flex: 2,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ImageIcon(
AssetImage(
"assets/icons/ic_fb.png",
),
color: secondaryColor,
size: 10,
),
SizedBox(
width: 15,
),
ImageIcon(
AssetImage("assets/icons/ic_twt.png"),
color: secondaryColor,
size: 10,
),
SizedBox(
width: 15,
),
ImageIcon(
AssetImage("assets/icons/ic_insta.png"),
color: secondaryColor,
size: 10,
),
],
),
),
),
Spacer(),
Text(
locale!.comment7!,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 10, fontWeight: FontWeight.w500),
),
Spacer(),
Expanded(
flex: 2,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ProfilePageButton(
locale.message,
() => Navigator.pushNamed(
context, PageRoutes.chatPage)),
SizedBox(width: 16),
isFollowed
? ProfilePageButton(locale.following, () {
setState(() {
isFollowed = false;
});
})
: ProfilePageButton(
locale.follow,
() {
setState(() {
isFollowed = true;
});
},
color: mainColor,
textColor: secondaryColor,
),
],
),
),
Spacer(),
Expanded(
flex: 2,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
RowItem(
'1.2m',
locale.liked,
Scaffold(
appBar: AppBar(
title: Text('Liked'),
),
body: TabGrid(
food + lol,
),
)),
RowItem('12.8k', locale.followers, FollowersPage()),
RowItem('1.9k', locale.following, FollowingPage()),
],
),
),
],
)),
),
),
SliverPersistentHeader(
delegate: SliverAppBarDelegate(
TabBar(
labelColor: mainColor,
unselectedLabelColor: lightTextColor,
indicatorColor: transparentColor,
tabs: [
Tab(icon: Icon(Icons.dashboard)),
Tab(
icon: ImageIcon(AssetImage(
'assets/icons/ic_like.png',
)),
),
],
),
),
pinned: true,
),
];
},
body: TabBarView(
children: <Widget>[
FadedSlideAnimation(
child: TabGrid(dance),
beginOffset: Offset(0, 0.3),
endOffset: Offset(0, 0),
slideCurve: Curves.linearToEaseOut,
),
FadedSlideAnimation(
child: TabGrid(food + lol),
beginOffset: Offset(0, 0.3),
endOffset: Offset(0, 0),
slideCurve: Curves.linearToEaseOut,
),
],
),
),
),
),
);
}
}
The error is caused in this row. Remove this row and see if you still see the same problem in the Row above it. If you do then i guess it has something to do with the code below it. Is the code below this one also in singlechildscrollview or expanded? if its not then add it. i'm on phone so it's hard for me to clearly see the syntax.
Spacer(),
Expanded(
flex: 2,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
RowItem(
'1.2m',
locale.liked,
Scaffold(
appBar: AppBar(
title: Text('Liked'),
),
body: TabGrid(
food + lol,
),
)),
RowItem('12.8k', locale.followers, FollowersPage()),
RowItem('1.9k', locale.following, FollowingPage()),
],
),
),
],
)),
),
),
As document says, You cannot use the Expanded widget inside the child of FadedScaleAnimation
You should only use the Expanded Widget as the direct child of Row/Column/Flex because these are flex widgets
Try putting FadedScaleAnimation inside Expanded Widget in your Column widget, the Expanded widget should be the direct child of your Column

How do I fix 'RenderFlex overflowed by 283 pixels on the bottom' in flutter?

The error occurs in a screen where I am trying to render a list of contributions. I have tried a number of things (listed below), none of which works.
Wrapping my column widget with Expanded()
Wrapping my Column widget with Flexible()
Wrapping my Listview.builder() with SingleScrollView() then adding physics: NeverScrollableScrollPhysics() in it.enter image description here
I have a contributions screen with contains a Lisview.builder()
This is my contributions screen
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('My Chamas'),
centerTitle: true,
),
floatingActionButton: CustomFloatingActionButton(
buttonLabel: 'Contribute +',
),
resizeToAvoidBottomInset: false,
body: Column(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height * 0.22,
margin: EdgeInsets.only(top: 20),
child: PageView.builder(
itemCount: widget.availableChamas.length, // number of cards
controller: PageController(viewportFraction: 0.8),
onPageChanged: (int index) => setState(() => _index = index),
/*** Begin snapping chama cards */
itemBuilder: (_, i) {
return Transform.scale(
scale: i == _index ? 1 : 0.9,
child: Card(
elevation: 6,
margin: EdgeInsets.only(right: 0),
color: Theme.of(context).primaryColor, // Card backgound color
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(25)),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25),
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
stops: [0.1, 0.9],
colors: [Colors.indigo, Colors.teal],
),
),
child: ChamaCard(
id: widget.availableChamas[i].id,
name: widget.availableChamas[i].name,
totalMembers: widget.availableChamas[i].totalMembers,
totalContributions: widget.availableChamas[i].totalContributions,
),
),
),
);
/*** End snapping chama cards */
},
),
),
SizedBox(height: 15),
Container(
padding: EdgeInsets.only(right: 15, left: 15),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
'All my chamas',
style: TextStyle(fontSize: 15, color: Colors.red[900]),
),
Icon(
Icons.arrow_forward,
size: 17,
color: Colors.red[900],
)
],
),
SizedBox(height: 15),
Row(
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('My', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20)),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text(
'Contributions',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
),
SizedBox(width: 5),
Text(
'to this chama',
style: TextStyle(color: Colors.green[800]),
)
],
),
],
)
],
),
SizedBox(height: 10),
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return ChamaListItem(
id: widget.availableContributions[index].id,
amount: widget.availableContributions[index].amount,
contributionDate: widget.availableContributions[index].contributionDate,
);
},
itemCount: widget.availableContributions.length,
),
],
),
)
],
),
);
}
This is my ChamaListItem widget which simply holds a single contribution card. This is what I am iterating to build a scrollable list in my Listview.builder()
Widget build(BuildContext context) {
return Card(
elevation: 4,
shadowColor: Color.fromRGBO(255, 255, 255, 0.5),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Date',
style: TextStyle(fontWeight: FontWeight.bold),
),
SizedBox(height: 5),
Text(
'$contributionDate',
style: TextStyle(color: Colors.red[900]),
)
],
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text('Kes'),
SizedBox(width: 1),
Text(
'$amount',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30),
),
],
)
],
),
),
);
}
This is the error thrown in the console
Performing hot reload...
Syncing files to device sdk gphone x86 arm...
Reloaded 5 of 566 libraries in 1,183ms.
======== Exception caught by rendering library =====================================================
The following assertion was thrown during layout:
A RenderFlex overflowed by 283 pixels on the bottom.
The relevant error-causing widget was:
Column file:///Users/Steve/StudioProjects/m_chama/lib/screens/myChamas.dart:35:13
The overflowing RenderFlex has an orientation of Axis.vertical.
The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the RenderFlex to fit within the available space instead of being sized to their natural size.
This is considered an error condition because it indicates that there is content that cannot be seen. If the content is legitimately bigger than the available space, consider clipping it with a ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex, like a ListView.
The specific RenderFlex in question is: RenderFlex#3a382 relayoutBoundary=up1 OVERFLOWING
... needs compositing
... parentData: offset=Offset(0.0, 105.5); id=_ScaffoldSlot.body (can use size)
... constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=697.5)
... size: Size(392.7, 697.5)
... direction: vertical
... mainAxisAlignment: start
... mainAxisSize: max
... crossAxisAlignment: center
... verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
====================================================================================================
Wrap Column widget with SingleChiledScrollView

Flutter Column inside SingleChildScrollView doesn't scroll

When I try to use Card inside SingleScrollChildView, I get this error:
The following assertion was thrown during layout:
A RenderFlex overflowed by 178 pixels on the bottom.
The relevant error-causing widget was:
Column file:///C:/Users/emirs/AndroidStudioProjects/view_met/lib/home.dart:197:16
The overflowing RenderFlex has an orientation of Axis.vertical.
The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the RenderFlex to fit within the available space instead of being sized to their natural size.
This is considered an error condition because it indicates that there is content that cannot be seen. If the content is legitimately bigger than the available space, consider clipping it with a ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex, like a ListView.
The specific RenderFlex in question is: RenderFlex#d861f relayoutBoundary=up2 OVERFLOWING
... needs compositing
... parentData: offset=Offset(0.0, 0.0) (can use size)
... constraints: BoxConstraints(0.0<=w<=411.4, 0.0<=h<=820.6)
... size: Size(411.4, 820.6)
... direction: vertical
... mainAxisAlignment: start
... mainAxisSize: max
... crossAxisAlignment: center
... verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
This is my code:
Padding(
padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
child: Column(
children: <Widget>[
Text("Random Items You Could Like", style: GoogleFonts.merriweather(fontSize: 18, color: Colors.black)),
SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
children: <Widget>[
builder(randint1.toString()),
builder(randint2.toString()),
builder(randint3.toString()),
builder(randint4.toString()),
builder(randint5.toString()),
],
)
),
],
),
)
This is the builder() function:
builder(String id) {
return FutureBuilder(
future: fetchData(id),
builder: (BuildContext context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Padding(
padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
child: CircularProgressIndicator(),
);
}
var data = jsonDecode(snapshot.data.toString());
var leading;
var artist;
if (data["primaryImageSmall"] == "") {
leading = Icon(Icons.dangerous);
}
else {
leading = Image.network(data["primaryImageSmall"]);
}
if (data["artistDisplayName"]== "") {
artist = "Unknown";
}
else {
artist = data["artistDisplayName"];
}
return Card(
clipBehavior: Clip.antiAlias,
child: Column(
children: [
ListTile(
leading: leading,
title: Text(data["title"]),
subtitle: Text(
"by $artist",
style: TextStyle(color: Colors.black.withOpacity(0.6)),
),
),
ButtonBar(
alignment: MainAxisAlignment.start,
children: [
TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => DetailsPage()),
);
},
child: Text("Details", style: TextStyle(color: Color(0xFF6200EE))),
),
TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => DetailsPage()),
);
},
child: Text("Add to Favorites", style: TextStyle(color: Color(0xFF6200EE))),
),
],
),
],
),
);
},
);
}
This is the result:
I looked at other questions too but none of them actually helped and they didn't have the answer I was looking for. I really don't know what do to at this moment. I would appreciate any type of help. I can give more information if required.
Wrap the SingleChildScrollView with Expanded.
Column(
children: [
// ...
Expanded(
child: SingleChildScrollView(),
),
],
),
I think that you are using the SingleChildScrollView wrongly, remove the SingleChildScrollView and scrollDirection; use it to wrap this part:
Column(
children: <Widget>[
builder(randint1.toString()),
builder(randint2.toString()),
builder(randint3.toString()),
builder(randint4.toString()),
builder(randint5.toString()),
],
and it would look like this:
SingleChildScrollView(
scrollDirection: Axis.vertical,
Column(
children: <Widget>[
builder(randint1.toString()),
builder(randint2.toString()),
builder(randint3.toString()),
builder(randint4.toString()),
builder(randint5.toString()),
],
),
Try Out below Code
Padding(
padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
child: Stack(
children: [
Align(
alignment:Alignment.topCenter,
child: Text("Random Items You Could Like", style: GoogleFonts.merriweather(fontSize: 18, color: Colors.black))),
SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
children: <Widget>[
Column(
children: <Widget>[
builder(randint1.toString()),
builder(randint2.toString()),
builder(randint3.toString()),
builder(randint4.toString()),
builder(randint5.toString()),
],
),
],
),
),
],
),
)