How to structure table data within Flutter - flutter

I am currently trying to create a table like structure within my code and am sure there is an easier way of completing this rather than what I have already attempting which is bulky and achieves an incorrect outcome.
SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Stack(
children: <Widget>[
Container(
width: double.infinity,
height: 750,
child: Stack(
children: <Widget>[
Positioned(
right: 0,
top: 0,
left: 0,
child: Padding(
padding: const EdgeInsets.only(
left: 20.0,
top: 20.0,
),
child: Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Text(
'How much should I charge?',
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 20.0,
fontFamily: 'OpenSans',
fontWeight: FontWeight.bold,
),
),
),
),
),
],
),
),
Positioned(
top: 60,
right: 90,
left: 0,
child: Padding(
padding: const EdgeInsets.only(bottom: 10.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'Currency used for this campaign: USD\$',
style: TextStyle(
fontFamily: 'OpenSans',
fontSize: 14.0,
),
),
],
),
),
),
Positioned(
top: 90.0,
left: 3.0,
right: 3.0,
child: Padding(
padding: const EdgeInsets.only(left: 20.0, right: 20.0),
child: Divider(
height: 10.0,
color: Colors.black45,
),
),
),
Positioned(
top: 95.0,
left: 3.0,
right: 3.0,
child: Row(
children: <Widget>[
Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 30.0, right: 30.0),
child: Text(
'IN-FEED POSTS',
style: TextStyle(
fontSize: 18,
color: Colors.deepPurpleAccent,
fontFamily: 'OpenSans',
fontWeight: FontWeight.bold),
),
),
],
),
Container(
height: 60,
child: VerticalDivider(color: Colors.black45)),
],
),
),
Positioned(
top: 125.0,
left: 3.0,
right: 3.0,
child: Row(
children: <Widget>[
Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 30.0, right: 30.0),
child: Text(
'Followers per account',
style: TextStyle(
fontSize: 14,
fontFamily: 'OpenSans',
),
),
)
],
),
Container(
height: 60,
child: VerticalDivider(color: Colors.black45)),
],
),
),
],
),
),
This is the final outcome I have so far achieved using this code strategy.
Can anyone suggest another strategy?

I think the simplest way is to use row and column.
I'm not in front of PC, you can try with something like that!
Column
Text,
Text,
Row
Container -> border.only
Column
Text
Text
Container -> border.only
Column
Text
Text
Hope this help.

I've made a solution working with TableRow, the structure is quite similar to that Simone's made.
Check it out below...
Container(
padding: EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 5),
child: Text(
'How much should I charge?',
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 20.0,
fontFamily: 'OpenSans',
),
),
),
Padding(
child: Text(
'Currency used for this campaign: USD\$',
style: TextStyle(
fontFamily: 'OpenSans', fontSize: 14.0, color: Colors.grey),
),
padding: EdgeInsets.only(bottom: 10),
),
Container(
child: Table(
border: TableBorder(
top: BorderSide(width: 2, color: Colors.grey.shade300),
verticalInside:
BorderSide(width: 1, color: Colors.grey.shade300),
),
children: [
TableRow(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Padding(
child: Text(
'IN-FEED POSTS',
style: TextStyle(
fontSize: 18,
color: Colors.pinkAccent,
fontFamily: 'OpenSans',
),
),
padding: EdgeInsets.only(top: 10),
),
Padding(
child: Text(
'Followers per account',
style: TextStyle(
fontSize: 14,
fontFamily: 'OpenSans',
),
),
padding: EdgeInsets.only(bottom: 10),
),
],
),
Container(
child: Column(children: <Widget>[
Padding(
child: Text(
'Another text...',
style: TextStyle(
fontSize: 18,
color: Colors.black,
fontFamily: 'OpenSans',
),
),
padding: EdgeInsets.only(top: 10),
),
]),
),
],
),
],
),
),
],
),
),

Related

How to remove an item that contains a map that I build with a ListView.builder using a button (a cart page) ? - Flutter

