Column widget not positioning widgets properly when using Stack widget-Flutter - flutter

The first image is the design of the app from Figma. While the next image is the one which I am getting though I am using simple stack and columns. I am not being able to understand why it is coming out as such. The Text Widgets must be under the picture but they are going right at the bottom of the screen. Can anyone help me out with this one?
My code:
import 'package:flutter/material.dart';
import '../../app_theme.dart';
class ProfileScreen extends StatefulWidget {
const ProfileScreen({Key? key}) : super(key: key);
#override
_ProfileScreenState createState() => _ProfileScreenState();
}
class _ProfileScreenState extends State<ProfileScreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: AppTheme.lightBlue,
title: Text(
'Profile',
style: TextStyle(color: AppTheme.black100),
),
elevation: 0,
),
body: Column(
children: [
SizedBox(
height: 50,
),
Stack(
alignment: Alignment.center,
clipBehavior: Clip.none,
children: [
Container(
width: double.infinity,
height: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(16),
topLeft: Radius.circular(16),
),
color: AppTheme.lightGrey),
),
Positioned(
top: -50,
child: _buildProfileDetails(),
),
],
)
],
),
backgroundColor: AppTheme.lightBlue,
drawer: Drawer(),
);
}
Widget _buildProfileDetails() {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Stack(
clipBehavior: Clip.none,
children: [
CircleAvatar(
radius: 50,
backgroundImage: AssetImage('assets/images/profile_photo.jpg'),
),
Positioned(
left: 78,
top: 60,
child: CircleAvatar(
radius: 14,
backgroundColor: AppTheme.blue,
child: Icon(Icons.camera_alt_outlined),
),
),
],
),
Text(
'Alexis Sanchez',
style: TextStyle(
color: AppTheme.black100,
fontSize: 22,
fontWeight: FontWeight.w600,
fontStyle: FontStyle.normal,
fontFamily: 'Poppins',
height: 33,
),
textAlign: TextAlign.center,
),
Text(
'Alexis Sanchez',
style: TextStyle(
color: AppTheme.black80,
fontSize: 12,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
fontFamily: 'Poppins',
height: 18,
),
textAlign: TextAlign.center,
),
Text(
'Alexis Sanchez',
style: TextStyle(
color: AppTheme.black80,
fontSize: 12,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
fontFamily: 'Poppins',
height: 18,
),
textAlign: TextAlign.center,
),
],
);
}
}

Stack widget extends and fills all the available space. if you want your stack to be smaller than all available space. wrap it inside a SizedBox widget.

If you need to control height, do like height: 1.2. and use mainAxisSize: MainAxisSize.min, on Column.
I am using different approach to gain this and will contain some extra widget for future purpose. Mostly describe on code-comment. If you face any issue while scaling/increasing size, adjust the parent Container size. Used demo color for design purpose.
Run on dartPad.
Result will be:
body: LayoutBuilder(
builder: (context, constraints) {
return Column(
children: [
/// header Part: Name, logo, info
Container(
color: Colors.grey,
height: kToolbarHeight * 3, //adjust box Stack size
child: Stack(
children: [
/// bottom Half background
Align(
alignment: Alignment.bottomCenter,
child: Container(
height: kToolbarHeight * 2,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topRight: Radius.circular(16),
topLeft: Radius.circular(16),
),
),
),
),
/// center logo with info
Positioned(
bottom: 10,
left: 0,
right: 0,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
height: 50 * 2, // from your logo radius
width: 50 * 2 +
7, //7 is from `camera_alt_outlined` to align
child: Stack(
children: const [
CircleAvatar(
radius: 50,
backgroundColor: Colors.deepPurple,
// backgroundImage: AssetImage(
// 'assets/images/profile_photo.jpg'),
),
Positioned(
bottom: 7,
right: 0,
child: CircleAvatar(
radius: 14,
backgroundColor: Colors.blue,
child: Icon(Icons.camera_alt_outlined),
),
)
],
),
),
///now rest of Text
const Text(
'Alexis Sanchez',
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.w600,
fontStyle: FontStyle.normal,
fontFamily: 'Poppins',
height: 1.2),
textAlign: TextAlign.center,
),
const Text(
'Alexis Sanchez',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
fontFamily: 'Poppins',
),
textAlign: TextAlign.center,
),
const Text(
'Alexis Sanchez',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
fontFamily: 'Poppins',
),
textAlign: TextAlign.center,
),
],
),
),
],
),
)
],
);
},
));

