Flutter - How to make Container grow with a dynamic ListView? - flutter

I have a Container that contains a ListView, I want the Container to grow as big as the ListView. When I remove the height on the Container, I get an error saying (Vertical viewport was given unbounded height). How can I achieve this with flutter?
The ListView can contain multiple card items.
order_stack.dart file:
import 'package:flutter/material.dart';
class OrderStack extends StatelessWidget {
const OrderStack({Key? key, required this.id, required this.tableNumber}) : super(key: key);
final int id;
final int tableNumber;
#override
Widget build(BuildContext context) {
return Container(
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5)),
color: Color.fromRGBO(33, 49, 55, 1),
),
clipBehavior: Clip.antiAlias,
child: Column(
children: [
Container(
height: 80,
width: 400,
color: const Color.fromRGBO(93, 194, 188, 1),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
padding: const EdgeInsets.only(left: 30),
child: Text(
'Table $tableNumber',
style: const TextStyle(
color: Colors.black,
fontSize: 25,
fontWeight: FontWeight.w900,
),
),
),
Container(
padding: const EdgeInsets.only(right: 30),
child: Text(
'#$id',
style: const TextStyle(
color: Colors.black,
fontSize: 25,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
Container(
height: 70,
width: 400,
child: ListView(
physics: const NeverScrollableScrollPhysics(),
children: <Widget>[
Card(
elevation: 0,
margin: EdgeInsets.zero,
child: ListTile(
tileColor: Colors.yellow[200],
leading: const Text(
'3X',
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.w800
),
),
title: const Text(
'Good Burger',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w800
),
),
subtitle: const Text('Here is a second line'),
trailing: IconButton(
iconSize: 30,
icon: const Icon(Icons.expand_more_outlined),
color: Colors.black,
onPressed: () {},
),
onTap: () => print('Good Burger'),
),
),
],
),
),
],
),
);
}
}

The easiest way would be to wrap your ListView() widget with a Column() and this column given a height of the user's screen with media query remember you should also use shrink wrap to true in the list and wrap your body with SingleChildScrollView()like so:
...
body: SingleChildScrollView(
...
Container(
height: MediaQuery.of(context).size.height,
child: Column(
children: [
///Your listview
ListView(
shrinkWrap: true,
)
]
)
)
...
)

Replace the Container with the Expanded widget. It will expand the ListView to fit the available space in the Column.
Expanded(
child: ListView(
...
)

Related

Renderflex overflowed error, also when i wrap column with SingleChildScrollView or ListView my UI disappered

I am creating a Login page, when i click on text field due to overlapping keyboard i got error......................................................................................................
Renderflex overflowed error, also when i wrap column with SingleChildScrollView or ListView my UI disappered. new to flutter lagging in concept , plz help.
import 'package:flutter/material.dart';
import 'package:flutter_chat_application_1/modals/customtheme.dart';
import 'package:flutter_chat_application_1/widgets/customappbar.dart';
import 'package:flutter_chat_application_1/widgets/widget.dart';
class SignIn extends StatefulWidget {
const SignIn({Key? key}) : super(key: key);
#override
_SignInState createState() => _SignInState();
}
class _SignInState extends State<SignIn> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: CustomAppBar(),
body: Container(
padding: EdgeInsets.symmetric(horizontal: 24),
child: Column(
children: [
Spacer(),
Form(
child: Column(
children: [
TextFormField(
style: myTextStyle(),
decoration: textFieldInputDecoration('email')),
TextFormField(
style: myTextStyle(),
decoration: textFieldInputDecoration('password'),
)
],
),
),
SizedBox(
height: 16,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
padding:
EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: TextButton(
onPressed: () {},
child: Text(
'Forgot Password?',
style: myTextStyle(),
),
))
],
),
SizedBox(
height: 16,
),
GestureDetector(
onTap: () {},
child: Container(
padding: EdgeInsets.symmetric(vertical: 16),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
gradient: LinearGradient(
colors: [Color(0xff007EF4), Color(0xff2A75BC)])),
width: MediaQuery.of(context).size.width,
child: Text(
'Sign In',
style: biggerTextStyle(),
textAlign: TextAlign.center,
),
),
),
SizedBox(
height: 16,
),
GestureDetector(
onTap: () {},
child: Container(
padding: EdgeInsets.symmetric(vertical: 16),
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(30)),
child: Text(
'Sign in with Google',
style:
TextStyle(fontSize: 17, color: CustomTheme.textColor),
textAlign: TextAlign.center,
),
),
),
SizedBox(
height: 16,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Don\'t have account?',
style: myTextStyle(),
),
TextButton(
onPressed: () {},
child: Text('Register Now',
style: TextStyle(
decoration: TextDecoration.underline,
color: Colors.white,
fontSize: 16,
)))
],
),
SizedBox(
height: 10,
)
],
)));
}
}