I have a cart page in my app that contains a list of items.
I build this list with a ListView.builder. The content it returns contains a data from API.
Here's the visual of it
and here's my code
ListView.builder(
itemCount: cartController.cartList.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: Container(
width: MediaQuery
.of(context)
.size
.width,
decoration: BoxDecoration(
color: Color(0xffF1F5F9),
boxShadow: <BoxShadow>[
BoxShadow(
color: Color(0xff7D7D7D).withOpacity(0.6),
blurRadius: 4.0,
offset: Offset(2, 3))
],
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(10, 6, 10, 6),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 40,
width: 40,
child: CachedNetworkImage(
useOldImageOnUrlChange: false,
imageUrl:
'${cartController.cartList.values.toList() [index]
.image}',
placeholder: (context, url) =>
Stack(
alignment: Alignment.center,
children: [
Image.asset(
Constants.loading,
height: 30,
width: 30,
),
],
),
errorWidget: (context, url, error) =>
Image.asset(
"assets/logo/carisayur_empty.png",
height: 20,
width: 20,
),
)),
Padding(
padding: const EdgeInsets.only(left: 14.0, top: 12),
child: Text(
'${cartController.cartList.values.toList() [index]
.name}',
maxLines: 2,
style: TextStyle(
fontSize: 12,
color: Color(0xff31708F),
fontWeight: FontWeight.w500),
),
),
Spacer(),
IconButton(
padding: EdgeInsets.zero,
constraints: BoxConstraints(),
onPressed: () {
cartController.cartList.remove(index);
},
icon: Icon(
Icons.close,
color: Color(0xff31708F),
size: 20,
),
),
// Image.asset("assets/icons/cancel.png"),
],
),
),
Divider(
thickness: 0.8,
color: Color(0xffE1E1E1),
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 70,
padding: const EdgeInsets.only(left: 8.0),
child: Text(
"Kemasan",
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w400,
color: Color(0xff000000)),
),
),
Container(
width: MediaQuery
.of(context)
.size
.width / 2,
child: Text(
"Jumlah",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w400,
color: Color(0xff000000)),
),
),
Spacer(),
Padding(
padding: const EdgeInsets.only(right: 20),
child: Text(
"Harga",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w400,
color: Color(0xff000000)),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 70,
child: Text(
'${cartController.cartList.values.toList() [index]
.kemasan}',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w600,
color: Color(0xff7F8A8E)),
),
),
Container(
width: MediaQuery
.of(context)
.size
.width / 2,
child: Text(
"1",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w500,
color: Color(0xff7F8A8E)),
),
),
Spacer(),
Padding(
padding: const EdgeInsets.only(right: 20),
child: Text(
"${GlobalFunctions().rupiah(
cartController.cartList.values.toList() [index]
.price ?? 0)}",
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w500,
color: Color(0xff000000))),
)
],
),
Divider(
thickness: 0.8,
color: Color(0xffE1E1E1),
),
Padding(
padding: const EdgeInsets.fromLTRB(10, 6, 18, 6),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(left: 10, right: 5.0),
child: Image.asset("assets/icons/edit.png"),
),
Text(
"Edit",
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w400,
color: Color(0xff000000)),
),
Padding(
padding: EdgeInsets.only(left: 60, right: 5),
child:
InkWell(
onTap: () {
setState(() {
isTap = !isTap;
});
if (isTap == true) {
favAlert(
'Barang berhasil \n'
'ditambahkan \n'
'ke Favorit',
);
} else {
favAlert(
'Favorit dihapus'
);
}
},
// padding: EdgeInsets.only(right: 35, top: 3),
child: Container(
child: isTap == false
? Icon(Icons.favorite_border, size: 14,)
: Icon(
Icons.favorite, color: Colors.red, size: 14,),
),
),
),
Text(
"Favorit",
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w400,
color: Color(0xff000000)),
),
Spacer(),
Text(
"Total",
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w400,
color: Color(0xff000000)),
),
Padding(
padding: const EdgeInsets.only(left: 16),
child:
Text(
"${GlobalFunctions().rupiah(
cartController.cartList.values.toList() [index]
.price ?? 0)}",
style: TextStyle(
fontSize: 12,
color: Color(0xff31708F),
fontWeight: FontWeight.w500),
),
)
],
),
),
],
),
),
);
}),
if I print the cartController.cartList and cartController.cartList.length, it will print I/flutter ( 5474): {2907: Instance of 'UpdateCartProductResponse', 2916: Instance of 'UpdateCartProductResponse', 2820: Instance of 'UpdateCartProductResponse'} and 3
my problem is I can't remove one of the item with an IconButton that I made there.
How can I remove an item?

Flutter - How to fix text overflow in a card?

