How to use GestureDetector on Stack's children elements - flutter

I'm designing a profile image widget and I need to perform 2 different tasks.
Edit icon will change the profile image and Clicking on the image will enlarge the image but I got these errors instead :
I/flutter (21524): The following assertion was thrown building RawGestureDetector(state:
I/flutter (21524): RawGestureDetectorState#6b90e(gestures: [tap])):
I/flutter (21524): Incorrect use of ParentDataWidget.
I/flutter (21524): Positioned widgets must be placed directly inside Stack widgets.
I/flutter (21524): Positioned(no depth, top: 0.0, right: 2.0, dirty) has a Stack ancestor, but there are other widgets
I/flutter (21524): between them:
I/flutter (21524): - Listener(listeners: [down], behavior: deferToChild)
I/flutter (21524): - _GestureSemantics
I/flutter (21524): These widgets cannot come between a Positioned and its Stack.
I/flutter (21524): The ownership chain for the parent of the offending Positioned was:
I/flutter (21524): Listener ← _GestureSemantics ← RawGestureDetector ← GestureDetector ← Stack ← Padding ← Column ←
I/flutter (21524): Center ← DecoratedBox ← Container ← ⋯
Here's my code :
Stack(children: <Widget>[
GestureDetector(
onTap : openImage
child: Container(
width: 120.0,
height: 120.0,
decoration: new BoxDecoration(
color: const Color(0xff7c94b6),
image: DecorationImage(
image: new NetworkImage(user.dp ),
fit: BoxFit.cover,
),
borderRadius:
new BorderRadius.all(new Radius.circular(100.0)),
border: new Border.all(
color: Colors.white,
width: 2.0,
),
),
),
GestureDetector(
onTap: uploadImage,
child: Positioned(
child: CircleAvatar(child: Icon(Icons.edit)),
right: 2.0, top: 0.0,),
)
],
),
How can I fix this error?

This is the key detail on the logs displayed:
"Positioned widgets must be placed directly inside Stack widgets."
The reason of this issue is that Positioned widget is wrapped inside GestureDetector. To solve this error, add Positioned in the Stack, then wrap GestureDetector with it.
Stack(
children: <Widget>[
GestureDetector(
onTap: () {
debugPrint('Clicked open image');
},
child: Container(
width: 120.0,
height: 120.0,
...
),
),
Positioned(
child: GestureDetector(
onTap: () {
debugPrint('Clicked edit image');
},
child: CircleAvatar(child: Icon(Icons.edit)),
),
right: 2.0,
top: 0.0,
),
],
),

Related

TabBarView expanded inside a column error

I am getting this error from the TabBarView.
When I use a container with a specific height there are no errors.
but I don't want to set a specific height
I want it to take the rest of the column. So I tried using expanded and flexible but I am getting this error.
i really need to use TabBarView I can't use any other options.
Can any body help plz
Exception has occurred.
FlutterError (RenderFlex children have non-zero flex but incoming height constraints are unbounded.
When a column is in a parent that does not provide a finite height constraint, for example if it is in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining space in the vertical direction.
These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child cannot simultaneously expand to fit its parent.
Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible children (using Flexible rather than Expanded). This will allow the flexible children to size themselves to less than the infinite remaining space they would otherwise be forced to take, and then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum constraints provided by the parent.
If this message did not help you determine the problem, consider using debugDumpRenderTree():
https://flutter.dev/debugging/#rendering-layer
http://api.flutter.dev/flutter/rendering/debugDumpRenderTree.html
The affected RenderFlex is:
RenderFlex#c8da4 relayoutBoundary=up14 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE(creator: Column ← _SingleChildViewport ← IgnorePointer-[GlobalKey#a14ea] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#45e38] ← Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#ecd8b] ← NotificationListener<ScrollMetricsNotification> ← RepaintBoundary ← ⋯, parentData: <none> (can use size), constraints: BoxConstraints(0.0<=w<=363.4, 0.0<=h<=Infinity), size: MISSING, direction: vertical, mainAxisAlignment: start, mainAxisSize: min, crossAxisAlignment: center, verticalDirection: down)
The creator information is set to:
Column ← _SingleChildViewport ← IgnorePointer-[GlobalKey#a14ea] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#45e38] ← Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#ecd8b] ← NotificationListener<ScrollMetricsNotification> ← RepaintBoundary ← ⋯
The nearest ancestor providing an unbounded width constraint is: _RenderSingleChildViewport#b15e8 relayoutBoundary=up13 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
needs compositing
creator: _SingleChildViewport ← IgnorePointer-[GlobalKey#a14ea] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#45e38] ← Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#ecd8b] ← NotificationListener<ScrollMetricsNotification> ← RepaintBoundary ← CustomPaint ← ⋯
parentData: <none> (can use size)
constraints: BoxConstraints(0.0<=w<=363.4, h=636.6)
size: MISSING
offset: Offset(0.0, -0.0)
See also: https://flutter.dev/layout/
If none of the above helps enough to fix this problem, please don't hesitate to file a bug:
https://github.com/flutter/flutter/issues/new?template=2_bug.md)
import 'package:flutter/material.dart';
import 'package:news_app/helper/enum.dart';
import 'package:news_app/screens/home/home_top_bar.dart';
import 'package:news_app/screens/home/latest_widget.dart';
import 'package:news_app/screens/home/news_tile.dart';
import 'package:news_app/screens/home/see_all_widget.dart';
import 'package:news_app/screens/home/trending_widget.dart';
import 'package:news_app/widgets/text_fields/search_field.dart';
class HomeSection extends StatefulWidget {
const HomeSection({super.key});
#override
State<HomeSection> createState() => _HomeSectionState();
}
class _HomeSectionState extends State<HomeSection>
with TickerProviderStateMixin {
TextEditingController search = TextEditingController();
#override
Widget build(BuildContext context) {
final TabController tabController = TabController(
length: 2,
initialIndex: 1,
vsync: this,
);
return Column(
children: [
const HomeTopBar(),
SearchField(
controller: search,
onChanged: (value) {},
prefixIcon: Icon(
Icons.search,
size: 30,
color: Theme.of(context).secondaryHeaderColor,
),
suffixIcons: Image.asset(
'assets/icons/slider_menu.png',
color: Theme.of(context).secondaryHeaderColor,
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.0101,
),
Expanded(
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SeeAllBar(heading: "Trending"),
TrendingWidget(
newsCategory: "Europe",
title: "Russian warship: Moskva sinks in Black Sea",
publishedTime: "4h ago",
image: Image.asset('assets/temp/trending1.png'),
publisher: "BBC",
publisherLogo: Image.asset('assets/temp/bbc.png'),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.0101,
),
const SeeAllBar(heading: "Latest"),
TabBar(
controller: tabController,
isScrollable: true,
tabs: const [
Text("All"),
Text("Politics"),
],
),
Expanded(
child: TabBarView(
controller: tabController,
children: const [
Text("All"),
Text("Politics"),
],
),
),
],
),
),
),
],
);
}
}
If you need scrolling only for TabBarView - wrap main Column with fixed height container. Then you can use Expanded inside without SingleChildScrollView.
return Container(
color: Colors.redAccent,
height: MediaQuery.of(context).size.height, //<<< your device height
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: _topHeight,
width: double.infinity,
color: Colors.orange,
child: Center(child: Text('TopBar')),
),
Container(
height: _searchHeight,
width: double.infinity,
color: Colors.yellowAccent,
child: Center(child: Text('Search Field')),
),
SizedBox(
height: _sizeBoxHeight,
),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text("Trending Bar"),
Container(
height: 210,
width: double.infinity,
color: Colors.blueAccent,
child: Center(child: Text('Trending widget')),
),
SizedBox(
height: _sizeBoxHeight,
),
const Text("Latest"),
TabBar(
controller: tabController,
isScrollable: true,
tabs: const [
Text("All"),
Text("Politics"),
],
),
Expanded(
child: TabBarView(
controller: tabController,
children: [
ListView.builder(itemBuilder: (context, index) {
return Text ('All $index');
}, itemCount: 100,),
ListView.builder(itemBuilder: (context, index) {
return Text ('Politics $index');
}, itemCount: 100,),
],
),
),
],
),
),
],
),
);