Error:RenderBox was not laid out: NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE

i am having problem using SingleChildScrollView in this way, i dont no what is wrong, i keep getting this error.
If add the SingleChildScrollView the page will be blank(will not show all the widget)but if i remove the SingleChildScrollView, the page will show.
RenderBox was not laid out: RenderPadding#583c0 relayoutBoundary=up1
NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart': Failed assertion: line 1929
pos 12: 'hasSize
The relevant error-causing widget was Scaffold
Scaffold:file:///Users/mac/Documents/Uneleap-Platform-master/lib/screens/Pages/forum/forum.dart:25:12
here is the code
SafeArea(
minimum: EdgeInsets.only(left: 25.0, right: 20.0, top: 10.0),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
WidgetForum(
details: 'The Get Is Not Geting together ?',
name: 'Nina Simon',
url: 'assets/dashboard_pic.png',
),
SizedBox(
height: 5,
),
WidgetForum(
details:
'''Notes is designed for whatever’s on your mind.\nJot down your thoughts. Download Notes.\nThere is something wonderful in writing. \nThe Get Is Not Getting Together?''',
name: 'James Nugar',
url: 'assets/dashboard_pic.png',
),
Text(
'Topics',
style: TextStyle(
fontSize: 35,
),
),
Expanded(
child: ListView.separated(
scrollDirection: Axis.horizontal,
separatorBuilder: (_, inedex) => SizedBox(
width: 20,
),
itemCount: topics.length,
itemBuilder: (context, index) {
return Container(
height: 50,
width: 100,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(15),
image: DecorationImage(
image: AssetImage('assets/saved_2.png'),
fit: BoxFit.fill,
),
),
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Align(
alignment: Alignment.bottomLeft,
child: Text(
topics[index].schoolNmae!,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
)
],
),
);
}),
),
WidgetForum(
details:
'''Notes is designed for whatever’s on your mind.\nJot down your thoughts. Download Notes.\nThere is something wonderful in writing. \nThe Get Is Not Getting Together?''',
name: 'Sam Ajayi',
url: 'assets/dashboard_pic.png',
),
],
),
),
),
// bottomSheet:
floatingActionButton: FloatingActionButton(
onPressed: () {
Scaffold.of(context).showBottomSheet<void>((BuildContext context) {
return Container(
height: 250,
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
),
),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 50,
horizontal: 15.0,
),
child: Column(
children: [
Row(
children: [
Icon(
CustomIcons.answers_forum,
color: Colors.grey,
),
SizedBox(
width: 10,
),
Text(
'Post',
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: Colors.white,
),
)
],
),
Padding(
padding: const EdgeInsets.only(right: 120.0),
child: Divider(
thickness: 2,
color: Colors.white,
),
),
Row(
children: [
Icon(
CustomIcons.create_forum,
color: Colors.grey,
),
SizedBox(
width: 10,
),
Text(
'Create Forum',
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: Colors.white,
),
)
],
),
Align(
alignment: Alignment.bottomRight,
child: GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Container(
height: 70,
width: 70,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
),
child: Center(
child: Icon(Icons.add),
),
),
),
)
],
),
),
);
});
},
child: Icon(Icons.add),
),
);
}
}
class WidgetForum extends StatefulWidget {
final String? name;
final String? details;
final String? url;
WidgetForum(
{Key? key, required this.name, required this.details, required this.url})
: super(key: key);
#override
_WidgetForumState createState() => _WidgetForumState();
}
class _WidgetForumState extends State<WidgetForum> {
#override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Container(
height: 50,
width: 50,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(widget.url!),
fit: BoxFit.fill,
),
),
),
SizedBox(
width: 5,
),
Text(
widget.name!,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 25),
)
],
),
PopupMenuButton(
color: Colors.black,
offset: Offset(0, 40),
itemBuilder: (_) => <PopupMenuItem<String>>[
new PopupMenuItem<String>(
child: Center(
child: Text(
'Fellow',
style: TextStyle(
color: Colors.white,
),
),
),
),
new PopupMenuItem<String>(
child: Center(
child: Text(
'Block',
style: TextStyle(
color: Colors.white,
),
),
),
),
new PopupMenuItem<String>(
child: Center(
child: Text(
'Report',
style: TextStyle(
color: Colors.white,
),
),
),
),
],
child: Container(
height: 20,
width: 20,
child: SvgPicture.asset('assets/library_pre.svg'),
),
),
],
),
SizedBox(height: 18),
Text(
widget.details!,
style: TextStyle(fontSize: 15),
),
SizedBox(height: 18),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Icon(
CustomIcons.icons8_up_2_11,
color: Colors.red,
),
Text('36'),
Icon(
CustomIcons.icons8_down,
color: Colors.grey,
),
Icon(
CustomIcons.answers_forum,
color: Colors.grey,
),
Text('3')
],
),
Text('Sep 2, 2020')
],
),
Divider(
thickness: 1,
)
],
);
}
}
You cannot use Expanded in Column if it has a parent SingleChildScrollView because When you use column it tries to be in screen height and when use expanded inside, The column will allocate remaining space to the child of the expanded widget, Now if you use SingleChildScrollView It will try to expand(by direction, vertically in your case) as long as possible but as you're using the Expanded which tries to take remaining space, So it goes infinite thus throws that error,
So Either remove SingleChildScrollView and use Column and expanded or remove the Expanded and Use SingleChildScrollView also make sure ShrinkWrap in ListView to true.
Column(
children: [
Text(
'Hello, World!',
style: Theme.of(context).textTheme.headline4,
),
Container(
height: 50,
width: 200,
color: Colors.amber,
child: const Text('Random widget'),
),
Expanded(
child: ListView.separated(
shrinkWrap: true,
itemCount: 20,
separatorBuilder: (_, __) => const Divider(),
itemBuilder: (context, int index) {
return ListTile(
title: Text('Item at $index'),
);
},
),
)
],
);
Or to Scroll all the widgets You can do using SingleChildScrollView
Remove the Expanded widget here.
SingleChildScrollView(
child: Column(
children: [
Text(
'Hello, World!',
style: Theme.of(context).textTheme.headline4,
),
Container(
height: 50,
width: 200,
color: Colors.amber,
child: const Text('Random widget'),
),
ListView.separated(
shrinkWrap: true,
itemCount: 20,
separatorBuilder: (_, __) => const Divider(),
itemBuilder: (context, int index) {
return ListTile(
title: Text('Item at $index'),
);
},
),
],
),
);
Wrap it in a Container and add a height to it.
Fixed it for me.
I solved the issue by enclosing the Column widget in a Container widget that has a set width and height
You cannot use Expanded in Column if it has a parent SingleChildScrollView because When you use column it tries to be in screen height and when use expanded inside, The column will allocate remaining space to the child of the expanded widget, Now if you use SingleChildScrollView It will try to expand(by direction, vertically in your case) as long as possible but as you're using the Expanded which tries to take remaining space, So it goes infinite thus throws that error,
So Either remove SingleChildScrollView and use Column and expanded or remove the Expanded and Use SingleChildScrollView also make sure ShrinkWrap in ListView to true.
I have found the same problem. but in my case I was trying to provide row of widgets
for trailing property of the listTile class .and I solve it by wrapping the row with container and set its width.
In one case, I got the same error.
When I scrolled to top of the log message, I found out the issue in below widget.I have wrapped the Row with IntrinsicHeight widget.
IntrinsicHeight(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: []));
On removing IntrinsicHeight widget, it solved.

