0

I want a minimum spacing of 20 between Left Text and Right Text, and Left Text can multi Line automatically

Limiting the width on the left or right side does not solve the problem well, because the length of Right Text is also uncertain.

I tried many ways, but without success, Please Help. Thanks very much!

enter image description here


 Future<void> _pop() async {
 final res = await showModalBottomSheet(
 context: context,
 isScrollControlled: true,
 builder: (BuildContext context) {
 return DemoView();
 });
 }
import 'package:flutter/material.dart';
class DemoView extends StatelessWidget {
 DemoView({super.key});
 final list = ['A Very Long Text ' * 2, 'B Text --------- Text', 'C Text'];
 final list1 = ['Right Text', 'Right Text Right Text', 'C Text'];
 @override
 Widget build(BuildContext context) {
 return Padding(
 padding: const EdgeInsets.all(16),
 child: Column(
 mainAxisSize: MainAxisSize.min,
 children: [
 ...list.mapIndexed((i, e) => Container(
 color: Colors.grey,
 padding: const EdgeInsets.all(16),
 margin: const EdgeInsets.all(16),
 child: Row(
 children: [
 Column(
 crossAxisAlignment: CrossAxisAlignment.start,
 children: [
 Text(
 e,
 maxLines: 3,
 // softWrap: true,
 // overflow: TextOverflow.ellipsis,
 ),
 Text('C Short Text'),
 ],
 ),
 const Spacer(),
 Container(
 constraints: BoxConstraints(minWidth: 20),
 ),
 Text(
 list1[i],
 textAlign: TextAlign.end,
 )
 ],
 ),
 ))
 ],
 ),
 );
 }
}
extension ListExtensions<E> on List<E> {
 Iterable<R> mapIndexed<R>(R Function(int index, E element) convert) sync* {
 for (var index = 0; index < length; index++) {
 yield convert(index, this[index]);
 }
 }
}
asked Jul 25, 2024 at 4:37
2
  • Try to use ListTile() widget Commented Jul 25, 2024 at 4:43
  • 2
    Refer this hope its help. Commented Jul 25, 2024 at 4:49

2 Answers 2

3

enter image description here

Try the following snippet:

Container(
 color: Colors.black38,
 child: Row(
 children: [
 Expanded(
 flex : 2,
 child: Text('Very ver long text Very ver long text Very ver long text Very ver long text')
 ),
 Expanded(
 flex : 1,
 child: Text('any text any text any text any text any text any text')
 )
 ],
 ),
 )
answered Jul 25, 2024 at 5:34
Sign up to request clarification or add additional context in comments.

Comments

1

You may wrap the Column with long text in Expanded and set a desired maxWidth constraint to the right text.

 Row(
 children: [
 Expanded(
 child: Column(
 crossAxisAlignment: CrossAxisAlignment.start,
 children: [
 Text(
 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore ",
 maxLines: 3,
 // softWrap: true,
 overflow: TextOverflow.ellipsis,
 ),
 Text('C Short Text'),
 ],
 ),
 ),
 // const Spacer(),
 Container(
 constraints: BoxConstraints(minWidth: 20),
 ),
 Container(
 constraints: BoxConstraints(maxWidth: 150),
 child: Text(
 " Text2:",
 maxLines: 1,
 overflow: TextOverflow.ellipsis,
 textAlign: TextAlign.end,
 ),
 )
 ],
 ),

Screenshot

answered Jul 25, 2024 at 6:33

1 Comment

It's Cool. Thanks!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.