[flutter]Why my column alignment is always center? - flutter

I declared two columns in a row to layout the text and the icon.
The column for the icon is always center even if I set the mainAxisAlignment with MainAxisAlignment.start.
Here is the code for the card:
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:life_logger/models.dart';
import 'package:life_logger/screens/entry_editor_screen.dart';
import 'package:life_logger/widgets/dot.dart';
Wrap buildActivities(Entry entry) {
var children = <Widget>[];
var idx = 0;
entry.activities.forEach((activity) {
var element = Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
Icon(
activity.iconData,
color: entry.mood.color,
),
SizedBox(
width: 3,
),
Text(
'${activity.description}',
style: TextStyle(color: Colors.grey),
),
]);
children.add(element);
if (idx < entry.activities.length - 1) {
children.add(Dot());
}
idx++;
});
return Wrap(
children: children,
spacing: 5,
crossAxisAlignment: WrapCrossAlignment.center,
);
}
Widget buildEntryRow(Entry entry, BuildContext context) {
var entryRow = GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => EntryEditorScreen(entry)),
);
},
child: Row(
children: <Widget>[
// the column for the icon
Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 8.0, right: 8.0),
child: Icon(
entry.mood.iconData,
color: entry.mood.color,
size: 48,
),
),
],
),
Expanded(
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Baseline(
baseline: 30.0,
baselineType: TextBaseline.alphabetic,
child: Text(
entry.mood.description,
style: TextStyle(
color: entry.mood.color,
fontSize: 24,
),
),
),
Baseline(
baseline: 30.0,
baselineType: TextBaseline.alphabetic,
child: Text(
DateFormat.Hm().format(entry.createdAt),
style: TextStyle(
color: Colors.grey,
fontSize: 16,
),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(child: buildActivities(entry)),
],
),
Row(
children: <Widget>[
Text(
entry.note,
style: TextStyle(
color: Colors.grey,
fontSize: 16,
),
),
],
),
],
),
),
],
));
return entryRow;
}
class EntryCard extends StatefulWidget {
final List<Entry> entries;
EntryCard(this.entries);
#override
_EntryCardState createState() => _EntryCardState();
}
class _EntryCardState extends State<EntryCard> {
#override
Widget build(BuildContext context) {
var dateRow = Container(
height: 30,
decoration: BoxDecoration(
color: widget.entries[0].mood.color.withOpacity(0.5),
borderRadius: BorderRadius.all(Radius.circular(4.0)),
),
child: Row(
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 24.5, right: 24.5),
child: Ring(
size: 5.0,
color: widget.entries[0].mood.color,
),
),
Text(
DateFormat('EEEEE, M月d日').format(widget.entries[0].createdAt),
style: TextStyle(
color: widget.entries[0].mood.color,
fontSize: 14,
),
)
],
));
return Card(
child: Column(
children: <Widget>[dateRow] +
widget.entries.map((entry) => buildEntryRow(entry, context)).toList(),
));
}
}
The actual layout as follow:

Use crossAxisAlignment: CrossAxisAlignment.start
And for future, I would suggest you to add code that is independent of other code so that others can run it and see.

like that for one widget
Container(
child: Align(
alignment: Alignment.centerRight,
child: Text(S.current.forgetPassword),
),
),
or for all
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,

If you want you can adjust column according to you .
Here is code of how to call widgets of columns at start.
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,

Use it :
Column(
children: const <Widget>[
Align(
alignment: Alignment.centerLeft,
child: Text('Text 1')
),
Align(
alignment: Alignment.centerLeft,
child: Text('Text 2')
),
],
)

Setting the height of the Container worked for me:
height: double.infinity,

Related

Centring a Column inside another Column in Flutter