Another exception was thrown: A RenderFlex overflowed by 4.1 pixels on the bottom

I am need to create to Material Widget per row, but when i create it i wanted to add padding when i do so for the column the yellow error appears with this error:
Another exception was thrown: A RenderFlex overflowed by 4.1 pixels on
the bottom.
Another exception was thrown: A RenderFlex overflowed by 4.1 pixels on
the bottom.
Another exception was thrown: A RenderFlex overflowed by 4.1 pixels on
the bottom.
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY
╞═════════════════════════════════════════════════════════ The
following assertion was thrown during layout: A RenderFlex overflowed
by 0.200 pixels on the right. The relevant error-causing widget was:
Row
Row:file:///E:/work/nabaa_mobile-main/lib/ui/screens/home/widgets/bottom_home_page/home.dart:134:25
To inspect this widget in Flutter DevTools, visit:
http://127.0.0.1:9101/#/inspector?uri=http%3A%2F%2F127.0.0.1%3A56940%2FUjrL2FntShg%3D%2F&inspectorRef=inspector-1305
The overflowing RenderFlex has an orientation of Axis.horizontal. 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#164c6
relayoutBoundary=up1 OVERFLOWING: creator: Row ← Column ← Semantics ←
DefaultTextStyle ← AnimatedDefaultTextStyle ←
_InkFeatures-[GlobalKey#020b0 ink renderer] ← NotificationListener ← CustomPaint ←
_ShapeBorderPaint ← PhysicalShape ← _MaterialInterior ← Material ← ⋯ parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use
size) constraints: BoxConstraints(0.0<=w<=135.2, 0.0<=h<=Infinity)
size: Size(135.2, 40.0) direction: horizontal mainAxisAlignment:
start mainAxisSize: max crossAxisAlignment: center textDirection: ltr
verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
════════════════════════════════════════════════════════════════════════════════════════════════════
Another exception was thrown: A RenderFlex overflowed by 12 pixels on
the bottom. Another exception was thrown: A RenderFlex overflowed by
0.200 pixels on the right. Another exception was thrown: A RenderFlex overflowed by 12 pixels on the bottom. Another exception
was thrown: A RenderFlex overflowed by 0.200 pixels on the right.
Another exception was thrown: A RenderFlex overflowed by 12 pixels
on the bottom. Another exception was thrown: A RenderFlex
overflowed by
0.200 pixels on the right. Another exception was thrown: A RenderFlex overflowed by 12 pixels on the bottom. Performing hot
reload... Reloaded 1 of 1166 libraries in 4,534ms. Performing hot
reload... Reloaded 1 of 1166 libraries in 3,199ms. ══╡ EXCEPTION
CAUGHT BY RENDERING LIBRARY
╞═════════════════════════════════════════════════════════ The
following assertion was thrown during layout: A RenderFlex overflowed
by 0.200 pixels on the right. The relevant error-causing widget was:
Row
Row:file:///E:/work/nabaa_mobile-main/lib/ui/screens/home/widgets/bottom_home_page/home.dart:140:27
To inspect this widget in Flutter DevTools, visit:
http://127.0.0.1:9101/#/inspector?uri=http%3A%2F%2F127.0.0.1%3A56940%2FUjrL2FntShg%3D%2F&inspectorRef=inspector-2705
The overflowing RenderFlex has an orientation of Axis.horizontal. 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#4f67e
relayoutBoundary=up1 OVERFLOWING: creator: Row ← Column ← Padding ←
DefaultTextStyle ← AnimatedDefaultTextStyle ←
_InkFeatures-[GlobalKey#c9285 ink renderer] ← NotificationListener ← CustomPaint ←
_ShapeBorderPaint ← PhysicalShape ← _MaterialInterior ← Material ← ⋯ parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use
size) constraints: BoxConstraints(0.0<=w<=135.2, 0.0<=h<=Infinity)
size: Size(135.2, 40.0) direction: horizontal mainAxisAlignment:
start mainAxisSize: max crossAxisAlignment: center textDirection: ltr
verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
════════════════════════════════════════════════════════════════════════════════════════════════════
Another exception was thrown: A RenderFlex overflowed by 12 pixels on
the bottom.
========================================================================
the code is
GridView.count(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
crossAxisCount: 2,
mainAxisSpacing: 4,
scrollDirection: Axis.vertical,
crossAxisSpacing: 4.w,
// padding: EdgeInsets.all(9),
children: List.generate(4, (index) {
return Material(
// padding: const EdgeInsets.all(8.0),
shape: RoundedRectangleBorder(
// side: ,
borderRadius: BorderRadius.circular(18.0),
),
type: MaterialType.button,
color: whiteColor,
elevation: 5,
// clipBehavior: Clip.antiAliasWithSaveLayer,
shadowColor: blackColor.withOpacity(0.5),
child: Column(
children: [
Row(
children: [
CircleAvatar(
foregroundColor: blackColor,
child: ClipOval(
child:
Image.asset('assets/images/meta-logo.png'),
),
),
Padding(
padding: EdgeInsetsDirectional.only(start: 4.w),
child: Text(
"company_name".tr,
// textAlign: TextAlign.end,
style: Get.textTheme.headline3!
.copyWith(color: faddenGreyColor),
),
),
],
),
Align(
alignment: AlignmentDirectional.centerStart,
heightFactor: 0.3.h,
child: Text(
"opportunity_title".tr,
style: Get.textTheme.headline4,
),
),
Row(
children: [
Icon(
Icons.calendar_today_outlined,
color: faddenGreyColor,
size: 13.sp,
),
Padding(
padding: EdgeInsetsDirectional.only(start: 2.w),
child: Text(
"date".tr,
style: Get.textTheme.headline3!.copyWith(
color: faddenGreyColor,
),
),
),
],
),
Row(
children: [
Icon(
Icons.location_on_outlined,
color: faddenGreyColor,
size: 15.sp,
),
Padding(
padding: EdgeInsetsDirectional.only(start: 2.w),
child: Text(
"location".tr,
style: Get.textTheme.headline3!.copyWith(
color: faddenGreyColor,
),
),
),
],
),
SizedBox(height: 2.h),
],
),
);
}),
),
-> Use Can Use For This Code SingleChildScrollView
import 'package:flutter/material.dart';
class Data extends StatefulWidget {
const Data({Key? key}) : super(key: key);
#override
_DataState createState() => _DataState();
}
class _DataState extends State<Data> {
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: GridView.count(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
crossAxisCount: 2,
mainAxisSpacing: 4,
scrollDirection: Axis.vertical,
crossAxisSpacing: 4,
// padding: EdgeInsets.all(9),
children: List.generate(4, (index) {
return Material(
// padding: const EdgeInsets.all(8.0),
shape: RoundedRectangleBorder(
// side: ,
borderRadius: BorderRadius.circular(18.0),
),
type: MaterialType.button,
color: Colors.white,
elevation: 5,
// clipBehavior: Clip.antiAliasWithSaveLayer,
shadowColor: Colors.black.withOpacity(0.5),
child: Column(
children: [
Row(
children: [
CircleAvatar(
foregroundColor: Colors.black,
child: ClipOval(
child: Image.asset('assets/images/meta-logo.png'),
),
),
Padding(
padding: EdgeInsetsDirectional.only(start: 4),
child: Text(
"company_name",
// textAlign: TextAlign.end,
style: TextStyle(),
),
),
],
),
Align(
alignment: AlignmentDirectional.centerStart,
child: Text(
"opportunity_title",
style: TextStyle(),
),
),
Row(
children: [
Icon(
Icons.calendar_today_outlined,
color: Colors.red,
size: 13,
),
Padding(
padding: EdgeInsetsDirectional.only(start: 2),
child: Text(
"location",
style: TextStyle(),
),
),
],
),
Row(
children: [
Icon(
Icons.location_on_outlined,
color: Colors.red,
size: 15,
),
Padding(
padding: EdgeInsetsDirectional.only(start: 2),
child: Text(
"location",
style: TextStyle(),
),
),
],
),
SizedBox(height: 2),
],
),
);
}),
),
);
}
}
Expanded all your widget in Column
GridView.count(
shrinkWrap: true,
physics: const ScrollPhysics(),
crossAxisCount: 2,
mainAxisSpacing: 4,
scrollDirection: Axis.vertical,
crossAxisSpacing: 4,
// padding: EdgeInsets.all(9),
children: List.generate(4, (index) {
return Material(
// padding: const EdgeInsets.all(8.0),
shape: RoundedRectangleBorder(
// side: ,
borderRadius: BorderRadius.circular(18.0),
),
type: MaterialType.button,
elevation: 5,
// clipBehavior: Clip.antiAliasWithSaveLayer,
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Expanded(
child: Row(
children: [
Expanded(
child: CircleAvatar(
child: ClipOval(
child: Image.asset('images/profile.png'),
),
),
),
Expanded(
child: Padding(
padding: EdgeInsetsDirectional.only(start: 4),
child: Text(
"company_name",
// textAlign: TextAlign.end,
),
),
),
],
),
),
Expanded(
child: Align(
alignment: AlignmentDirectional.centerStart,
heightFactor: 0.3,
child: Text(
"opportunity_title",
),
),
),
Expanded(
child: Row(
children: [
Expanded(
child: Icon(
Icons.calendar_today_outlined,
),
),
Expanded(
child: Padding(
padding: EdgeInsetsDirectional.only(start: 2),
child: Text(
"date",
),
),
),
],
),
),
Expanded(
child: Row(
children: [
Expanded(
child: Icon(
Icons.location_on_outlined,
),
),
Expanded(
child: Padding(
padding: EdgeInsetsDirectional.only(start: 2),
child: Text(
"location",
),
),
),
],
),
),
],
),
),
);
}),
),
output:

How to make the Wrap widget child inside SingleChildScrollView to expand to full height in Flutter?

I'm trying to make a UI where there are some text fields inside a container and there are some icon buttons which are always going to stay at the bottom.
Here is the code minimal code
Center(
child: Container(
// width: 1006,
constraints: BoxConstraints(
maxWidth: 1006,
maxHeight: sizingInformation.screenSize.height,
),
margin: EdgeInsets.only(
left: isMobile ? 0 : 34,
),
child: Flex(
direction: Axis.vertical,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
Flex(
// rest of the widgets
),
Expanded(
child: Container(
padding: EdgeInsets.all(isMobile ? 15 : 34),
margin: EdgeInsets.only(
top: isMobile ? 15 : 27,
),
constraints: BoxConstraints(
maxWidth: 1006,
),
height: 750,
decoration: BoxDecoration(
color: CARD_DARK_PURPLE,
borderRadius: BorderRadius.circular(8),
),
child: SingleChildScrollView(
physics: AlwaysScrollableScrollPhysics(),
child: Wrap(
direction: Axis.horizontal,
children: <Widget>[
Wrap(
direction: Axis.horizontal,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Pošiljalac",
style: TextStyle(
color: WHITE,
fontSize: isMobileTablet ? 22 : 24,
fontWeight: BOLD,
),
),
SizedBox(
height: 20,
),
_phoneInfo(widget.order.senderPhoneNumber, isMobile),
_emailInfo(widget.order.senderEmail, isMobile),
_fullNameInfo(widget.order.senderFirstName,
widget.order.senderLastName, isMobile, isMobileTablet),
_addressInfo(widget.order.senderStreetNumber, isMobile),
_zipCodeInfo(widget.order.senderZipCode, isMobile),
_cityInfo(widget.order.senderCity, isMobile),
SizedBox(
height: isDesktopLaptop ? 14 : 0,
),
_payeeInfo(isMobile, isMobileTablet),
],
),
SizedBox(
width: 34,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: isDesktopLaptop ? 482 : 10,
),
_weightInfo(isMobile, isMobileTablet),
_noteSmall(isMobile, isMobileTablet),
],
),
],
),
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
SizedBox(height: 10),
Flex(
direction: Axis.horizontal,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
SizedBox(width: 20),
Material(
color: DIVIDER,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
child: Center(
child: Ink(
decoration: const ShapeDecoration(
color: DIVIDER,
shape: CircleBorder(),
),
child: IconButton(
splashColor: DARK_PURPLE.withOpacity(0.3),
icon: Image.asset(
'assets/images/inter-note-icon.png',
width: 20,
height: 24,
),
onPressed: () {
if (widget.order.operatorNote == "/") {
_dialogs.internNoteDialog(
context,
widget.order.id,
"order",
widget.order.operatorNote);
} else {
_dialogs.changeInternNoteDialog(
context,
widget.order.id,
"order",
widget.order.operatorNote);
}
},
),
),
),
),
SizedBox(width: 20),
Material(
color: DIVIDER,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
child: Center(
child: Ink(
decoration: const ShapeDecoration(
color: DIVIDER,
shape: CircleBorder(),
),
child: IconButton(
splashColor: DARK_PURPLE.withOpacity(0.3),
icon: Image.asset(
'assets/images/trash-icon.png',
width: 28,
height: 28,
),
onPressed: () {
_dialogs.deleteOrderDialog(
context, widget.order.id, isMobile);
},
),
),
),
),
],
),
],
),
),
],
),
),
),
),
),
),
)
This is the UI that I'm trying to achieve(the box highlighted on the right side specifically)
There is SingleChildScrollView parent which has Wrap as its child. SingleChildScrollView is taking the full height available but Wrap isn't spanning to that full height. I want to make the Wrap span full height so that the icons can stay at the bottom always.
So, I placed it inside Expanded as I thought it would make it expand to the full available height. But I got this error.
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.
The ParentDataWidget Expanded(flex: 1) 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 _SingleChildViewport widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
Wrap ← Expanded ← _SingleChildViewport ← IgnorePointer-[GlobalKey#01401] ← Semantics ← _PointerListener ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#7427b] ← _PointerListener ← ⋯
When the exception was thrown, this was the stack
dart:sdk_internal 4461:11 throw_
packages/flutter/src/widgets/widget_span.dart.lib.js 12339:23 <fn>
packages/flutter/src/widgets/widget_span.dart.lib.js 12355:24 [_updateParentData]
packages/flutter/src/widgets/widget_span.dart.lib.js 12372:61 attachRenderObject
packages/flutter/src/widgets/widget_span.dart.lib.js 12184:12 mount
...
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════
Incorrect use of ParentDataWidget.
════════════════════════════════════════════════════════════════════════════════
So, Expanded is not the answer to this. But I don't know what else is. I'm new to Flutter and having a hard time understanding the Flutter layout system. Any help would be great. Thanks for your time.
What if you make your Wrap widget the child of a container the size of the screen ?
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Wrap(
children: [],
))),
);
}
}