how to add fixed container above x number of scrollable card

I am trying to add a fixed buildHelpCard(context, alldata) above the scrollable list but whenever I try to add the buildHelpCard the list got disappeared and only the buildHelpCard is showing ... can you guys please suggest me how to fix this issues
**here is my code**
```
import 'package:flutter/material.dart';
import '../colors/constants.dart';
import 'package:get/get.dart';
import 'package:flutter_svg/flutter_svg.dart';
class duesDetails extends StatefulWidget {
var data;
var count;
duesDetails(this.data, this.count);
#override
_duesDetailsState createState() => _duesDetailsState();
}
class _duesDetailsState extends State<duesDetails> {
#override
Widget build(BuildContext context) {
var alldata = widget.data; // added all value to data for easy access
int count = widget.count;
return Scaffold(
appBar: buildAppBar(alldata),
body: Container(
decoration: BoxDecoration(
color: kPrimaryColor.withOpacity(0.03),
),
child: Center(
child: ListView.builder(
itemBuilder: (BuildContext context, int index) {
return Card(
child: Padding(
padding: const EdgeInsets.only(
top: 22, bottom: 22, left: 16, right: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
InkWell(
onTap: () {},
child: Text(
'${alldata[count]['pay list'][index]['discription']}',
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 22),
),
),
Text(
'Capital',
style: TextStyle(color: Colors.grey.shade500),
),
],
),
Container(
height: 30,
width: 50,
child: Image.asset('assets/facebook.png'),
)
],
),
),
);
},
itemCount: alldata[count]['pay count'] == null ? 0 : alldata[count]['pay count'],
),
),
),
);
}
AppBar buildAppBar(var data) {
return AppBar(
backgroundColor: kPrimaryColor.withOpacity(.05),
elevation: 0,
//title: Obx(() => Text('Randas ', style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold),),),
title: Text("${data[0]['name']} Pay Details", style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold),),
iconTheme: IconThemeData(
color: kPrimaryColor,
size: 28.0,
),
);
}
Container buildHelpCard(BuildContext context, var data) {
return Container(
height: 150,
width: double.infinity,
child: Stack(
alignment: Alignment.bottomLeft,
children: <Widget>[
Container(
padding: EdgeInsets.only(
// left side padding is 40% of total width
left: MediaQuery.of(context).size.width * .4,
top: 20,
right: 20,
),
height: 130,
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0xFF60BE93),
Color(0xFF1B8D59),
],
),
borderRadius: BorderRadius.circular(20),
),
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: "${data[5]["title"]}\n",
style: Theme.of(context)
.textTheme
.headline6
.copyWith(color: Colors.white),
),
TextSpan(
text: "${data[5]["dis"]}",
style: TextStyle(
color: Colors.white.withOpacity(0.7),
),
),
],
),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 210.0, 20.0),
child: SvgPicture.asset("assets/svg/friends.svg"),
),
],
),
);
}
}
```
NOTE - I want to add buildHelpCard(context, alldata) function above the start of the card list... but when I try to do this the list got disappeared
Try this
child: Column(
children: [
buildHelpCard()
Expanded(child:
ListView.builder(
itemBuilder: (BuildContext context, int index) {
return Card(
child: Padding(
padding: const EdgeInsets.only(
top: 22, bottom: 22, left: 16, right: 16),
child:........

Define Number of lists according with Number into Widget flutter

What I Have are number of orders received that has be shown into a tab into a widget in flutter according with this code:
class ShipmentTab extends StatefulWidget {
#override
_ShipmentTabState createState() => _ShipmentTabState();
}
class _ShipmentTabState extends State<ShipmentTab> {
**final shipmentNumber = "16";**
#override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Card(
color: Color(0xfffeaf0d),
child: Container(
width: 40,
height: 40,
child: Icon(
Icons.local_shipping,
color: Colors.white,
),
),
),
),
Padding(
padding: const EdgeInsets.all(13),
child: Text(
shipmentNumber,
style: TextStyle(
color: Colors.white, fontSize: 35, fontWeight: FontWeight.bold),
),
),
],
);
}
}
as you can see variable is " shipmentNumber " that show "16"
below I have listview.builder and I need to add itemCount and this count has to be refered to the tab above "16"
this is the code of the list:
Container(
height: 400,
child: ListView.builder(
shrinkWrap: true,
itemBuilder: (ctx, int) {
return Card(
color: Color(0xFF1f2032),
elevation: 15,
child: Container(
width: 60,
height: 60,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Card(
color: Color(0xfffeaf0d),
child: Container(
height: 40,
width: 40,
child: Icon(
Icons.local_shipping,
color: Colors.white,
size: 25,
)),
),
Text(
'Ref № $int',
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
),
Text(
'Mario Rossi',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Color(0xfffeaf0d),
),
),
Text(
'Consegnato',
style: TextStyle(color: Colors.lightGreenAccent),
),
Icon(
Icons.share,
color: Colors.white,
)
],
),
),
);
},
),
),
],
);
}
}
ListView.builder has itemCount parameter. I notice shipmentNumber is in String so you can parse it to int. Also you need to remove the Container height wrapping your ListView
ListView.builder(
shrinkWrap: true,
itemCount: int.parse(shipmentNumber),
itemBuilder: (BuildContext context, int index) {
/** build your Item here **/
return BuiltItem();
},
)