I'm currently writing my first Flutter App and I got a little stuck here. Basically what I'm trying to do is display an image at the top of the screen (with 100px top-margin) and display a Column which contains some Text and a Button on the centre of the screen. I tried moving mainAxisAlignment crossAxisAlignment into the outer Column Widget but that centres everything.
Here's my code:
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Column(
children: [
Opacity(
opacity: 0.25,
child: Container(
child: Image.asset('assets/images/logo.png'),
margin: EdgeInsets.only(top: 100),
width: 75,
),
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('Please enter your first name:'),
TextButton(onPressed: () {}, child: Text('Submit'))
],
)
],
),
),
);
You actually only need to wrap the second column in an Expanded widget, "so that the child fills the available space", that's all:
Column(
children: [
Expanded(
child: Column(
children: [],
),
)],
),
try, wrap your second Column inside a Center widget.
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Column(
children: [
Opacity(
opacity: 0.25,
child: Container(
child: Image.asset('assets/images/logo.png'),
margin: EdgeInsets.only(top: 100),
width: 75,
),
),
Center(
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('Please enter your first name:'),
TextButton(onPressed: () {}, child: Text('Submit'))
],
)
],
),
),
),
);
If this doesn't work you could also wrap it in an Align widget and add the alignment property to it.
Align(
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('Please enter your first name:'),
TextButton(onPressed: () {}, child: Text('Submit'))
],
),
),
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Scaffold(
appBar: AppBar(),
body: Container(
height: double.infinity,
width: double.infinity,
color: Colors.blue,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
height: 200,
width: 200,
color: Colors.pink,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
),
),
],
),
),
),
),
);
}
you have to use mainAxisAlignment property to set MainAxisAlignment.center.
In order to center align your second column,
Make sure MainAxisAlignment of your Second Column is MainAxisAlignment.center
Wrap your second column inside a Align Widget
Now, wrap your Align widget with Expanded widget.
This should solve your issue.
Check this refrence.
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 18.0,
),
const Padding(
padding: EdgeInsets.only(left: 16.0),
child: Text(
'Recent Search(s)',
style: TextStyle(
color: Colors.black,
fontSize: 16.0,
fontWeight: FontWeight.bold),
),
),
Expanded(
child: Align(
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
MdiIcons.magnify,
color: Colors.grey.shade600,
size: 72.0,
),
const SizedBox(
height: 8.0,
),
Text(
'Search for places',
style: TextStyle(
fontSize: 14.0,
color: Colors.grey.shade600,
fontWeight: FontWeight.w600),
),
Text(
'You haven\'t serached for any items yet...',
style: TextStyle(
fontSize: 12.0,
color: Colors.grey.shade700,
fontWeight: FontWeight.w500),
),
Text(
'Try now - we will help you!',
style: TextStyle(
fontSize: 12.0,
color: Colors.grey.shade700,
fontWeight: FontWeight.w500),
)
],
),
),
)
],

How to disable Slide Icon on last page in Flutter Liquid Swipe?