flutter not compiling with different colored border sides

I'm getting started with flutter and want to create a widget which has different colored borders on each side depending on a condition.
decoration: new BoxDecoration(
border: new Border(
top: new BorderSide(width: 1.0, color: Colors.red),
left: new BorderSide(width: 1.0, color: Colors.red),
right: new BorderSide(width: 1.0, color: Colors.red),
bottom: new BorderSide(width: 1.0, color: Colors.white)
),
borderRadius: new BorderRadius.only(
topLeft: new Radius.circular(15.0)
),
),
whenever I try to use more than one color on the borders in breaks and I'm not sure why but works fine if they all are one single color.
I get the following error on the hot reload :
I/flutter ( 1274): The following RenderObject was being processed when the exception was fired: RenderDecoratedBox#746f5 relayoutBoundary=up5:
I/flutter ( 1274): creator: DecoratedBox ← Container ← Row ← Column ← Container ← Column ← Center ← MediaQuery ←
I/flutter ( 1274): LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout ← AnimatedBuilder ← DefaultTextStyle ← ⋯
I/flutter ( 1274): parentData: offset=Offset(140.2, 0.0); flex=null; fit=null (can use size)
I/flutter ( 1274): constraints: BoxConstraints(unconstrained)
I/flutter ( 1274): size: Size(57.0, 38.0)
I/flutter ( 1274): decoration: BoxDecoration:
I/flutter ( 1274): border: Border(top: BorderSide(MaterialColor(primary value: Color(0xfff44336)), 1.0,
I/flutter ( 1274): BorderStyle.solid), right: BorderSide(MaterialColor(primary value: Color(0xff4caf50)), 1.0,
I/flutter ( 1274): BorderStyle.solid), bottom: BorderSide(MaterialColor(primary value: Color(0xff4caf50)), 1.0,
I/flutter ( 1274): BorderStyle.solid), left: BorderSide(MaterialColor(primary value: Color(0xfff44336)), 1.0,
I/flutter ( 1274): BorderStyle.solid))
I/flutter ( 1274): borderRadius: BorderRadius.only(topLeft: Radius.circular(15.0))
I/flutter ( 1274): configuration: ImageConfiguration(bundle: PlatformAssetBundle#bb4b7(), devicePixelRatio: 2.6,
I/flutter ( 1274): locale: en_US, textDirection: TextDirection.ltr, platform: android)
I/flutter ( 1274): This RenderObject had the following descendants (showing up to depth 5):
I/flutter ( 1274): child: RenderPadding#f05f1 relayoutBoundary=up6 NEEDS-PAINT
I/flutter ( 1274): child: RenderParagraph#4842a relayoutBoundary=up7 NEEDS-PAINT
I/flutter ( 1274): text: TextSpan
thanks for any help in advance
That gives you the following error:
The following assertion was thrown during paint():
I/flutter (19471): A borderRadius can only be given for uniform borders.
So, if you want to have different border colors, better use a Material:
Material(
child: Container(),
shape: Border(
right: BorderSide(
width: 1,
color: Colors.red,
),
left: BorderSide(
width: 1,
color: Colors.green,
),
bottom: BorderSide(
width: 1,
color: Colors.blue,
),
top: BorderSide(
width: 1,
color: Colors.yellow,
),
),
),