I would have put child in this container and put everything that I want on this background
Must use screenutil helps for different screen sizes
Container(
width: double.infinity,
height: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(16.sp),
topLeft: Radius.circular(16.sp),
),
color: AppTheme.lightGrey),
),

Related

Stack item are not positioned when the screen size changes Flutter

1-I am making a simple app where I am creating Profile section Where there is Stack at the top with two widgets
but the problem is when ever I test the app on different screen sizes the Stack item widgets are not at same position even i tried with MediaQuery
2-And the Second issue is I want the Circle Avatar to be place Half inside the Container And Half Out-side the Container.
Here is my Profile.dart class
class SettingsScreen extends StatelessWidget {
const SettingsScreen({super.key});
#override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Stack(
children: <Widget>[
Container(
// height: mediaQueryData.size.height * 0.4,
height: 300,
width: double.infinity,
decoration: const BoxDecoration(
gradient: LinearGradient(colors: [
Colors.black,
Color.fromRGBO(255, 243, 18, 3),
], begin: Alignment.topLeft, end: Alignment.bottomRight),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(50),
bottomRight: Radius.circular(50))),
),
const Padding(
padding: EdgeInsets.only(top: 240, left: 140),
child: CircleAvatar(
backgroundColor: Color.fromARGB(183, 40, 46, 3),
radius: 50,
child: Text(
"M-E",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 32),
),
),
),
Positioned(
top: 110,
left: 40,
child: Text(
"مثابة ايلاف",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 70),
),
),
//),
],
),
Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 0),
child: ListTile(
trailing: const Icon(
Icons.cast_for_education,
color: Colors.black,
),
title: const Text(
"Subjects (مضامین)",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 18),
),
onTap: () {},
),
),
const Divider(
color: Colors.black,
thickness: 0.5,
),
Padding(
padding: const EdgeInsets.only(top: 2),
child: ListTile(
trailing: const Icon(
Icons.contacts,
color: Colors.black,
),
title: const Text(
"Contact (رابطہ )",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 18),
),
onTap: () {},
),
),
const Divider(
color: Colors.black,
thickness: 0.5,
),
Padding(
padding: const EdgeInsets.only(top: 2),
child: ListTile(
trailing: const Icon(
Icons.settings,
color: Colors.black,
),
title: const Text(
"Setting (ترتیبات)",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 18),
),
onTap: () {},
),
),
const Divider(
color: Colors.black,
thickness: 0.5,
),
Padding(
padding: const EdgeInsets.only(top: 2),
child: ListTile(
trailing: const Icon(
Icons.logout,
color: Colors.black,
),
title: const Text(
"Logout (لاگ آوٹ)",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 18),
),
onTap: () {},
),
),
],
),
],
),
));
}
}
Here is the const result I want when the app run on different devices
Here is the result I don't want to be happens whenever the device size changes
Use this structure.
Positioned(
top: 110,
left: 1,
right:1
child: Text(
"مثابة ايلاف",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 70),
),
),

Flutter App Screen is appearing weird on Samsung S8