Is there any way to disable the slide icon when you reach last page of Liquid Swipe while not looping?
enableSlideIcon: false, //disables slide icon on all pages
I want to hide it from last page only.
You can copy paste run full code below
Step 1: You can use bool slideIcon to control
Step 2: In pageChangeCallback, compare pages.length with lpage then do setState
code snippet
bool slideIcon = true;
...
LiquidSwipe(
enableSlideIcon: slideIcon,
...
pageChangeCallback(int lpage) {
setState(() {
if (lpage == pages.length - 1) {
slideIcon = false;
} else {
slideIcon = true;
}
page = lpage;
});
}
working demo
full code
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:liquid_swipe/liquid_swipe.dart';
void main() {
runApp(
MyApp(),
);
}
class MyApp extends StatefulWidget {
static final style = TextStyle(
fontSize: 30,
fontFamily: "Billy",
fontWeight: FontWeight.w600,
);
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
int page = 0;
LiquidController liquidController;
UpdateType updateType;
bool slideIcon = true;
#override
void initState() {
liquidController = LiquidController();
super.initState();
}
final pages = [
Container(
color: Colors.pink,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover,
),
Padding(
padding: EdgeInsets.all(20.0),
),
Column(
children: <Widget>[
Text(
"Hi",
style: MyApp.style,
),
Text(
"It's Me",
style: MyApp.style,
),
Text(
"Sahdeep",
style: MyApp.style,
),
],
),
],
),
),
Container(
color: Colors.deepPurpleAccent,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Image.network(
'https://picsum.photos/250?image=10',
fit: BoxFit.cover,
),
Padding(
padding: EdgeInsets.all(20.0),
),
Column(
children: <Widget>[
Text(
"Take a",
style: MyApp.style,
),
Text(
"look at",
style: MyApp.style,
),
Text(
"Liquid Swipe",
style: MyApp.style,
),
],
),
],
),
),
Container(
color: Colors.greenAccent,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Image.network(
'https://picsum.photos/250?image=11',
fit: BoxFit.cover,
),
Padding(
padding: EdgeInsets.all(20.0),
),
Column(
children: <Widget>[
Text(
"Liked?",
style: MyApp.style,
),
Text(
"Fork!",
style: MyApp.style,
),
Text(
"Give Star!",
style: MyApp.style,
),
],
),
],
),
),
Container(
color: Colors.yellowAccent,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Image.network(
'https://picsum.photos/250?image=12',
fit: BoxFit.cover,
),
Padding(
padding: EdgeInsets.all(20.0),
),
Column(
children: <Widget>[
Text(
"Can be",
style: MyApp.style,
),
Text(
"Used for",
style: MyApp.style,
),
Text(
"Onboarding Design",
style: MyApp.style,
),
],
),
],
),
),
Container(
color: Colors.redAccent,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Image.network(
'https://picsum.photos/250?image=13',
fit: BoxFit.cover,
),
Padding(
padding: EdgeInsets.all(20.0),
),
Column(
children: <Widget>[
Text(
"Do",
style: MyApp.style,
),
Text(
"Try it",
style: MyApp.style,
),
Text(
"Thank You",
style: MyApp.style,
),
],
),
],
),
),
];
Widget _buildDot(int index) {
double selectedness = Curves.easeOut.transform(
max(
0.0,
1.0 - ((page ?? 0) - index).abs(),
),
);
double zoom = 1.0 + (2.0 - 1.0) * selectedness;
return Container(
width: 25.0,
child: Center(
child: Material(
color: Colors.white,
type: MaterialType.circle,
child: Container(
width: 8.0 * zoom,
height: 8.0 * zoom,
),
),
),
);
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Stack(
children: <Widget>[
LiquidSwipe(
enableSlideIcon: slideIcon,
pages: pages,
onPageChangeCallback: pageChangeCallback,
waveType: WaveType.liquidReveal,
liquidController: liquidController,
ignoreUserGestureWhileAnimating: true,
),
Padding(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
Expanded(child: SizedBox()),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List<Widget>.generate(pages.length, _buildDot),
),
],
),
),
Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.all(25.0),
child: FlatButton(
onPressed: () {
liquidController.animateToPage(
page: pages.length - 1, duration: 500);
},
child: Text("Skip to End"),
color: Colors.white.withOpacity(0.01),
),
),
),
Align(
alignment: Alignment.bottomLeft,
child: Padding(
padding: const EdgeInsets.all(25.0),
child: FlatButton(
onPressed: () {
liquidController.jumpToPage(
page: liquidController.currentPage + 1);
},
child: Text("Next"),
color: Colors.white.withOpacity(0.01),
),
),
)
],
),
),
);
}
pageChangeCallback(int lpage) {
setState(() {
if (lpage == pages.length - 1) {
slideIcon = false;
} else {
slideIcon = true;
}
page = lpage;
});
}
}

How to draw vertical connector lines between icons in Flutter?