A RenderFlex overflowed by 112 pixels on the bottom

I am using AnimatedContainer. it animate size from 0 to some size and it contain some text and all other things. on pressing one button animation is started and it shows flowing errors.
On the button press i just set value of sizeOfLevel. initially value of it is 0.
Code:
AnimatedContainer(
curve: Curves.bounceIn,
duration: Duration(milliseconds: 200),
width: sizeOfLevel,
height: sizeOfLevel,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8.0)),
image: DecorationImage(
image: AssetImage('images/levelunlockScreen.jpg'),
fit: BoxFit.cover),
border: Border.all(
style: BorderStyle.solid, width: 4.0, color: Colors.white)),
child: Column(
children: <Widget>[
Center(
child: new Text(
"Unlock Level",
style: TextStyle(color: Colors.white, fontSize: 30.0),
),
),
],
),
),
Errors:
I/flutter ( 4579): The following message was thrown during layout:
I/flutter ( 4579): A RenderFlex overflowed by 112 pixels on the bottom.
I/flutter ( 4579): The overflowing RenderFlex has an orientation of Axis.vertical.
I/flutter ( 4579): The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and
I/flutter ( 4579): black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
I/flutter ( 4579): Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the
I/flutter ( 4579): RenderFlex to fit within the available space instead of being sized to their natural size.
I/flutter ( 4579): This is considered an error condition because it indicates that there is content that cannot be
I/flutter ( 4579): seen. If the content is legitimately bigger than the available space, consider clipping it with a
I/flutter ( 4579): ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
I/flutter ( 4579): like a ListView.
I/flutter ( 4579): The specific RenderFlex in question is:
I/flutter ( 4579): RenderFlex#4086c OVERFLOWING
I/flutter ( 4579): creator: Column ← Padding ← DecoratedBox ← ConstrainedBox ← Container ← AnimatedContainer ← Center
I/flutter ( 4579): ← Stack ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout ← AnimatedBuilder
I/flutter ( 4579): ← ⋯
I/flutter ( 4579): parentData: offset=Offset(4.0, 4.0) (can use size)
I/flutter ( 4579): constraints: BoxConstraints(w=115.7, h=115.7)
I/flutter ( 4579): size: Size(115.7, 115.7)
I/flutter ( 4579): direction: vertical
I/flutter ( 4579): mainAxisAlignment: start
I/flutter ( 4579): mainAxisSize: max
I/flutter ( 4579): crossAxisAlignment: center
I/flutter ( 4579): verticalDirection: down
" Warping your parent Column into - SingleChildScrollView" works to me, I'm animate the height of the AnimatedContainer.
Older code
return new AnimatedContainer(
curve: Curves.easeInOutCubic,
height: showSearchBar ? 350 : 0,
duration: new Duration(seconds: 3),
child: Container(
margin: EdgeInsets.all(10),
child: Card(
child: Padding(
padding: EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Text('Busque por pacientes'),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 0, vertical: 20),
child: Column(
children: this.children,
),
),
RaisedButton(
color: themeSecondary,
onPressed: () {
print('raised clicked');
},
child: Text('Buscar'),
)
]),
),
),
),
);
And the newer, warping the SingleChildScrollView
return new AnimatedContainer(
curve: Curves.easeInOutCubic,
height: showSearchBar ? 350 : 0,
duration: new Duration(seconds: 3),
child: Container(
margin: EdgeInsets.all(10),
child: Card(
child: Padding(
padding: EdgeInsets.all(20),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Text('Busque por pacientes'),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 0, vertical: 20),
child: Column(
children: this.children,
),
),
RaisedButton(
color: themeSecondary,
onPressed: () {
print('raised clicked');
},
child: Text('Buscar'),
)
]),
),
),
),
),
);