Flutter: How to set variable length string inside a row?

I am trying to set a string inside a row, but the length of the string is variable i.e data is fetched from API. Then it is set inside the row, but currently, as the length is greater it shows as A RenderFlex overflowed by 48 pixels on the right.
I am been trying to use expanded/flex/flexible but getting incorrect parent error. (Don't know how to as I am new to flutter)
So, please help in how to solve this problem of renderflex overflow.
Following is my method:
void confirmpayment(double amount, String description) {
final itemsSubmit = <Widget>[
Image.asset(
'images/payments.jpg',
width: MediaQuery.of(context).size.width,
fit: BoxFit.contain,
),
ListTile(
title: AutoSizeText(
'Confirmation',
style: TextStyle(fontSize: 20),
),
subtitle: AutoSizeText(
'Hey Gaurav, please confirm examination as payment once done will be irrevocable.',
style: TextStyle(color: Colors.grey),
),
// onTap: () {},
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 20,
),
Padding(
padding: EdgeInsets.only(top: 10),
child: AutoSizeText(
'Exam:',
textAlign: TextAlign.start,
style: TextStyle(
fontSize: 16,
),
),
),
Spacer(),
CheckboxGroup(
orientation: GroupedButtonsOrientation.VERTICAL,
labelStyle: TextStyle(fontSize: 15),
labels: [
...listexam.map((location) {
return location['name']; //this is where string is set from api data
}).toList()
],
checked: _checked,
),
SizedBox(
width: 20,
),
],
),
Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 20,
),
Padding(
padding: EdgeInsets.only(top: 1),
child: AutoSizeText(
'Plan',
textAlign: TextAlign.start,
style: TextStyle(
fontSize: 16,
),
),
),
Expanded(
child: Padding(
padding: EdgeInsets.only(top: 1),
child: AutoSizeText(
description,
textAlign: TextAlign.right,
textDirection: TextDirection.ltr,
style: TextStyle(
fontSize: 15,
),
),
),
),
SizedBox(
width: 20,
),
]),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 20,
),
Padding(
padding: EdgeInsets.only(top: 1),
child: AutoSizeText(
'Amount',
textAlign: TextAlign.start,
style: TextStyle(
fontSize: 16,
),
)),
Expanded(
child: Padding(
padding: EdgeInsets.only(top: 1),
child: AutoSizeText(
'Rs. ' + amount.toString(),
textDirection: TextDirection.ltr,
textAlign: TextAlign.right,
style: TextStyle(
fontSize: 15,
// fontWeight: FontWeight.w500,
),
),
),
),
SizedBox(
width: 20,
),
]),
SizedBox(
height: 40,
),
Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: <Widget>[
RaisedButton(
elevation: 1,
// onPressed: _showSheetSubmit,
color: Colors.grey[200],
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(28.0),
side: BorderSide(color: Colors.grey[200])),
onPressed: null,
child: AutoSizeText(
"Cancel",
style: TextStyle(
fontSize: 16,
// fontFamily: 'lato',
letterSpacing: 1,
color: Colors.white,
),
)),
RaisedButton(
elevation: 1,
color: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(28.0),
side: BorderSide(color: Colors.green)),
onPressed: () {
openCheckout(amount, description);
},
child: AutoSizeText(
"Buy",
style: TextStyle(
fontSize: 16,
// fontFamily: 'lato',
color: Colors.white,
letterSpacing: 1),
)),
]),
SizedBox(
height: MediaQuery.of(context).size.height / 12,
),
];
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
backgroundColor: Colors.white,
context: context,
builder: (BuildContext _) {
return Container(
// color: Colors.white,
child: Wrap(
children: itemsSubmit,
),
);
},
isScrollControlled: true,
// isDismissible: true
);
}
Following is the mock:
Instead of trying to trim the String data that will go into the Text widget, I would use a LayoutBuilder to get the available space that the Row widget could occupy. Then, I would wrap the Text in a SizedBox to limit the maximum width of the Text widget. Finally, I would set the overflow property of the Text widget, so that it shows an ellipsis when the text is longer than the available space.
Here is a little app I wrote for you to see how to do this. You can run it on DartPad to play around with it.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
LayoutBuilder(
builder: (context, constraints) {
return Row(
children: <Widget>[
SizedBox(
width: constraints.maxWidth,
child: Text(
'This is a very very long text that might overflow the available rendering space',
overflow: TextOverflow.ellipsis,
),
),
],
);
},
),
],
),
),
);
}
}