Image is here
Flutter app screen and text is appearing weird in Samsung S8 mobile
but tested in Other Samsung devises and its working fine, you can see how its supposed to work on the other devices on the above image
any one know why is this screen issue is happening only on samsung s8 ,only this image is here no log is getting so it is hard to resolve , is anyone faced this issue before,
minimumSdk is 21
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
import 'package:splink/src/constants/app_colors.dart';
import 'package:splink/src/controllers/login_view_controllers.dart';
import 'package:splink/src/view/login_view/login_welcome_view.dart';
import 'package:splink/src/view/signup_view/signup_welcome_view.dart';
class LandingView extends StatefulWidget {
const LandingView({Key? key}) : super(key: key);
#override
State<LandingView> createState() => _LandingViewState();
}
class _LandingViewState extends State<LandingView> {
final signLoginController = Get.find<LoginViewController>();
final controller = PageController(
viewportFraction: 1,
keepPage: true,
);
List items = [
"assets/images/6D2Lmtv_X8A.png",
"assets/images/secondimage.png",
"assets/images/thirdImage.png"
];
List textItems = [
//first page of intro
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: const [
Text(
"Find and play sports at",
style: TextStyle(
fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold),
),
Text(
"anywhere, anytime",
style: TextStyle(
fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold),
),
SizedBox(
height: 25,
),
Text(
"splink helps you find, connect and organise activities",
style: TextStyle(
color: Colors.white,
),
),
Text(
"with other sports players easily at anywhere, anytime",
style: TextStyle(
color: Colors.white,
),
),
],
),
//second page of intro
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: const [
Text(
"Organise and manage",
style: TextStyle(
fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold),
),
Text(
"activties easily",
style: TextStyle(
fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold),
),
SizedBox(
height: 25,
),
Text(
"no more messy groups and missed activities.",
style: TextStyle(
color: Colors.white,
),
),
Text(
"Activity creation and RSVPs, calendar-tracking",
style: TextStyle(
color: Colors.white,
),
),
Text(
"or notifications, everything doe easily in-app",
style: TextStyle(
color: Colors.white,
),
),
],
),
//third page of intro
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: const [
Text(
"Meet, play and endorse",
style: TextStyle(
fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold),
),
Text(
"one another",
style: TextStyle(
fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold),
),
SizedBox(
height: 25,
),
Text(
"Have fun, encourage one another by exchanging medals,",
style: TextStyle(
color: Colors.white,
),
),
Text(
"track sports statistics and keep on playing!",
style: TextStyle(
color: Colors.white,
),
),
],
),
];
#override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
final pages = List.generate(
3,
(index) => Image.asset(
items[index],
fit: BoxFit.cover,
),
);
final pages2 = List.generate(3, (index) => textItems[index]);
return Scaffold(
backgroundColor: primaryColor,
body: Column(
children: [
Expanded(
child: ClipPath(
clipper: ClipPathClass(),
child: PageView.builder(
controller: controller,
padEnds: false,
// itemCount: pages.length,
itemBuilder: (_, index) {
return SizedBox(
height: size.height,
width: size.width,
child: pages[index % pages.length]);
},
onPageChanged: (value) {
signLoginController.curouselIndex(value % pages.length);
},
),
),
),
Expanded(
child: Container(
color: primaryColor,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
child: SmoothPageIndicator(
controller: controller,
count: 3,
effect: const ExpandingDotsEffect(
strokeWidth: 2.0,
dotColor: Colors.white,
activeDotColor: Colors.white,
dotHeight: 6,
dotWidth: 6,
),
),
),
const SizedBox(
height: 15,
),
Obx(
() => textItems[signLoginController.curouselIndex.value],
),
const SizedBox(
height: 70,
),
Padding(
padding: const EdgeInsets.only(right: 15, left: 15),
child: Material(
color: Colors.white,
borderRadius: BorderRadius.circular(15),
child: InkWell(
onTap: () {
Get.to(SignupWelcomeView());
},
borderRadius: BorderRadius.circular(15),
child: Container(
width: size.width,
height: 50,
alignment: Alignment.center,
child: Text(
'Sign Up',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
color: primaryColor),
),
),
),
),
),
const SizedBox(
height: 20,
),
Padding(
padding: const EdgeInsets.only(right: 15, left: 15),
child: InkWell(
onTap: () {
Get.to(LoginWelcomeView());
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
border: Border.all(color: Colors.white),
),
width: size.width,
height: 50,
alignment: Alignment.center,
child: const Text(
'Login',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
color: Colors.white),
),
),
),
),
],
),
),
)
],
),
);
}
}
class ClipPathClass extends CustomClipper<Path> {
#override
Path getClip(Size size) {
Path path = Path();
path.addOval(Rect.fromCircle(
center: Offset(size.width * 0.5, -10),
radius: size.height - 20,
));
return path;
}
#override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
I mean, the "issue" is that the width/pixel density of the device is causing the text to overflow to the next line. You can either use a FittedBox, or tweak the fontSize to optimize it depending on the width (using MediaQuery or LayoutBuilder), both sould work.
You can also align the text on the center, instead of to the right, and I'd add some padding to ensure the text doesn't go right up to the screen border.
How do I auto scale down a font in a Text widget to fit the max number of lines?

The named parameter 'fontSize' isn't defined. in flutter code

want to add 5 box containers display xs, s, m, l, xl sizes. but the code throwing errors. where should I correct this? please refer to the image here. I add a container to create those. I'm new to flutter and can anyone please help how can I fix this.
error >> The named parameter 'fontSize' isn't defined. in flutter code
error>> The named parameter 'fontWeight' isn't defined.
import 'package:flutter/material.dart';
class DetailsScreen extends StatelessWidget {
const DetailsScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: Colors.pinkAccent,
),
body: Column(
children: <Widget>[
Expanded(
child: Container(height: MediaQuery.of(context).size.height*.8,
padding: EdgeInsets.all(10.0),
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/image23.png"),
//fit: BoxFit.fitHeight,
),
),
),
),
Stack(
alignment: Alignment.bottomRight,
children: <Widget>[
// Max Size
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: Colors.red.shade50,
),
alignment: const Alignment (1,1),
height: 400,
width: 350,
child: Column(
children: const [
Padding(
padding: const EdgeInsets.fromLTRB(10, 40, 100, 40),
child: Text(
"Summer Collections",
style: TextStyle(
fontSize: 24,
color: Color(0xff262626),
fontWeight: FontWeight.w700),
textAlign: TextAlign.left,
),
),
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 270, 100),
child: Text(
"Sizes",
style: TextStyle(
fontSize: 12,
color: Color(0xff262626),
fontWeight: FontWeight.w700),
textAlign: TextAlign.left,
),
),
],
),
)
Container(
child: Row(
children: [
Container(
height:49, width: 49,
decoration: BoxDecoration(
color: Color.fromRGBO(228, 228, 228, 1),
borderRadius: BorderRadius.circular(10)
),
child:const Center(
child:Text("xs",
fontSize:20,
fontWeight:FontWeight.bold
),
),
)
],
)),
Padding(
padding: const EdgeInsets.fromLTRB(230, 110, 0, 40),
child: ElevatedButton(
onPressed: () {},
child: const Text(
"Add to Cart ",
),
style: ElevatedButton.styleFrom(
primary: Colors.black,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
bottomRight: Radius.circular(20))),
padding: const EdgeInsets.all(15)),
),
),
]
),
],
),
);
}
}
This is the correct way to use TextStyle. reference.
Text(
'text',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold),
),
You should use TextStyle :
Text(
"your text here" ,
style: TextStyle(
fontsize: ,
fontWeight:
),
)
You need TextStyle to change fontSize, color, fontWeight etc.
child: Text("xs", style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold
),
),
You have wrote a wrong code,Try below code hope its helpful to you.
Refer Text Class here
Refer TextStyle here
Center(
child: Text(
"xs",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
Your Reslt Screen->
Put the text styles in a TextStyle widget.
The problem here is pretty simple. The text widget does not have any attribute fontSize or font weight. Instead, it is the TextStyle widge.
This is how it works
const Center(
child: Text("xs",
style: TextStyle(
fontSize: 22,
fontWeight: FontWight.bold
)
)
This is the props of textStyle of Text widget, So first you have to give textstyle of Text widget, then set this.
Text(
"Helo world",
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.normal,
)),
used this:-
Center(
child: Text(
"xs",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),

Add image to listview from Gallery in Flutter/dart

This is currently what I have achived,
#override
Widget build(BuildContext context) {
_height = MediaQuery.of(context).size.height;
return Scaffold([![enter image description here][1]][1]
resizeToAvoidBottomInset: false,
extendBodyBehindAppBar: true,
appBar: AppBar(
leading: GestureDetector(
child: Image.asset('graphics/back_arrow.png'),
onTap: () {
Get.back();
},
),
backgroundColor: Colors.transparent,
elevation: 0,
title: Text(
'Ask The Internet',
style: GoogleFonts.montserrat(
fontSize: 20,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.bold,
color: Colors.white),
),
),
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("graphics/login.png"),
fit: BoxFit.cover,
),
),
child: Column(
children: [
Container(
width: double.infinity,
height: _height * 0.15,
),
Container(
padding:
EdgeInsets.only(top: 64, left: 16, right: 16, bottom: 16),
height: _height * 0.85,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(64),
topRight: Radius.circular(64),
),
),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Align(
alignment: Alignment.center,
child: Text(
'Ask The Internet',
style: GoogleFonts.montserrat(
fontSize: 16,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.w600,
color: loginPageTitleColor),
),
),
SizedBox(
height: _height * 0.04,
),
Text(
'Upload Content for UP',
style: GoogleFonts.montserrat(
fontSize: 14,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
color: askInternetPageTitleColor),
),
SizedBox(
height: _height * 0.01,
),
Row(
children: [
GestureDetector(
child: Image.asset('graphics/add.png'),
onTap: () {
_pickImages();
},
),
],
),
Align(
alignment: Alignment.center,
child: Image.asset('graphics/divider.png')),
SizedBox(
height: _height * 0.04,
),
Text(
'Upload Content for DOWN',
style: GoogleFonts.montserrat(
fontSize: 14,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
color: askInternetPageTitleColor),
),
SizedBox(
height: _height * 0.01,
),
Image.asset('graphics/add.png'),
Align(
alignment: Alignment.center,
child: Image.asset('graphics/divider.png')),
SizedBox(
height: _height * 0.06,
),
TextFieldInput(
titleText: 'Text up to 140 characters',
hintText: 'Enter Question',
inputType: TextInputType.visiblePassword,
textEditingController: controller.questionController,
titleTextStyle: GoogleFonts.montserrat(
fontSize: 15,
fontWeight: FontWeight.normal,
color: editProfivePageTitleColor),
),
SizedBox(
height: _height * 0.04,
),
Align(
alignment: Alignment.center,
child: Text(
'Ask The Community',
style: GoogleFonts.montserrat(
fontSize: 16,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.w600,
color: loginPageTitleColor),
),
),
SizedBox(
height: _height * 0.04,
),
Text(
'Select The Community',
style: TextStyle(fontSize: 20, color: Colors.black38),
),
Obx(
() => DropdownButton<CommunityItem>(
isExpanded: true,
value: controller.item.value,
items:
controller.communityRows.map((CommunityItem value) {
return DropdownMenuItem<CommunityItem>(
value: value,
child: Text(value!.name!),
);
}).toList(),
onChanged: (value) {
controller.item.value = value!;
},
),
),
SizedBox(
height: _height * 0.04,
),
GestureDetector(
child: Container(
width: double.maxFinite,
height: 55,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(4.0),
),
color: Colors.black,
image: DecorationImage(
image: AssetImage("graphics/btn.png"),
fit: BoxFit.cover),
),
child: Center(
child: Text(
"Save",
style: GoogleFonts.montserrat(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.white),
),
) // button text
),
onTap: () {
print("you clicked me");
},
),
],
),
),
),
],
),
),
);
}
I want when user click on plus icon he can add images from gallery, just like this.
I tried to use Listview builder but it was not prefect.