I'm building an app and I want to show this text but i need put some "limit" to not happen this:
card with overflow
so, I tried a few things (like SizedBox to limit the text, AutoSizeText to change the font size... but i don't know how to limit this and make this responsive), but to no avail.
this is the code of the card:
Card(
child: Container(
height: 120,
child: Padding(
padding: EdgeInsets.only(
left: 15,
right: 15,
top: 10,
bottom: 10,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
ClipOval(
child: Image.network(
pedido.logomarca,
height: 90,
width: 90,
),
),
Padding(
padding: EdgeInsets.only(left: 20),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
SizedBox(
child: AutoSizeText(
pedido.nomefantasia.toUpperCase(),
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
Row(
children: <Widget>[
ClipOval(
child: Container(
height: 10,
width: 10,
color: Colors.green,
),
),
Padding(
padding: EdgeInsets.only(
left: 8,
),
child: Text(
pedido.statuspedidodescricao,
),
),
),
],
),
],
),
),
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
DateFormat('dd/MM/yyyy').format(pedido.datavenda),
style: TextStyle(
color: Colors.blueGrey,
fontSize: 14,
),
),
Padding(
padding: EdgeInsets.only(top: 10),
child: Text(
'R\$ ${pedido.valortotal.toStringAsFixed(2).replaceAll('.', ',')}',
style: TextStyle(
color: Colors.green[600],
fontSize: 16,
),
),
),
telefone
? OutlineButton(
onPressed: () {},
splashColor: Colors.green,
highlightColor: Colors.green,
highlightedBorderColor: Colors.green,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Ligar'),
Padding(
padding: EdgeInsets.only(left: 3),
child: Icon(
Icons.call,
size: 15,
),
),
],
),
)
: Container(),
],
),
),
],
),
),
),
),
AutoSized text has a parameter you need to set. maxlines: 2
AutoSizeText(
pedido.nomefantasia.toUpperCase(),
maxlines: 2,
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
Documentation
change this:
Padding(
padding: EdgeInsets.only(
left: 8,
),
child: Text(
pedido.statuspedidodescricao,
),
),
to this:
Expanded(
child: Padding(
padding: EdgeInsets.only(
left: 8,
),
child: Text(
pedido.statuspedidodescricao,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
)

Exception type Future(void) in not subtype of Future<AnimationController>

the code below performs the creation of a layout in flutter, to create the layout I must first make sure that the set function is executed to make it use future builder but when I run the code I have the following error.
It tells me that the following error is present, future is not a subtype of future ,
theoretically both derive from object so there shouldn't be inheritance problems on dart, what is this due to?
Error:
type Future(void) in not subtype of Future
Flutter Code:
import ...
double latitudine=0;
Future<void> setValori() async {
latitudine=await Gps.getLatitudine();
print("Latitudine: "+latitudine.toString());
print("\n \n Sono dentro set valori \n \n");
}
class MediterranesnDietView extends StatelessWidget {
final AnimationController animationController;
final Animation animation;
const MediterranesnDietView(
{Key key, this.animationController, this.animation})
: super(key: key);
#override
Widget build(BuildContext context) {
return FutureBuilder<AnimatedBuilder>(
future: setValori(),
builder: (BuildContext context, AsyncSnapshot<AnimatedBuilder> snapshot) {
return AnimatedBuilder(
animation: animationController,
builder: (BuildContext context, Widget child) {
return FadeTransition(
opacity: animation,
child: new Transform(
transform: new Matrix4.translationValues(
0.0, 30 * (1.0 - animation.value), 0.0),
child: Padding(
padding: const EdgeInsets.only(
left: 24, right: 24, top: 16, bottom: 18),
child: Container(
decoration: BoxDecoration(
color: FintnessAppTheme.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(8.0),
bottomLeft: Radius.circular(8.0),
bottomRight: Radius.circular(8.0),
topRight: Radius.circular(68.0)),
boxShadow: <BoxShadow>[
BoxShadow(
color: FintnessAppTheme.grey.withOpacity(0.2),
offset: Offset(1.1, 1.1),
blurRadius: 10.0),
],
),
child: Column(
children: <Widget>[
Padding(
padding:
const EdgeInsets.only(top: 16, left: 16, right: 16),
child: Row(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 8, right: 8, top: 4),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Container(
height: 48,
width: 2,
decoration: BoxDecoration(
color: HexColor('#87A0E5')
.withOpacity(0.5),
borderRadius: BorderRadius.all(
Radius.circular(4.0)),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(
left: 4, bottom: 2),
child: Text(
'Latitudine',
textAlign: TextAlign.center,
style: TextStyle(
fontFamily:
FintnessAppTheme.fontName,
fontWeight: FontWeight.w500,
fontSize: 16,
letterSpacing: -0.1,
color: FintnessAppTheme.grey
.withOpacity(0.5),
),
),
),
Row(
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.end,
children: <Widget>[
SizedBox(
width: 28,
height: 28,
child: Image.asset(
"assets/Home/eaten.png"),
),
Padding(
padding:
const EdgeInsets.only(
left: 4, bottom: 3),
child: Text(
'${(latitudine * animation.value).toInt()}',
textAlign: TextAlign.center,
style: TextStyle(
fontFamily:
FintnessAppTheme
.fontName,
fontWeight:
FontWeight.w600,
fontSize: 16,
color: FintnessAppTheme
.darkerText,
),
),
),
Padding(
padding:
const EdgeInsets.only(
left: 4, bottom: 3),
child: Text(
'',
textAlign: TextAlign.center,
style: TextStyle(
fontFamily:
FintnessAppTheme
.fontName,
fontWeight:
FontWeight.w600,
fontSize: 12,
letterSpacing: -0.2,
color: FintnessAppTheme
.grey
.withOpacity(0.5),
),
),
),
],
)
],
),
)
],
),
SizedBox(
height: 8,
),
Row(
children: <Widget>[
Container(
height: 48,
width: 2,
decoration: BoxDecoration(
color: HexColor('#F56E98')
.withOpacity(0.5),
borderRadius: BorderRadius.all(
Radius.circular(4.0)),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(
left: 4, bottom: 2),
child: Text(
'Longitudine',
textAlign: TextAlign.center,
style: TextStyle(
fontFamily:
FintnessAppTheme.fontName,
fontWeight: FontWeight.w500,
fontSize: 16,
letterSpacing: -0.1,
color: FintnessAppTheme.grey
.withOpacity(0.5),
),
),
),
Row(
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.end,
children: <Widget>[
SizedBox(
width: 28,
height: 28,
child: Image.asset(
"assets/Home/burned.png"),
),
Padding(
padding:
const EdgeInsets.only(
left: 4, bottom: 3),
child: Text(
'${(102 * animation.value).toInt()}',
textAlign: TextAlign.center,
style: TextStyle(
fontFamily:
FintnessAppTheme
.fontName,
fontWeight:
FontWeight.w600,
fontSize: 16,
color: FintnessAppTheme
.darkerText,
),
),
),
Padding(
padding:
const EdgeInsets.only(
left: 8, bottom: 3),
child: Text(
'Kcal',
textAlign: TextAlign.center,
style: TextStyle(
fontFamily:
FintnessAppTheme
.fontName,
fontWeight:
FontWeight.w600,
fontSize: 12,
letterSpacing: -0.2,
color: FintnessAppTheme
.grey
.withOpacity(0.5),
),
),
),
],
)
],
),
)
],
)
],
),
),
),
Padding(
padding: const EdgeInsets.only(right: 16),
child: Center(
child: Stack(
overflow: Overflow.visible,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: FintnessAppTheme.white,
borderRadius: BorderRadius.all(
Radius.circular(100.0),
),
border: new Border.all(
width: 4,
color: FintnessAppTheme
.nearlyDarkBlue
.withOpacity(0.2)),
),
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.center,
children: <Widget>[
Text(
'${(1503 * animation.value).toInt()}',
textAlign: TextAlign.center,
style: TextStyle(
fontFamily:
FintnessAppTheme.fontName,
fontWeight: FontWeight.normal,
fontSize: 24,
letterSpacing: 0.0,
color: FintnessAppTheme
.nearlyDarkBlue,
),
),
Text(
'Kcal left',
textAlign: TextAlign.center,
style: TextStyle(
fontFamily:
FintnessAppTheme.fontName,
fontWeight: FontWeight.bold,
fontSize: 12,
letterSpacing: 0.0,
color: FintnessAppTheme.grey
.withOpacity(0.5),
),
),
],
),
),
),
Padding(
padding: const EdgeInsets.all(4.0),
child: CustomPaint(
painter: CurvePainter(
colors: [
FintnessAppTheme.nearlyDarkBlue,
HexColor("#8A98E8"),
HexColor("#8A98E8")
],
angle: 140 +
(360 - 140) *
(1.0 - animation.value)),
child: SizedBox(
width: 108,
height: 108,
),
),
)
],
),
),
)
],
),
),
Padding(
padding: const EdgeInsets.only(
left: 24, right: 24, top: 8, bottom: 8),
child: Container(
height: 2,
decoration: BoxDecoration(
color: FintnessAppTheme.background,
borderRadius: BorderRadius.all(Radius.circular(4.0)),
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 24, right: 24, top: 8, bottom: 16),
child: Row(
children: <Widget>[
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Carbs',
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: FintnessAppTheme.fontName,
fontWeight: FontWeight.w500,
fontSize: 16,
letterSpacing: -0.2,
color: FintnessAppTheme.darkText,
),
),
Padding(
padding: const EdgeInsets.only(top: 4),
child: Container(
height: 4,
width: 70,
decoration: BoxDecoration(
color:
HexColor('#87A0E5').withOpacity(0.2),
borderRadius: BorderRadius.all(
Radius.circular(4.0)),
),
child: Row(
children: <Widget>[
Container(
width: ((70 / 1.2) * animation.value),
height: 4,
decoration: BoxDecoration(
gradient: LinearGradient(colors: [
HexColor('#87A0E5'),
HexColor('#87A0E5')
.withOpacity(0.5),
]),
borderRadius: BorderRadius.all(
Radius.circular(4.0)),
),
)
],
),
),
),
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
'12g left',
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: FintnessAppTheme.fontName,
fontWeight: FontWeight.w600,
fontSize: 12,
color: FintnessAppTheme.grey
.withOpacity(0.5),
),
),
),
],
),
),
...
),
),
),
);
},
);
});
}
}
The error indicates, that the Future you are giving the FutureBuilder does not match the Builders generic type.
You defined FutureBuilder<AnimatedBuilder> with the generic parameter AnimatedBuilder and it expects a Future<AnimatedBuilder>. The function setValori() is returning a Future<void>.
If you change your FutureBuilder<AnimatedBuilder> to FutureBuilder<void> and change AsyncSnapshot<AnimatedBuilder> to AsyncSnapshot<void>, you resolved the issues.
As your method setValori() returns a Future of type void you need to change the following line:
return FutureBuilder<AnimatedBuilder>
this should be
return FutureBuilder<void>

