In my flutter screen I am trying to create a Card with title and below it iterate the data related to this title. I am currently getting the following error:
I/flutter ( 3496): Incorrect use of ParentDataWidget.
I/flutter ( 3496): 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.
I/flutter ( 3496): Usually, this means that the Expanded widget has the wrong ancestor RenderObjectWidget. Typically, Expanded widgets are placed directly inside Flex widgets.
I/flutter ( 3496): The offending Expanded is currently placed inside a ConstrainedBox widget.
I/flutter ( 3496): The ownership chain for the RenderObject that received the incompatible parent data was:
I/flutter ( 3496): RichText ← Text ← Expanded ← FutureBuilder<List<AllActiveSessionsModel>> ← ConstrainedBox ← Container ← Expanded ← Row ← Padding ← Semantics ← ⋯
I/flutter ( 3496): #0 RenderObjectElement._updateParentData.<anonymous closure> (package:flutter/src/widgets/framework.dart:6042:11)
I/flutter ( 3496): #1 RenderObjectElement._updateParentData (package:flutter/src/widgets/framework.dart:6059:6)
I/flutter ( 3496): #2 ParentDataElement._applyParentData.applyParentDataToChild (package:flutter/src/widgets/framework.dart:5258:15)
I/flutter ( 3496): #3 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4931:14)
I/flutter ( 3496): #4 ParentDataElement._applyParentData.applyParentDataToChild (package:flutter/src/widgets/framework.dart:5261:15)
I/flutter ( 3496): #5 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4931:14)
I/flutter ( 3496): #6 ParentDataElement._applyParentData (package:flutter/src/widgets/framework.dart:5264:5)
I/flutter ( 3496): #7 ParentDataElement.notifyClients (package:flutter/src/widgets/framework.dart:5308:5)
I/flutter ( 3496): #8 ProxyElement.updated (package:flutter/src/widgets/framework.dart:5238:5)
I/flutter ( 3496): #9 ProxyElement.update (package:flutter/src/widgets/framework.dart:5226:5)
I/flutter ( 3496): #10 Element.updateChild (package
I am not sure how to fix this error here is the UI code:
Builder(builder: (context) {
return SafeArea(
child: Container(
padding: const EdgeInsets.all(10),
// width: double.infinity, // Set the width of the container to be as wide as possible
child: SingleChildScrollView(
child: Column(
children: [
Card(
child: Row(
children: [
Expanded(
flex: 2,
child: Container(
child: FutureBuilder(
future: _allActiveSessions,
builder: (BuildContext context, AsyncSnapshot snapshot) {
if ..............................
return Expanded(
child: lastSession != null ? Text(DateFormat("d/MM").format(lastSession.endDate)) : Center(child: Text("")),
);
} else {
return Text("No Data");
}
} else {
return CircularProgressIndicator();
}
}, ),), ), ],),),
for (var stuff in snapshot.stuff![index].stuff)
Card(
child: Padding(
padding: EdgeInsets.only(bottom: 8.0, right: 8.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
// flex: 2,
child: Container(
height: 50, // set a fixed height for the container
width: 50, // set the width to 200 pixels
child: FutureBuilder(
future: _allActiveSessions,
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasError) {
print("The error is ${snapshot.error}");
return Text("Error/No Data");
}
if .......................................
return Expanded(
child: lastSession != null
? Text(filteredLogs.map((log) => "Some Data").join(", "))
: Text("N/A"),
);
}
} else {
return Center(child: Text("N/A"));
}
} else {
return CircularProgressIndicator();
}
},),), ),], ),),),], ),),),); }),
My question how can I update the UI code so that it can show data using FutureBuilder to avoid the error of Incorrect use of ParentDataWidget. My objective is to have a simplified data of dates or N/A nothing too long showing screen