Open RoarGronmo opened 2 months ago
Thank you for including the picture, it really helps me understand the benefit!
Working on this feature in #56
I have merged this new feature and will try and publish a new version soon!
I forgot to add support for setting "shrink" via the controller, so this is going to be a little bit longer out.
This feature should be ready once I can get #65 completed and merged.
I appreciate your patience ❤️
@RoarGronmo A pre-release version (4.0.0-beta.1) is available on pub.dev that includes full support for shrink.
I'm going to give it some more testing before publishing a full release, but it's available if you'd like to try it out, too!
Referencing the picture above, here are the code for that particular widget.
class CustomerPage extends StatefulWidget{
final GlobalKey mPortalScreenKey;
const CustomerPage({
super.key, required this.mPortalScreenKey
});
@override
State<CustomerPage> createState() => _CustomerPageState();
}
class _CustomerPageState extends State<CustomerPage> {
@override
Widget build(BuildContext context) {
// TODO: implement build
return Row(
children: [
Expanded(
child: Column(
children: [
Expanded(
child: ResizableContainer(
direction: Axis.horizontal,
divider: ResizableDivider(
thickness: 5,
length: ResizableSize.ratio(0.75)
),
children: [
ResizableChild(
child: MPortalMap(mPortalScreenKey: widget.mPortalScreenKey,),
size: const ResizableSize.ratio(0.5),
minSize: 200
),
ResizableChild(
child: Center(
child: ResizableContainer(
direction: Axis.vertical,
divider: ResizableDivider(
thickness: 5,
length: ResizableSize.ratio(0.75)
),
children: [
ResizableChild(
child: CustomerInfoCard(),
size: ResizableSize.shrink(),
//size: ResizableSize.ratio(0.5),
minSize: 100
),
ResizableChild(
child: CustomerContactsCard(),
minSize: 100
)
],
),
),
minSize: 500
)
]
),
),
],
),
),
],
);
}
}
I am not sure I have entirely understood the usage...
Anyway, I replaced the size:ResizeableSize.ratio(0.5)
with size:ResizableSize.shrink()
, but now I ran into theese errors:
[ +507 ms] DartError: Assertion failed: file:///C:/Flutter/flutter/packages/flutter/lib/src/rendering/box.dart:2176:12
hasSize
"RenderBox was not laid out: RenderConstraintsTransformBox#d5f21 relayoutBoundary=up3"
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 288:3 throw_
dart-sdk/lib/_internal/js_dev_runtime/private/profile.dart 110:39 assertFailed
packages/flutter/src/rendering/box.dart 2176:12 get size
packages/flutter_resizable_container/src/resizable_container.dart 204:23 [_getRenderBoxSize]
packages/flutter_resizable_container/src/resizable_container.dart 187:20 <fn>
dart-sdk/lib/internal/iterable.dart 435:31 elementAt
dart-sdk/lib/internal/iterable.dart 364:26 moveNext
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 921:20 next
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 342:14 of
dart-sdk/lib/internal/iterable.dart 224:7 toList
packages/flutter_resizable_container/src/resizable_container.dart 199:35 [_readSizesAfterLayout]
dart-sdk/lib/_internal/js_dev_runtime/private/isolate_helper.dart 47:11 internalCallback
======== Exception caught by rendering library =====================================================
The following assertion was thrown during performLayout():
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/to/debug-render-layer
https://api.flutter.dev/flutter/rendering/debugDumpRenderTree.html
The affected RenderFlex is: RenderFlex#47d86 relayoutBoundary=up4 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: offset=Offset(0.0, 0.0) (can use size)
constraints: BoxConstraints(unconstrained)
size: MISSING
direction: vertical
mainAxisAlignment: start
mainAxisSize: max
crossAxisAlignment: stretch
verticalDirection: down
spacing: 0.0
... child 1: RenderRepaintBoundary#92c97 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... needs compositing
... parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
... constraints: MISSING
... size: MISSING
... usefulness ratio: no metrics collected yet (never painted)
... child: RenderPointerListener#8caea NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: <none>
... constraints: MISSING
... size: MISSING
... behavior: deferToChild
... listeners: signal
... child: RenderSemanticsGestureHandler#52e3b NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: <none>
... constraints: MISSING
... size: MISSING
... behavior: deferToChild
... gestures: <none>
... child: RenderPointerListener#f3246 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: <none>
... constraints: MISSING
... size: MISSING
... behavior: deferToChild
... listeners: down, panZoomStart
The creator information is set to: Column ← CustomerInfoCard ← ConstraintsTransformBox ← UnconstrainedBox-[GlobalKey#da464] ← Builder ← Flex ← PreLayout ← AnimatedBuilder ← LayoutBuilder ← ResizableContainer ← Center ← Expanded-[GlobalKey#141c7] ← ⋯
The nearest ancestor providing an unbounded width constraint is: RenderFlex#5a5b0 relayoutBoundary=up2 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: offset=Offset(0.0, 0.0) (can use size)
... constraints: BoxConstraints(0.0<=w<=913.0, 0.0<=h<=889.0)
... size: MISSING
... direction: vertical
... mainAxisAlignment: start
... mainAxisSize: max
... crossAxisAlignment: stretch
... verticalDirection: down
... spacing: 0.0
See also: https://flutter.dev/unbounded-constraints
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.yml
The relevant error-causing widget was:
Column Column:file:///C:/FlutterProjects/mPortal/lib/widgets/screens/cards/customer/customer_info_card.dart:13:12
When the exception was thrown, this was the stack:
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 288:3 throw_
packages/flutter/src/rendering/flex.dart 1116:9 <fn>
packages/flutter/src/rendering/flex.dart 1118:14 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/rendering/shifted_box.dart 888:12 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/rendering/layout_helper.dart 61:10 layoutChild
packages/flutter/src/rendering/flex.dart 1055:73 [_computeSizes]
packages/flutter/src/rendering/flex.dart 1121:32 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/widgets/layout_builder.dart 379:7 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/rendering/shifted_box.dart 456:7 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/rendering/layout_helper.dart 61:10 layoutChild
packages/flutter/src/rendering/flex.dart 1079:71 [_computeSizes]
packages/flutter/src/rendering/flex.dart 1121:32 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/widgets/layout_builder.dart 379:7 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/rendering/layout_helper.dart 61:10 layoutChild
packages/flutter/src/rendering/flex.dart 1079:71 [_computeSizes]
packages/flutter/src/rendering/flex.dart 1121:32 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/rendering/layout_helper.dart 61:10 layoutChild
packages/flutter/src/rendering/flex.dart 1079:71 [_computeSizes]
packages/flutter/src/rendering/flex.dart 1121:32 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/rendering/layout_helper.dart 61:10 layoutChild
packages/flutter/src/rendering/flex.dart 1079:71 [_computeSizes]
packages/flutter/src/rendering/flex.dart 1121:32 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/rendering/layout_helper.dart 61:10 layoutChild
packages/flutter/src/rendering/flex.dart 1079:71 [_computeSizes]
packages/flutter/src/rendering/flex.dart 1121:32 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/rendering/custom_layout.dart 178:10 layoutChild
packages/flutter/src/material/scaffold.dart 1105:7 performLayout
packages/flutter/src/rendering/custom_layout.dart 242:7 [_callPerformLayout]
packages/flutter/src/rendering/custom_layout.dart 409:5 performLayout
packages/flutter/src/rendering/object.dart 2465:7 [_layoutWithoutResize]
packages/flutter/src/rendering/object.dart 1062:17 flushLayout
packages/flutter/src/rendering/object.dart 1075:14 flushLayout
packages/flutter/src/rendering/binding.dart 609:5 drawFrame
packages/flutter/src/widgets/binding.dart 1178:13 drawFrame
packages/flutter/src/rendering/binding.dart 475:5 [_handlePersistentFrameCallback]
packages/flutter/src/scheduler/binding.dart 1397:7 [_invokeFrameCallback]
packages/flutter/src/scheduler/binding.dart 1318:9 handleDrawFrame
packages/flutter/src/scheduler/binding.dart 1176:5 [_handleDrawFrame]
lib/_engine/engine/platform_dispatcher.dart 1408:5 invoke
lib/_engine/engine/platform_dispatcher.dart 310:5 invokeOnDrawFrame
lib/_engine/engine/initialization.dart 187:36 <fn>
dart-sdk/lib/_internal/js_dev_runtime/patch/js_allow_interop_patch.dart 212:27 _callDartFunctionFast1
The following RenderObject was being processed when the exception was fired: RenderFlex#47d86 relayoutBoundary=up4 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: offset=Offset(0.0, 0.0) (can use size)
... constraints: BoxConstraints(unconstrained)
... size: MISSING
... direction: vertical
... mainAxisAlignment: start
... mainAxisSize: max
... crossAxisAlignment: stretch
... verticalDirection: down
... spacing: 0.0
RenderObject: RenderFlex#47d86 relayoutBoundary=up4 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: offset=Offset(0.0, 0.0) (can use size)
constraints: BoxConstraints(unconstrained)
size: MISSING
direction: vertical
mainAxisAlignment: start
mainAxisSize: max
crossAxisAlignment: stretch
verticalDirection: down
spacing: 0.0
... child 1: RenderRepaintBoundary#92c97 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... needs compositing
... parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
... constraints: MISSING
... size: MISSING
... usefulness ratio: no metrics collected yet (never painted)
... child: RenderPointerListener#8caea NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: <none>
... constraints: MISSING
... size: MISSING
... behavior: deferToChild
... listeners: signal
... child: RenderSemanticsGestureHandler#52e3b NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: <none>
... constraints: MISSING
... size: MISSING
... behavior: deferToChild
... gestures: <none>
... child: RenderPointerListener#f3246 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: <none>
... constraints: MISSING
... size: MISSING
... behavior: deferToChild
... listeners: down, panZoomStart
====================================================================================================
======== Exception caught by rendering library =====================================================
The following assertion was thrown during performLayout():
Assertion failed: file:///C:/Flutter/flutter/packages/flutter/lib/src/rendering/box.dart:2176:12
hasSize
"RenderBox was not laid out: RenderFlex#47d86 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE"
The relevant error-causing widget was:
ResizableContainer ResizableContainer:file:///C:/FlutterProjects/mPortal/lib/widgets/screens/pages/customer_page.dart:43:34
When the exception was thrown, this was the stack:
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 288:3 throw_
dart-sdk/lib/_internal/js_dev_runtime/private/profile.dart 110:39 assertFailed
packages/flutter/src/rendering/box.dart 2176:12 get size
packages/flutter/src/rendering/shifted_box.dart 889:41 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/rendering/layout_helper.dart 61:10 layoutChild
packages/flutter/src/rendering/flex.dart 1055:73 [_computeSizes]
packages/flutter/src/rendering/flex.dart 1121:32 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/widgets/layout_builder.dart 379:7 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/rendering/shifted_box.dart 456:7 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/rendering/layout_helper.dart 61:10 layoutChild
packages/flutter/src/rendering/flex.dart 1079:71 [_computeSizes]
packages/flutter/src/rendering/flex.dart 1121:32 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/widgets/layout_builder.dart 379:7 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/rendering/layout_helper.dart 61:10 layoutChild
packages/flutter/src/rendering/flex.dart 1079:71 [_computeSizes]
packages/flutter/src/rendering/flex.dart 1121:32 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/rendering/layout_helper.dart 61:10 layoutChild
packages/flutter/src/rendering/flex.dart 1079:71 [_computeSizes]
packages/flutter/src/rendering/flex.dart 1121:32 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/rendering/layout_helper.dart 61:10 layoutChild
packages/flutter/src/rendering/flex.dart 1079:71 [_computeSizes]
packages/flutter/src/rendering/flex.dart 1121:32 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/rendering/layout_helper.dart 61:10 layoutChild
packages/flutter/src/rendering/flex.dart 1079:71 [_computeSizes]
packages/flutter/src/rendering/flex.dart 1121:32 performLayout
packages/flutter/src/rendering/object.dart 2627:7 layout
packages/flutter/src/rendering/custom_layout.dart 178:10 layoutChild
packages/flutter/src/material/scaffold.dart 1105:7 performLayout
packages/flutter/src/rendering/custom_layout.dart 242:7 [_callPerformLayout]
packages/flutter/src/rendering/custom_layout.dart 409:5 performLayout
packages/flutter/src/rendering/object.dart 2465:7 [_layoutWithoutResize]
packages/flutter/src/rendering/object.dart 1062:17 flushLayout
packages/flutter/src/rendering/object.dart 1075:14 flushLayout
packages/flutter/src/rendering/binding.dart 609:5 drawFrame
packages/flutter/src/widgets/binding.dart 1178:13 drawFrame
packages/flutter/src/rendering/binding.dart 475:5 [_handlePersistentFrameCallback]
packages/flutter/src/scheduler/binding.dart 1397:7 [_invokeFrameCallback]
packages/flutter/src/scheduler/binding.dart 1318:9 handleDrawFrame
packages/flutter/src/scheduler/binding.dart 1176:5 [_handleDrawFrame]
lib/_engine/engine/platform_dispatcher.dart 1408:5 invoke
lib/_engine/engine/platform_dispatcher.dart 310:5 invokeOnDrawFrame
lib/_engine/engine/initialization.dart 187:36 <fn>
dart-sdk/lib/_internal/js_dev_runtime/patch/js_allow_interop_patch.dart 212:27 _callDartFunctionFast1
The following RenderObject was being processed when the exception was fired: RenderConstraintsTransformBox#4ebd1 relayoutBoundary=up3 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
... constraints: BoxConstraints(w=913.0, 0.0<=h<=Infinity)
... size: MISSING
... alignment: Alignment.center
... textDirection: ltr
RenderObject: RenderConstraintsTransformBox#4ebd1 relayoutBoundary=up3 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
constraints: BoxConstraints(w=913.0, 0.0<=h<=Infinity)
size: MISSING
alignment: Alignment.center
textDirection: ltr
... child: RenderFlex#47d86 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: offset=Offset(0.0, 0.0) (can use size)
... constraints: BoxConstraints(unconstrained)
... size: MISSING
... direction: vertical
... mainAxisAlignment: start
... mainAxisSize: max
... crossAxisAlignment: stretch
... verticalDirection: down
... spacing: 0.0
... child 1: RenderRepaintBoundary#92c97 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... needs compositing
... parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
... constraints: MISSING
... size: MISSING
... usefulness ratio: no metrics collected yet (never painted)
... child: RenderPointerListener#8caea NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: <none>
... constraints: MISSING
... size: MISSING
... behavior: deferToChild
... listeners: signal
... child: RenderSemanticsGestureHandler#52e3b NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: <none>
... constraints: MISSING
... size: MISSING
... behavior: deferToChild
... gestures: <none>
====================================================================================================
Is there anything I should be aware of when using the shrink
method ?
The containing widget above in the upper part, the one i want to embrace, is like this:
class CustomerInfoCard extends StatelessWidget{
const CustomerInfoCard({super.key});
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(child: SingleChildScrollView(
child: StreamBuilder(
stream: globals.mPortalDatabase.getSelectedCustomer(SettingKey.userSelectionSelectedCustomer).watchSingleOrNull(),
builder: (context, snapshot) {
if(snapshot.hasError){
return Card(
color: Colors.red,
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Text(snapshot.error.toString(), style: TextStyle(color: Colors.yellow),),
),
);
}
if(snapshot.connectionState==ConnectionState.waiting){
return const LinearProgressIndicator();
}
if(snapshot.hasData){
var selectedCustomer = snapshot.data;
if(selectedCustomer!=null){
return Card(
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(4.0),
child: Text(AppLocalizations.of(context).customerInfoCardCustomerInformation, style: TextStyle(fontWeight: FontWeight.bold),),
),
Divider(),
Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(4.0),
child: TextField(
controller: TextEditingController(text: selectedCustomer.custNo.toString()),
readOnly: true,
decoration: InputDecoration(
border: OutlineInputBorder(),
label: Text(AppLocalizations.of(context).customerInfoCardCustomerNo)
),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(4.0),
child: TextField(
controller: TextEditingController(text: selectedCustomer.actNo.toString()),
readOnly: true,
decoration: InputDecoration(
border: OutlineInputBorder(),
label: Text(AppLocalizations.of(context).customerInfoCardActorNo)
),
),
),
),
Expanded(
flex: 2,
child: Padding(
padding: const EdgeInsets.all(4.0),
child: TextField(
controller: TextEditingController(text: selectedCustomer.bsNo.toString()),
readOnly: true,
decoration: InputDecoration(
border: OutlineInputBorder(),
label: Text(AppLocalizations.of(context).customerInfoCardBizNo)
),
),
),
),
],
),
Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(4.0),
child: TextField(
controller: TextEditingController(text: selectedCustomer.nm),
readOnly: true,
decoration: InputDecoration(
border: OutlineInputBorder(),
label: Text(AppLocalizations.of(context).customerInfoCardCustomerName)
),
),
),
),
],
),
Row(
children: [
Expanded(
flex: 3,
child: Padding(
padding: const EdgeInsets.all(4.0),
child: TextField(
controller: TextEditingController(text: "${[null,""," "].contains(selectedCustomer.ad1)?"":selectedCustomer.ad1}"
"${((![null,""," "].contains(selectedCustomer.ad2))&&(![null,""," "].contains(selectedCustomer.ad1)))?"\n":""}"
"${[null,""," "].contains(selectedCustomer.ad2)?"":selectedCustomer.ad2}"),
readOnly: true,
maxLines: null,
decoration: InputDecoration(
border: OutlineInputBorder(),
label: Text(AppLocalizations.of(context).customerInfoCardBillingAddress)
),
),
),
),
Expanded(
flex: 1,
child: Padding(
padding: const EdgeInsets.all(4.0),
child: TextField(
controller: TextEditingController(text: selectedCustomer.pNo),
readOnly: true,
decoration: InputDecoration(
border: OutlineInputBorder(),
label: Text(AppLocalizations.of(context).customerInfoCardZIP)
),
),
),
),
Expanded(
flex: 2,
child: Padding(
padding: const EdgeInsets.all(4.0),
child: TextField(
controller: TextEditingController(text: selectedCustomer.pArea.toString()),
readOnly: true,
decoration: InputDecoration(
border: OutlineInputBorder(),
label: Text(AppLocalizations.of(context).customerInfoCardPlace)
),
),
),
),
],
),
Row(
children: [
Expanded(
flex:2,
child: Padding(
padding: const EdgeInsets.all(4.0),
child: TextField(
controller: TextEditingController(text: selectedCustomer.mailAd.toString()),
readOnly: true,
decoration: InputDecoration(
border: OutlineInputBorder(),
label: Text(AppLocalizations.of(context).customerInfoCardMail)
),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(4.0),
child: TextField(
controller: TextEditingController(text: selectedCustomer.phone),
readOnly: true,
decoration: InputDecoration(
border: OutlineInputBorder(),
label: Text(AppLocalizations.of(context).customerInfoCardPhone)
),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(4.0),
child: TextField(
controller: TextEditingController(text: selectedCustomer.mobPh),
readOnly: true,
decoration: InputDecoration(
border: OutlineInputBorder(),
label: Text(AppLocalizations.of(context).customerInfoCardAltPhone)
),
),
),
),
],
),
],
),
),
);
}
}
return Card(
color: Colors.amber,
child: Center(child: Padding(
padding: const EdgeInsets.all(4.0),
child: Text(AppLocalizations.of(context).customerInfoCardCustomerNotAvailable),
),),
);
}
),
))
],
);
}
}
The lower part of the widget is like this:
class CustomerContactsCard extends StatefulWidget{
const CustomerContactsCard({super.key});
@override
State<CustomerContactsCard> createState() => _CustomerContactsCardState();
}
class _CustomerContactsCardState extends State<CustomerContactsCard> {
@override
Widget build(BuildContext context) {
// TODO: implement build
return Card(
child: StreamBuilder(
stream: globals.mPortalDatabase.getSelectedCustomerContacts2(
SettingKey.userSelectionSelectedCustomer,
SettingKey.userSelectionSelectedSupplier
).watch(),
builder: (context, snapshot) {
if(snapshot.hasError){
return Center(
child: Card(
color: Colors.red,
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Text(
snapshot.error.toString(),
style: const TextStyle(color: Colors.yellow),
),
),
),
);
}
if(snapshot.connectionState == ConnectionState.waiting)
{
return const Center(child: CircularProgressIndicator(),);
}
if(snapshot.hasData){
var contacts = snapshot.data;
if(contacts != null){
if(contacts.isNotEmpty){
return Padding(
padding: const EdgeInsets.all(4.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(4.0),
child: Text(AppLocalizations.of(context).customerContactsCardCustomerContacts, style: TextStyle(fontWeight: FontWeight.bold),),
),
const Divider(),
Expanded(
child: DataTable2(
columns: <DataColumn>[
DataColumn2(size: ColumnSize.S,label: Text(AppLocalizations.of(context).customerContactsCardActorNo)),
DataColumn2(label: Text(AppLocalizations.of(context).customerContactsCardActorName)),
DataColumn2(size: ColumnSize.L,label: Text(AppLocalizations.of(context).customerContactsCardActorEmail)),
DataColumn2(size: ColumnSize.S,label: Text(AppLocalizations.of(context).customerContactsCardActorPhone)),
DataColumn2(size: ColumnSize.S,label: Text(AppLocalizations.of(context).customerContactsCardActorPhoneAlt)),
],
rows: List<DataRow2>.generate(
contacts.length, (index) {
return DataRow2(
cells: <DataCell>[
DataCell(Row(children: [Expanded(child: Text("${contacts[index].actNo}"),)],)),
DataCell(Row(children: [Expanded(child: Text("${contacts[index].nm}"),)],)),
DataCell(Row(children: [Expanded(child: Text("${contacts[index].mailAd}"),)],)),
DataCell(Row(children: [Expanded(child: Text("${contacts[index].mobPh}"),)],)),
DataCell(Row(children: [Expanded(child: Text("${contacts[index].phone}"),)],)),
]
);
})),
),
],
),
);
}
}
}
return Center(
child: Card(
color: Colors.amber,
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Text(
AppLocalizations.of(context).customerContactsCardNoContactsAvailable
),
),
),
);
}
),
);
}
}
Is there anything in theese two widgets that should have been restructured to use the shrink
method ?
Showing a picture here:
There should be a ResizeableSize.fitChild so that it could fit its containing child.