I have 3 ListTile widgets as shown below and I want to add vertical connection lines between icons but not sure how to do that. Can anyone help please? Thanks.
[Icon] Order received
| 2020-05-28 10:00 AM
|
|
[Icon] On the way
| 2020-05-29 10:00 AM
|
|
[Icon] Delivered
2020--05-29 11:00 AM
Edit: source code is provided below. As described above I need to draw a line between icons of the ListTile widgets. Tried VerticalDivider but there is still a big gap between ListTile widgets.
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:home_chefs/common_widgets/text_widget.dart';
import 'package:home_chefs/constants/color_palette.dart';
import 'package:home_chefs/constants/font_enum.dart';
import 'package:home_chefs/constants/form_styleguides.dart';
class OrderStatusWidget extends StatefulWidget {
#override
_OrderStatusWidgetState createState() => _OrderStatusWidgetState();
}
class _OrderStatusWidgetState extends State<OrderStatusWidget> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: ColorPalette.white,
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 30.0, bottom: 30.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
TextWidget(
text: 'Order status',
fontFamily: FontFamily.BalooRegular.toShortString(),
fontSize: FormStyleGuides.textSizeMedium,
),
TextWidget(
text: 'Invoice: 12828',
fontFamily: FontFamily.BalooRegular.toShortString(),
fontSize: FormStyleGuides.textSizeMedium,
),
Container(
height: 100.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8.0)),
image: DecorationImage(
fit: BoxFit.contain,
image: AssetImage(
'assets/images/trending/pho_ha_noi.jpg',
))))
],
),
),
Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
ListTile(
leading: FaIcon(
FontAwesomeIcons.book,
color: ColorPalette.persimmon,
),
title: Text('Order received'),
subtitle: Text('30/05/2020 10.00 AM'),
//contentPadding: EdgeInsets.only(left: 20.0, bottom: 30.0),
),
ListTile(
leading: FaIcon(
FontAwesomeIcons.truck,
color: ColorPalette.persimmon,
),
title: Text('On the way'),
subtitle: Text('30/05/2020 10.00 AM'),
//contentPadding: EdgeInsets.only(left: 20.0, bottom: 30.0),
),
ListTile(
leading: FaIcon(
FontAwesomeIcons.solidFlag,
color: ColorPalette.persimmon,
),
title: Text('Delivered'),
subtitle: Text('30/05/2020 11.00 AM'),
//contentPadding: EdgeInsets.only(left: 20.0, bottom: 30.0),
),
],
),
),
Container(
width: 100.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
FormStyleGuides.buttonBorderRadius),
side: BorderSide(color: ColorPalette.persimmon)),
color: ColorPalette.persimmon,
highlightColor: ColorPalette.persimmon,
onPressed: () {},
padding: EdgeInsets.fromLTRB(
FormStyleGuides.buttonPaddingLeft,
FormStyleGuides.buttonPaddingTop,
FormStyleGuides.buttonPaddingRight,
FormStyleGuides.buttonPaddingBottom),
child: TextWidget(
text: 'Confirm delivery',
color: ColorPalette.white,
fontSize: FormStyleGuides.textFormFieldLabelSize,
),
),
],
),
)
],
),
);
}
}
If I understood your question correctly, you are looking for something like this:
class IconLines62088774 extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
ItemContainer(),
ItemContainer(),
ItemContainer(),
],
);
}
}
class ItemContainer extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
color: Colors.blue,
height: 20,
width: 1,
),
Icon(Icons.message, color: Colors.grey,),
Container(
color: Colors.blue,
height: 20,
width: 1,
),
],
),
Expanded(
child: Padding(
padding: EdgeInsets.all(8),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('On the way'),
Text('01-07-2020'),
],
),
),
),
],
),
);
}
}

how to set the size of rows and columns as their parent widget in flutter?

Using a Column in a Row which is a child of a Card widget, how do I set the Column width as large as the row widget?
return Card(
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(4.0),
child: Container(
width: 100.0,
height: 100.0,
// container for image
color: Colors.grey,
),
),
Column(
//crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Item Name',
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
Text(
'Previous Price',
style: TextStyle(fontSize: 15.0, color: Colors.grey),
),
Row(
children: <Widget>[
RaisedButton(
textColor: Colors.white,
child: Text('Add'),
),
Icon(Icons.add),
Container(
width: 50.0,
height: 50.0,
child: Text('12'),
color: Colors.red[200],
),
Icon(Icons.remove),
],
),
],
),
],
),
)
import 'package:flutter/material.dart';
main() => runApp(MyApp());
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Container(
child: Card(
child: Row(
children: [
Padding(
padding: const EdgeInsets.all(4.0),
child: Container(
width: 100.0, height: 100.0,
// container for image
color: Colors.grey,
),
),
Container(
color: Colors.red,
child: Column(
mainAxisSize: MainAxisSize.min,
//crossAxisAlignment: CrossAxisAlignment.stretch,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Item Name',
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
Text(
'Previous Price',
style: TextStyle(fontSize: 15.0, color: Colors.grey),
),
Container(
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
RaisedButton(
textColor: Colors.white,
child: Text('Add'),
onPressed: () {},
),
Icon(Icons.add),
Padding(
padding: const EdgeInsets.all(5.0),
child: Container(
width: 50.0,
height: 50.0,
child: Center(child: Text('12')),
color: Colors.red[200],
),
),
Icon(Icons.remove),
],
),
),
],
),
),
],
),
),
),
)));
}
}
let me know if this works maybe I am correct, but still, the description is about confusing. looking at your code I made the prediction.
Thanks.
I'm a little confused by your description,
but crossAxisAlignment: CrossAxisAlignment.stretch might be the answer to the title.
Try using,
Expanded(
child:Container(
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
RaisedButton(
textColor: Colors.white,
child: Text('Add'),
onPressed: () {},
),
Icon(Icons.add),
Padding(
padding: const EdgeInsets.all(5.0),
child: Container(
width: 50.0,
height: 50.0,
child: Center(child: Text('12')),
color: Colors.red[200],
),
),
Icon(Icons.remove),
],
),
),
)