How to align TextFields e.g. Text() in a column?

I'm trying to draw a Dialog/Popup that will show when user taps on a marker in google map.
The problem is that the Text-Fields doesn't align in the Dialog. You can see it below in the image:
So, I wonder how I could align the text so each new text begins at a line vertically.
And here is my code for it:
child: Material(
color: Colors.transparent,
child: ScaleTransition(
scale: scaleAnimation,
child: Container(
decoration: ShapeDecoration(
color: Colors.blueGrey[900],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0))),
child: Padding(
padding: const EdgeInsets.fromLTRB(40, 20, 40, 15),
child: Container(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
child: Text(
'Stackoverflow Restaurant',
style: new TextStyle(
fontSize: 20.0,
color: textColorPopup,
fontWeight: FontWeight.bold),
),
),
Container(
padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
child: Text(
'Open hours',
style: new TextStyle(
fontSize: fontSizeWeekDays, color: textColorPopup),
),
),
Container(
padding: EdgeInsets.fromLTRB(0, 10, 0, 0),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'MON',
style: new TextStyle(
fontSize: fontSizeOpenHours,
color: textColorPopup),
),
SizedBox(
width: 30.0,
),
Text(
'15.00 - 03.00',
style: new TextStyle(
fontSize: fontSizeOpenHours,
color: textColorPopup),
),
],
),
),
Container(
padding: EdgeInsets.fromLTRB(0, 5, 0, 0),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'TUE',
style: new TextStyle(
fontSize: fontSizeOpenHours,
color: textColorPopup),
),
SizedBox(
width: 30.0,
),
Text(
'15.00 - 03.00',
style: new TextStyle(
fontSize: fontSizeOpenHours,
color: textColorPopup),
),
],
),
),
Container(
padding: EdgeInsets.fromLTRB(0, 5, 0, 0),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'WEN',
style: new TextStyle(
fontSize: fontSizeOpenHours,
color: textColorPopup),
),
SizedBox(
width: 30.0,
),
Text(
'15.00 - 03.00',
style: new TextStyle(
fontSize: fontSizeOpenHours,
color: textColorPopup),
),
],
),
),
Container(
padding: EdgeInsets.fromLTRB(0, 5, 0, 0),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'THU',
style: new TextStyle(
fontSize: fontSizeOpenHours,
color: textColorPopup),
),
SizedBox(
width: 30.0,
),
Text(
'15.00 - 03.00',
style: new TextStyle(
fontSize: fontSizeOpenHours,
color: textColorPopup),
),
],
),
),
Container(
padding: EdgeInsets.fromLTRB(0, 5, 0, 0),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'FRI',
style: new TextStyle(
fontSize: fontSizeOpenHours,
color: textColorPopup),
),
SizedBox(
width: 30.0,
),
Text(
'15.00 - 03.00',
style: new TextStyle(
fontSize: fontSizeOpenHours,
color: textColorPopup),
),
],
),
),
Container(
padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'SAT',
style: new TextStyle(
fontSize: fontSizeOpenHours,
color: textColorPopup),
),
SizedBox(
width: 30.0,
),
Text(
'15.00 - 03.00',
style: new TextStyle(
fontSize: fontSizeOpenHours,
color: textColorPopup),
),
],
),
),
Container(
padding: EdgeInsets.fromLTRB(0, 5, 0, 30),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'SUN',
style: new TextStyle(
fontSize: fontSizeOpenHours,
color: textColorPopup),
),
SizedBox(
width: 30.0,
),
Text(
'15.00 - 03.00',
style: new TextStyle(
fontSize: fontSizeOpenHours,
color: textColorPopup),
),
],
),
),
RaisedButton(
padding: EdgeInsets.fromLTRB(60, 0, 60, 0),
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
onPressed: _dismissAlertDialog,
child: Text(
'CLOSE',
style: TextStyle(
fontSize: 18,
color: Colors.black,
fontStyle: FontStyle.normal),
),
),
],
),
),
),
),
),
),
use mainAxisAlignment: MainAxisAlignment.spaceBetween on each Row and the Days will align left and the Times will align right.

