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'),
)
]),
),
),
),
),
);
Related
Expanded and FittedBox in Row and Column.
══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during a scheduler callback:
'package:flutter/src/widgets/binding.dart': Failed assertion: line 849 pos 12:
'!debugBuildingDirtyElements': is not true.
Either the assertion indicates an error in the framework itself, or we should provide substantially
more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.md
When the exception was thrown, this was the stack:
#2 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:849:12)
#3 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:378:5)
#4 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1175:15)
#5 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1104:9)
#6 SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:881:7)
(elided 6 frames from class _AssertionError, class _RawReceivePortImpl, class _Timer, and dart:async-patch)
════════════════════════════════════════════════════════════════════════════════════════════════════
Performing hot reload...
Reloaded 0 libraries in 31ms (compile: 7 ms, reload: 0 ms, reassemble: 13 ms).
Another exception was thrown: 'package:flutter/src/widgets/binding.dart': Failed assertion: line 849 pos 12: '!debugBuildingDirtyElements': is not true.
Another exception was thrown: 'package:flutter/src/widgets/binding.dart': Failed assertion: line 849 pos 12: '!debugBuildingDirtyElements': is not true.
Widget build(BuildContext context) {
return Scaffold(
body: Container(
alignment: Alignment.center,
color: Color.fromRGBO(0, 0, 0, 1),
child: SafeArea(
child: Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: IntrinsicWidth(
child: Stack(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
FittedBox(
fit: BoxFit.fitWidth,
child: Text(
_localeDate,
style: TextStyle(
color: Colors.white,
),
),
),
SizedBox(
height: 20,
),
FittedBox(
fit: BoxFit.fitWidth,
child: Text(
_time,
style: TextStyle(
color: Colors.white,
),
),
),
],
),
],
),
),
),
),
Expanded(
flex: 2,
child: Image(fit: BoxFit.cover, image: NetworkImage(img)))
],
),
),
),
);
}
When hot start is pressed, a screen appears and the following error is output.
The following RenderObject was being processed when the exception was fired: RenderFittedBox#e50d7 relayoutBoundary=up15 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
creator: FittedBox ← Column ← Stack ← IntrinsicWidth ← Padding ← SizedBox ← Row ← MediaQuery ←
Padding ← SafeArea ← Align ← ColoredBox ← ⋯
parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
constraints: BoxConstraints(w=237.2, 0.0<=h<=Infinity)
size: MISSING
fit: fitWidth
alignment: Alignment.center
textDirection: ltr
This RenderObject had the following descendants (showing up to depth 5):
child: RenderParagraph#39ce4 relayoutBoundary=up16 NEEDS-PAINT
text: TextSpan
════════════════════════════════════════════════════════════════════════════════════════════════════
Another exception was thrown: RenderBox was not laid out: RenderFittedBox#e50d7 relayoutBoundary=up15 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
Another exception was thrown: RenderBox was not laid out: RenderFlex#e77d9 relayoutBoundary=up14 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I would like to do this.
I use FitBox because I need to change the font size for each device.
Characters must be in a single column.
I want to display the maximum number of images.
This is because they are easy to see.
It doesn't make sense for a Row() to contain two Expanded(), since you also have no control over their widths.
It is recommended to fix the width of the text on the left
this is example
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:koreajob/view/common/funciton_of_print.dart';
class MyWidget extends StatefulWidget {
const MyWidget({super.key});
#override
State<MyWidget> createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
#override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
}
Widget _buildLandScreenView(BuildContext context, Orientation orientation) {
return Container(
alignment: Alignment.center,
width: MediaQuery.of(context).size.width,
color: Color.fromRGBO(0, 0, 0, 1),
child: SafeArea(
child: Row(
children: [
SizedBox(
width: MediaQuery.of(context).size.width * .5,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: IntrinsicWidth(
child: Stack(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
FittedBox(
fit: BoxFit.fitWidth,
child: Text(
"""Easy to use, """,
style: TextStyle(
color: Colors.white,
),
),
),
SizedBox(
height: 20,
),
FittedBox(
fit: BoxFit.fitWidth,
child: Text(
"""Just add Just add Just add Just add Just add Just add """,
style: TextStyle(
color: Colors.white,
),
),
),
],
),
],
),
),
),
),
Expanded(
child: Image(
fit: BoxFit.cover,
image: NetworkImage('https://picsum.photos/200')))
],
),
),
);
}
Widget _buildPortaraitScreenView(
BuildContext context, Orientation orientation) {
return _buildLandScreenView(context, orientation);
}
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: true,
body: OrientationBuilder(builder: (context, orientation) {
if (orientation == Orientation.portrait) {
return _buildPortaraitScreenView(context, orientation);
} else if (orientation == Orientation.landscape) {
return _buildLandScreenView(context, orientation);
}
return Container();
}));
}
}
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:
My UI screen is basically rendered using a Column Widget and inside this widget, I am inserting all the other UI components. One of these happens to be a Row ( consisting of 2 text fields). This is the Row Widget :
var phoneNumber = new Row(
children: <Widget>[
new Padding(
padding: const EdgeInsets.all(20.0),
child: countryCodePicker,
),
new Padding(
padding: const EdgeInsets.all(20.0),
child: mobileNumber,
),
],
);
The Main UI Screen being :
return SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
customerName,
emailAddress,
// new Container(
// child: deliveryOptionRow,
// ),
mobileNumber,
countryCodePicker,
templateMessagesDropDown,
templateMessageTextField,
sendGoogleReview,
],
)
);
I see this exception when I add the Row to the Column
The following RenderObject was being processed when the exception was fired:
flutter: _RenderListTile#06b03 relayoutBoundary=up11 NEEDS-LAYOUT NEEDS-PAINT
flutter: creator: _ListTile ← MediaQuery ← Padding ← SafeArea ← Semantics ← Listener ← _GestureSemantics ←
flutter: RawGestureDetector ← GestureDetector ← InkWell ← ListTile ← ListTileTheme ← ⋯
flutter: parentData: offset=Offset(0.0, 0.0) (can use size)
flutter: constraints: BoxConstraints(unconstrained)
flutter: size: MISSING
flutter: This RenderObject had the following descendants (showing up to depth 5):
flutter: _RenderRadio#302a4 relayoutBoundary=up12 NEEDS-PAINT
flutter: RenderParagraph#58a45 NEEDS-LAYOUT NEEDS-PAINT
What would be the best way to add the row inside the main UI screen.
this should solve your problem,
var phoneNumber = new Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(
child: new Padding(
padding: const EdgeInsets.all(20.0),
child: countryCodePicker,
),
),
Expanded(
child: new Padding(
padding: const EdgeInsets.all(20.0),
child: mobileNumber,
),
),
],
);
hope it helps!
If your Row contains a TextField or TextFormField or any other widget which tries to grow to infinity, you need to provide an intrinsic width to it. You can do it in several ways:
Use Expanded:
Row(
children: [
Expanded(
child: TextField(), // <-- Wrapped in Expanded.
),
],
)
Use Flexible:
Row(
children: [
Flexible(
child: TextField(), // <-- Wrapped in Flexible.
),
],
)
Provide a fixed width:
Row(
children: [
SizedBox(
width: 200, // <-- Fixed width.
child: TextField(),
),
],
)
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,
),
],
),
How can i create a TextField on a Card.
In a Function i return a Card. Here i needed to implement a TextField.
This is my Code:
return new Card(
color: Colors.white70,
child: new Container(
padding: EdgeInsets.all(10.0),
child: new Column(
children: <Widget>[
new Row(
children: <Widget>[
new Expanded(child: new Text("Bemerkung", style: style,)),
new TextField(
),
],
),
],
),
),
);
everytime i wanted to debug, this Exception was thrown:
I/flutter (17588): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (17588): The following assertion was thrown during performLayout():
I/flutter (17588): BoxConstraints forces an infinite width.
I/flutter (17588): These invalid constraints were provided to RenderRepaintBoundary's layout() function by the
I/flutter (17588): following function, which probably computed the invalid constraints in question:
I/flutter (17588): _RenderDecoration._layout.layoutLineBox (package:flutter/src/material/input_decorator.dart:747:11)
I/flutter (17588): The offending constraints were:
I/flutter (17588): BoxConstraints(w=Infinity, 0.0<=h<=Infinity)
i dont know why it didn't work.
Just wrap TextField with Expanded widget,
new Card(
color: Colors.white70,
child: new Container(
padding: EdgeInsets.all(10.0),
child: new Column(
children: <Widget>[
new Row(
children: <Widget>[
new Expanded(child: new Text("Bemerkung",)),
new Expanded(
child: new TextField(
),
),
],
),
],
),
),
);