Flutter Card Color

I want to make this card which i have divided into columns (Expanded widget), The problem i am facing is : i am unable to set color container (parent of right column) to full height, so only part of it shows colored background.
What I Have:
What I Want:
I tried Flutter Inspector tool and noticed that Container and its child Column are not getting full height (Even after typing mainAxisSize: MainAxisSize.max)
Instead of Using Expanded i also tried using FractionSized.. but not luck.
Code :
import 'package:flutter/material.dart';
class SubjectPage extends StatelessWidget {
final String dayStr;
SubjectPage(this.dayStr);
#override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.fromLTRB(20.0, 40.0, 20.0, 0),
child: Column(
children: <Widget>[
Card(
child: Row(
children: <Widget>[
// Column 1
Expanded(
flex: 7,
child: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
getTitle("UEC607"),
getSubName("Data Communication & Protocol"),
getVenue("E-204"),
],
),
),
),
// Column 2
// The Place where I am Stuck//
Expanded(
flex: 3,
child: Container(
color: Colors.blue,
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
getType("L"),
getTime("9:00"),
],
),
),
)
// COlumn 2 End
],
),
)
],
),
);
}
// Get Title Widget
Widget getTitle(String title) {
return Padding(
padding: EdgeInsets.only(bottom: 8.0),
child: Text(title),
);
}
// Get Subject Name
Widget getSubName(String subName) {
return Padding(
padding: EdgeInsets.only(bottom: 25.0),
child: Text(subName),
);
}
// Get Venue Name
Widget getVenue(String venue) {
return Padding(
padding: EdgeInsets.only(bottom: 0.0),
child: Text(venue),
);
}
Widget getType(String type) {
return Padding(
padding: EdgeInsets.only(bottom: 10.0),
child: Text(type),
);
}
Color getColor(String type) {
if (type == "L") {
return Color(0xff74B1E9);
}
}
Widget getTime(String time) {
return Text(time);
}
}
Set the container height
Expanded(
flex: 3,
child: Container(
height: double.infinity,
color: Colors.blue,
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
getType("L"),
getTime("9:00"),
],
),
),
)
For me it helps to make sure which Widget should be using a fixed space / size and which should expand to fit a space / size
Then I build the layout of the widget using Column and Row (this makes it easy to prepair and decide where to wrap widgets in a Expanded or Flexible widget)
But here is the short example:
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text('Stackoverflow'),
),
body: Container(
margin: EdgeInsets.all(10),
width: double.infinity,
height: 100,
child: Row(
children: <Widget>[
// Texts
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
// UEC607 & Digital communication text
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(
'UEC607',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.grey
),
),
],
),
SizedBox(
height: 5,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(
'Digital communication',
style: TextStyle(
fontSize: 20,
color: Colors.black
),
),
],
)
],
),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text(
'E-206',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.black
),
),
],
),
)
],
),
),
// Card
Container(
width: 90,
color: Colors.lightBlue.withOpacity(.8),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'L',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.white
),
),
SizedBox(
height: 5,
),
Text(
'09:00',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.white
),
),
],
),
)
],
),
),
);
}
And it will look like this:
Use a FittedBox for wrapping the blue container
Expanded(
flex: 2,
child: FittedBox(
child: Container(
color: Colors.blue,
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
getType("L"),
getTime("9:00"),
],
),
),
),
)
You should put your Row widget inside an IntrinsicHeight widget and set crossAxisAlignment property of your Row equal to CrossAxisAlignment.stretch. It will solve your problem.
IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[]
),
)