Flutter widget second row consume remaining space

I am fairly new to flutter, many things I don't understand yet. I have tried many things and I can't get what I want yet. Any suggestions would be helpful.
Widget build(BuildContext context) {
return Column(children: [
Expanded(
child: Container(
// make the full container the amber color
color: Colors.amber[600],
child: Column(children: [
Row(children: [
Expanded(
child: Text(
windowName,
style: TextStyle(
backgroundColor: Colors.blueGrey[200],
fontSize: 24,
fontWeight: FontWeight.bold),
),
),
IconButton(
onPressed: onCurrentDelete,
icon: Icon(Icons.delete_outline, size: 32)),
]),
//IntrinsicHeight(
// child:
Row(
//crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Container(
// make the left container blue
color: Colors.blue[600],
//constraints: BoxConstraints.expand(),
//decoration: BoxDecoration(
// border: Border.all(
// width: 2,
//)),
child: Text(
startTime,
style: TextStyle(
backgroundColor: Colors.blueGrey[200],
fontSize: 16,
fontWeight: FontWeight.normal),
)),
),
Expanded(
child: Container(
// make the right container green
color: Colors.green[600],
//decoration: BoxDecoration(
// border: Border.all(
// width: 2,
//)),
child: Text(
endTime,
style: TextStyle(
backgroundColor: Colors.blueGrey[200],
fontSize: 16,
fontWeight: FontWeight.normal),
)),
)
],
),
//),
]),
),
)
]);
What I want is the two containers in the last row to take up the remaining space. I have used color attribute to show the size of specific widgets.
The blue and green containers need to fill the to the bottom of the amber section.
I have tried many alternatives and each time the widget generates a fault when it is rendered.
I hope this is what you are looking for:
Image
Code:
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Column(children: [
Expanded(
child: Container(
// make the full container the amber color
color: Colors.amber[600],
child: Column(children: [
Row(children: [
Expanded(
child: Text(
"windowName",
style: TextStyle(
backgroundColor: Colors.blueGrey[200],
fontSize: 24,
fontWeight: FontWeight.bold),
),
),
IconButton(
onPressed: () {},
icon: Icon(Icons.delete_outline, size: 32)),
]),
//IntrinsicHeight(
// child:
Row(
//crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
// make the left container blue
color: Colors.blue[600],
//constraints: BoxConstraints.expand(),
//decoration: BoxDecoration(
// border: Border.all(
// width: 2,
//)),
child: Text(
"startTime",
style: TextStyle(
backgroundColor: Colors.blueGrey[200],
fontSize: 16,
fontWeight: FontWeight.normal),
)),
SizedBox(
width: MediaQuery.of(context).size.width * 0.4,
),
Container(
// make the right container green
color: Colors.green[600],
//decoration: BoxDecoration(
// border: Border.all(
// width: 2,
//)),
child: Text(
"endTime",
style: TextStyle(
backgroundColor: Colors.blueGrey[200],
fontSize: 16,
fontWeight: FontWeight.normal),
))
],
),
//),
]),
),
)
]),
),
);
}
I added height (300) to green and blue containers. and it works fine.
code:
Column(children: [
Expanded(
child: Container(
// make the full container the amber color
color: Colors.amber[600],
child: Column(mainAxisSize: MainAxisSize.max, children: [
Row(children: [
Expanded(
child: Text(
'windowName',
style: TextStyle(
backgroundColor: Colors.blueGrey[200],
fontSize: 24,
fontWeight: FontWeight.bold),
),
),
IconButton(
onPressed: () {}, icon: Icon(Icons.delete_outline, size: 32)),
]),
//IntrinsicHeight(
// child:
Row(
//crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Container(
height: 300,
// make the left container blue
color: Colors.blue[600],
//constraints: BoxConstraints.expand(),
//decoration: BoxDecoration(
// border: Border.all(
// width: 2,
//)),
child: Text(
'startTime',
style: TextStyle(
backgroundColor: Colors.blueGrey[200],
fontSize: 16,
fontWeight: FontWeight.normal),
)),
),
Expanded(
child: Container(
height: 300,
// make the right container green
color: Colors.green[600],
//decoration: BoxDecoration(
// border: Border.all(
// width: 2,
//)),
child: Text(
'endTime',
style: TextStyle(
backgroundColor: Colors.blueGrey[200],
fontSize: 16,
fontWeight: FontWeight.normal),
)),
)
],
),
//),
]),
),
)
])