Flutter text is not ellipsized in the list

I have a list of object. There is a name that can be long and according to design it should end with three dots if it can't fit
Container(
height: 72,
constraints: BoxConstraints(minWidth: double.infinity),
child: Row(
children: <Widget>[
Container(
margin: const EdgeInsets.only(left: 16.0, right: 16.0),
child: CircleAvatar(
radius: 20.0,
backgroundImage: NetworkImage(_model._organizerLogo),
backgroundColor: Colors.transparent,
),
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.only(right: 8.0),
child: Text(
_model._eventName,
style: TextStyle(
fontSize: 15,
color: Colors.black,
fontWeight: FontWeight.w500),
textAlign: TextAlign.start,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
...
])
],
),
)
Wrapping Container in Flexible or Expandable didn't work.
How to make oversized text ellipsis? Thanks!
Add Expanded to your Column to give it a fixed width based on the remaining space.
Container(
height: 72,
constraints: BoxConstraints(minWidth: double.infinity),
child: Row(
children: <Widget>[
Container(
margin: const EdgeInsets.only(left: 16.0, right: 16.0),
child: CircleAvatar(
radius: 20.0,
backgroundImage: NetworkImage(_model._organizerLogo),
backgroundColor: Colors.transparent,
),
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.only(right: 8.0),
child: Text(
_model._eventName,
style: TextStyle(
fontSize: 15,
color: Colors.black,
fontWeight: FontWeight.w500),
textAlign: TextAlign.start,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
...
])
),
],
),
)
Here is the working solution:
Container(
height: 72,
constraints: BoxConstraints(minWidth: double.infinity),
child: Row(
children: <Widget>[
Container(
margin: const EdgeInsets.only(left: 16.0, right: 16.0),
child: CircleAvatar(
radius: 20.0,
backgroundImage: NetworkImage(poolImageUrl),
backgroundColor: Colors.transparent,
),
),
Expanded(
child: Container(
padding: EdgeInsets.only(right: 8.0),
child: Text(
"This will not overflow now, because we have put it in Expanded, you can try any long string here for test",
style: TextStyle(fontSize: 15, color: Colors.black, fontWeight: FontWeight.w500),
textAlign: TextAlign.start,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
],
),
),