A RenderFlex overflowed Flutter - flutter

Trying use Positioned with Stack and Column, getting errors:
"A RenderFlex overflowed by 72 pixels on the bottom."
"A RenderFlex overflowed by 46 pixels on the bottom." etc...
Part of my block just disappears into the slider, i tried to use only Stacked and several Positioned pressed to the bottom of the picture, but then part of the picture is closed.
My dart:
final List<Widget> imageSliders = imgList.map((item) => Container(
child: Container(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(30.0)),
child: Stack(
children: <Widget>[
Container(
alignment: Alignment.bottomCenter,
decoration: BoxDecoration(color: Colors.white),
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Image.asset('assets/psplus-1month.png', fit: BoxFit.cover, width: 1000.0),
Container(
decoration: BoxDecoration(color: Colors.white),
padding: EdgeInsets.only(top: 20.0),
child: Text(
'Playstation Plus',
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xFF4F4F4F),
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
Container(
decoration: BoxDecoration(color: Colors.white),
padding: EdgeInsets.only(bottom: 5.0, top:5.0),
child: Text(
'1 месяц',
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xFFA5ABC8),
fontSize: 12,
),
),
),
Container(
decoration: BoxDecoration(color: Colors.white),
padding: EdgeInsets.only(bottom: 10.0),
child: Text(
'1 500 рублей',
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xFF789EEB),
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
)
],
),
),
Positioned(
bottom: 35.0,
left: 0.0,
right: 0.0,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
boxShadow: [BoxShadow(blurRadius: 10, color: Colors.black.withOpacity(0.10), spreadRadius: 5)],
),
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 15,
child: Icon(Icons.add),
),
)
],
),
),
],
)
),
),
)).toList();
CarouselSlider(
options: CarouselOptions(
autoPlay: false,
aspectRatio: 2.0,
enlargeCenterPage: true,
viewportFraction: 0.6,
),
items: imageSliders,
)
Screenshot for visual example:

If I understood you clear, i'd suggest you to use LayoutBuilder widget to get constraints of parent widget which is CarouselSlider.
Output
Full code
class MyHomePage extends StatefulWidget {
final Function onItemPressed;
MyHomePage({
Key key,
this.onItemPressed,
}) : super(key: key);
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<String> imgList = [
'assets/veg.png',
'assets/veg.png',
'assets/veg.png',
'assets/veg.png',
];
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blue,
body: Padding(
padding: const EdgeInsets.only(top: 50),
child: CarouselSlider(
options: CarouselOptions(
autoPlay: false,
enlargeCenterPage: true,
aspectRatio: 16 / 10,
viewportFraction: 0.6,
),
items: imgList
.map(
(item) => LayoutBuilder(
builder: (context, constraints) {
return ClipRRect(
borderRadius: BorderRadius.all(
Radius.circular(20.0),
),
child: Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(20.0),
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Image.asset(
'$item',
fit: BoxFit.cover,
width: constraints.maxWidth,
height: constraints.maxHeight / 2,
),
SizedBox(height: 23),
Text(
'Playstation Plus',
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xFF4F4F4F),
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 5),
Text(
'1 месяц',
style: TextStyle(
color: const Color(0xFFA5ABC8),
fontSize: 12,
),
),
SizedBox(height: 5),
Text(
'1 500 рублей',
style: TextStyle(
color: const Color(0xFF789EEB),
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
SizedBox(height: 5),
],
),
),
Positioned(
bottom: constraints.maxHeight / 2 - 18,
left: 0.0,
right: 0.0,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
blurRadius: 7,
color: Colors.black.withOpacity(0.10),
spreadRadius: 2)
],
),
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 18,
child: Icon(Icons.add),
),
)
],
),
),
],
),
);
},
),
)
.toList(),
),
),
);
}
}

Related

How do I put a button in a block in flutter?

Used expanded, container. Does not work. I tried to put the Elevated Button in Expanded. And all the time that child can't use something else. Most likely, I don't quite understand the structure. I tried to put the Elevated Button in Expanded.
import 'package:percent_indicator/percent_indicator.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(
debugShowCheckedModeBanner: false,
home: Pomodoro(),
));
}
class Pomodoro extends StatefulWidget {
const Pomodoro({Key? key}) : super(key: key);
#override
State<Pomodoro> createState() => _PomodoroState();
}
class _PomodoroState extends State<Pomodoro> {
double percent = 0;
// ignore: non_constant_identifier_names, unused_field
static int TimeInMinut = 25;
// ignore: non_constant_identifier_names
int TimeInSec = TimeInMinut = 60;
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xff1542bf), Color(0xff51a8ff)],
begin: FractionalOffset(0.5, 1)),
),
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Padding(
padding: EdgeInsets.only(top: 25.0),
child: Text(
'Pomodoro Clock',
style: TextStyle(color: Colors.white, fontSize: 40.0),
),
),
Expanded(
child: SizedBox(
height: 20.0,
width: 50.0,
child: CircularPercentIndicator(
percent: percent,
animation: true,
animateFromLastPercent: true,
radius: 90.0,
lineWidth: 20.0,
progressColor: Colors.white,
center: Text(
'$TimeInMinut',
style: const TextStyle(
color: Colors.white, fontSize: 30.0),
),
),
),
),
Expanded(
child: Container(
width: double.infinity,
decoration: const BoxDecoration(
color: Color.fromARGB(255, 163, 48, 48),
borderRadius: BorderRadius.only(
topRight: Radius.circular(30.0),
topLeft: Radius.circular(30.0)),
),
child: Padding(
padding: const EdgeInsets.only(
top: 30.0, left: 20.0, right: 20.0),
child: Row(
children: [
Expanded(
child: Column(
children: const [
Text(
'Study Time',
style: TextStyle(
fontSize: 30.0,
),
),
SizedBox(
height: 10.0,
),
Text(
'25',
style: TextStyle(
fontSize: 80.0,
),
),
],
),
),
Expanded(
child: Column(
children: const [
Text(
'Pause Timer',
style: TextStyle(
fontSize: 30.0,
),
),
Text(
'5',
style: TextStyle(
fontSize: 80.0,
),
),
Expanded(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 10.0),
child: Text(
'hello',
),
))
],
),
),
],
),
),
),
),
Container(
padding: const EdgeInsets.symmetric(vertical: 0.0),
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100.0),
),
),
child: const Padding(
padding: EdgeInsets.all(20.0),
child: Text(
'start studing',
style: TextStyle(color: Colors.white, fontSize: 22.0),
),
),
),
),
]),
),
),
);
}
}
If you like to use Expanded on Text(hello) widget. You need to get constrains from top level/parent widget, but this is not the solution you like to archive.
I will recommend checking /layout/constraints
As for the answer, you need to wrap Row widget Column to place another child just after the row widget. It could be skipped if you we had same color as background.
import 'package:percent_indicator/percent_indicator.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(
debugShowCheckedModeBanner: false,
home: Pomodoro(),
));
}
class Pomodoro extends StatefulWidget {
const Pomodoro({Key? key}) : super(key: key);
#override
State<Pomodoro> createState() => _PomodoroState();
}
class _PomodoroState extends State<Pomodoro> {
double percent = 0;
// ignore: non_constant_identifier_names, unused_field
static int TimeInMinut = 25;
// ignore: non_constant_identifier_names
int TimeInSec = TimeInMinut = 60;
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xff1542bf), Color(0xff51a8ff)],
begin: FractionalOffset(0.5, 1)),
),
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Padding(
padding: EdgeInsets.only(top: 25.0),
child: Text(
'Pomodoro Clock',
style: TextStyle(color: Colors.white, fontSize: 40.0),
),
),
Expanded(
child: SizedBox(
height: 20.0,
width: 50.0,
child: CircularPercentIndicator(
percent: percent,
animation: true,
animateFromLastPercent: true,
radius: 90.0,
lineWidth: 20.0,
progressColor: Colors.white,
center: Text(
'$TimeInMinut',
style: const TextStyle(
color: Colors.white, fontSize: 30.0),
),
),
),
),
Expanded(
child: Container(
width: double.infinity,
padding: const EdgeInsets.only(
top: 30.0, left: 20.0, right: 20.0),
decoration: const BoxDecoration(
color: Color.fromARGB(255, 163, 48, 48),
borderRadius: BorderRadius.only(
topRight: Radius.circular(30.0),
topLeft: Radius.circular(30.0)),
),
child: Column(
children: [
Row(
children: [
Expanded(
child: Column(
children: const [
Text(
'Study Time',
style: TextStyle(
fontSize: 30.0,
),
),
SizedBox(
height: 10.0,
),
Text(
'25',
style: TextStyle(
fontSize: 80.0,
),
),
],
),
),
Column(
children: const [
Text(
'Pause Timer',
style: TextStyle(
fontSize: 30.0,
),
),
Text(
'5',
style: TextStyle(
fontSize: 80.0,
),
),
Padding(
padding: EdgeInsets.symmetric(vertical: 10.0),
child: Text(
'hello',
),
)
],
),
],
),
Container(
height: 100,
width: 200,
padding: const EdgeInsets.symmetric(vertical: 0.0),
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100.0),
),
),
child: const Padding(
padding: EdgeInsets.all(20.0),
child: Text(
'start studing',
style: TextStyle(
color: Colors.white, fontSize: 22.0),
),
),
),
),
],
),
),
),
]),
),
),
);
}
}

How to set a separate value for each category to open related categories in flutter

Hello respected developers! I am trying to set separate category value for each category but now when I click on Pizza category it shows pizza, and when I click on other categories like Sandwich, Burger or anything else. it show the same value as it was designed in a widget. How to set category value for each category screen to have its own and related value. Please help me. here is a portion of my code that need to be fixed I can do it with a hard code but if I have more than 10 categories my code will be too long. Thank you very much and I really appreciate your help.
import 'package:flutter/material.dart';
import 'package:zar/screen/categories.dart';
class TopCard extends StatefulWidget {
const TopCard({Key? key}) : super(key: key);
#override
State<TopCard> createState() => _TopCardState();
}
// TOP CARD CLASS STARTS HERE
class CardItem {
final String urlImage;
final String title;
final String subTitle;
const CardItem({
required this.urlImage,
required this.title,
required this.subTitle,
});
}
// TOP CARD WIDGETS STARTS HERE
Widget topCard({
required CardItem item,
required BuildContext context,
}) =>
Container(
width: 150,
child: Column(
children: [
Expanded(
child: AspectRatio(
aspectRatio: 2 / 2,
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Material(
child: Ink.image(
image: NetworkImage(item.urlImage),
fit: BoxFit.cover,
child: InkWell(
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Categories(
item: item,
),
),
),
),
),
),
),
),
),
const SizedBox(height: 4),
Text(
item.title,
style: const TextStyle(
color: Color(0xff5e35b1),
fontSize: 20,
fontWeight: FontWeight.bold),
),
Text(
item.subTitle,
style: const TextStyle(
color: Colors.redAccent,
),
),
],
),
);
class _TopCardState extends State<TopCard> {
// TOP CARD LIST VIEW STARTS HERE
List<CardItem> items = const [
CardItem(
urlImage:
'https://images.unsplash.com/photo-1542834369-f10ebf06d3e0?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80',
title: 'PIZZA',
subTitle: '\$20',
),
CardItem(
urlImage:
'https://images.unsplash.com/photo-1621852004158-f3bc188ace2d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80',
title: 'SANDWICH',
subTitle: '\$7.99',
),
CardItem(
urlImage:
'https://images.unsplash.com/photo-1534938665420-4193effeacc4?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=871&q=80',
title: 'FRIES',
subTitle: '\$2.99',
),
CardItem(
urlImage:
'https://images.unsplash.com/photo-1585238341710-4d3ff484184d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=804&q=80',
title: 'BURGER',
subTitle: '\$5.99',
),
];
#override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(top: 20),
height: 150,
child: ListView.separated(
scrollDirection: Axis.horizontal,
itemCount: 4,
separatorBuilder: (constext, _) => const SizedBox(width: 16),
itemBuilder: (context, index) => topCard(
context: context,
item: items[index],
),
),
);
}
}
This is my home screen category
This is my Category screen that shows Pizza categories.
And again this is my Category screen that shows the same Pizza categories. And I want this to be different.
#override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(top: 20),
height: 150,
child: ListView.separated(
scrollDirection: Axis.horizontal,
itemCount: 4,
separatorBuilder: (constext, _) => const SizedBox(width: 16),
itemBuilder: (context, index) => topCard(
context: context,
item: items[index],
),
),
);
}
Here is my category screen code:
import 'package:flutter/material.dart';
import 'package:zar/widgets/top_card.dart';
class Categories extends StatelessWidget {
final CardItem item;
const Categories({Key? key, required this.item}) : super(key: key);
#override
Widget build(BuildContext context) {
final double height = MediaQuery.of(context).size.height;
final double width = MediaQuery.of(context).size.width;
return Scaffold(
appBar: AppBar(
title: Text(item.title),
),
body: ListView(
children: [
Container(
height: 350,
width: double.infinity,
color: const Color(0xff673ab7),
child: Column(
children: [
AspectRatio(
aspectRatio: 3 / 2,
child: Image.network(item.urlImage),
),
Text(
item.title,
style: const TextStyle(
color: Colors.white,
fontSize: 25,
fontWeight: FontWeight.bold,
),
)
],
),
),
SizedBox(
height: height * 0.01,
),
Center(
child: Container(
height: 167,
child: Stack(
children: [
Positioned(
child: Material(
child: Container(
margin: const EdgeInsets.all(5),
height: 300,
width: width * 0.9,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
boxShadow: [
BoxShadow(
color: const Color(0xff5e35b1).withOpacity(0.3),
blurRadius: 6.0,
offset: const Offset(4, 8),
),
],
),
),
),
),
Positioned(
top: 6,
left: 5,
child: Card(
elevation: 10.0,
shadowColor: const Color(0xff5e35b1).withOpacity(0.3),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Container(
height: 150,
width: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
image: const DecorationImage(
fit: BoxFit.fill,
image: NetworkImage(
"https://images.unsplash.com/photo-1625395005224-0fce68a3cdc8?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=580&q=80"),
)),
),
),
),
Positioned(
top: 15,
left: 180,
child: Container(
height: 150,
width: 180,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Pizza",
style: TextStyle(
color: Color(0xff5e35b1),
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
Text(
"Italian Chees and Beef",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Divider(
color: Color(0xff5e35b1),
),
],
),
),
),
Positioned(
top: 120,
left: 180,
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Rating",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Text("4.5"),
],
),
),
),
Positioned(
top: 120,
left: 350,
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Price",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Text("\$20"),
],
),
),
),
],
),
),
),
SizedBox(
height: height * 0.01,
),
Center(
child: Container(
height: 167,
child: Stack(
children: [
Positioned(
child: Material(
child: Container(
margin: const EdgeInsets.all(5),
height: 300,
width: width * 0.9,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
boxShadow: [
BoxShadow(
color: const Color(0xff5e35b1).withOpacity(0.3),
blurRadius: 6.0,
offset: const Offset(4, 8),
),
],
),
),
),
),
Positioned(
top: 6,
left: 5,
child: Card(
elevation: 10.0,
shadowColor: const Color(0xff5e35b1).withOpacity(0.3),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Container(
height: 150,
width: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
image: const DecorationImage(
fit: BoxFit.fill,
image: NetworkImage(
"https://images.unsplash.com/photo-1606502281004-f86cf1282af5?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=580&q=80"),
)),
),
),
),
Positioned(
top: 15,
left: 180,
child: Container(
height: 150,
width: 180,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Special Mini Pizza",
style: TextStyle(
color: Color(0xff5e35b1),
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
Text(
"American Pizza",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Divider(
color: Color(0xff5e35b1),
),
],
),
),
),
Positioned(
top: 120,
left: 180,
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Rating",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Text("4.5"),
],
),
),
),
Positioned(
top: 120,
left: 350,
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Price",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Text("\$9.99"),
],
),
),
),
],
),
),
),
SizedBox(
height: height * 0.01,
),
Center(
child: Container(
height: 167,
child: Stack(
children: [
Positioned(
child: Material(
child: Container(
margin: const EdgeInsets.all(5),
height: 300,
width: width * 0.9,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
boxShadow: [
BoxShadow(
color: const Color(0xff5e35b1).withOpacity(0.3),
blurRadius: 6.0,
offset: const Offset(4, 8),
),
],
),
),
),
),
Positioned(
top: 6,
left: 5,
child: Card(
elevation: 10.0,
shadowColor: const Color(0xff5e35b1).withOpacity(0.3),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Container(
height: 150,
width: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
image: const DecorationImage(
fit: BoxFit.fill,
image: NetworkImage(
"https://images.unsplash.com/photo-1628840042765-356cda07504e?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=580&q=80"),
)),
),
),
),
Positioned(
top: 15,
left: 180,
child: Container(
height: 150,
width: 180,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Paparoni Pizza",
style: TextStyle(
color: Color(0xff5e35b1),
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
Text(
"Maxcan Pizza",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Divider(
color: Color(0xff5e35b1),
),
],
),
),
),
Positioned(
top: 120,
left: 180,
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Rating",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Text("4.5"),
],
),
),
),
Positioned(
top: 120,
left: 350,
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Price",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Text("\$17.50"),
],
),
),
),
],
),
),
),
SizedBox(
height: height * 0.01,
),
Center(
child: Container(
height: 167,
child: Stack(
children: [
Positioned(
child: Material(
child: Container(
margin: const EdgeInsets.all(5),
height: 300,
width: width * 0.9,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
boxShadow: [
BoxShadow(
color: const Color(0xff5e35b1).withOpacity(0.3),
blurRadius: 6.0,
offset: const Offset(4, 8),
),
],
),
),
),
),
Positioned(
top: 6,
left: 5,
child: Card(
elevation: 10.0,
shadowColor: const Color(0xff5e35b1).withOpacity(0.3),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Container(
height: 150,
width: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
image: const DecorationImage(
fit: BoxFit.fill,
image: NetworkImage(
"https://images.unsplash.com/photo-1585828922344-85c9daa264b0?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=640&q=80"),
)),
),
),
),
Positioned(
top: 15,
left: 180,
child: Container(
height: 150,
width: 180,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Mashroom Pizza",
style: TextStyle(
color: Color(0xff5e35b1),
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
Text(
"European Pizza",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Divider(
color: Color(0xff5e35b1),
),
],
),
),
),
Positioned(
top: 120,
left: 180,
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Rating",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Text("4.5"),
],
),
),
),
Positioned(
top: 120,
left: 350,
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Price",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Text("\$15.99"),
],
),
),
),
],
),
),
),
],
),
);
}
}
And here is my home screen code.
import 'package:flutter/material.dart';
import 'package:zar/widgets/top_card.dart';
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
#override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Home"),
),
body: Container(
child: Column(
children: const [
TopCard(),
],
),
),
);
}
}

Cant align widgets correctly in Flutter

I have the following code, but i cant figure out, how to align the username to the left (next to the image) and the class-text to the right of the row. MainAxisAlignment.spaceBetween doesnt do the trick. I tried several different alignments on all the rows and columns but nothing is working. the only way i would get space between the two texts is by adding padding to one of the texts but this is not what want because the usernames have different sizes and the class text wouldnt be alligned to the right.
Container(
width: 180,
decoration: BoxDecoration(
color: const Color(0xffe8d9c3),
border: Border.all(color: Colors.transparent),
borderRadius: const BorderRadius.all(
Radius.circular(4),
),
boxShadow: const [
BoxShadow(
color: Colors.black,
blurRadius: 2.0,
spreadRadius: 0.0,
offset: Offset(0, 1),
),
],
),
child: Row(
//mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
const CircleAvatar(
backgroundImage: NetworkImage(
'https://www.woolha.com/media/2020/03/eevee.png',
),
),
const SizedBox(
width: 5,
),
Column(
//mainAxisAlignment: MainAxisAlignment.spaceBetween,
//crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
StreamBuilder<DocumentSnapshot>(
stream: userdoc.snapshots(),
builder: (BuildContext context,
AsyncSnapshot<DocumentSnapshot> snapshot) {
return Text(
"${snapshot.data?["username"]}",
style: const TextStyle(
fontSize: 10,
color: Colors.black,
),
);
},
),
const Text(
"Class 8",
style: TextStyle(
fontSize: 10,
color: Colors.black,
),
),
],
),
Stack(
clipBehavior: Clip.none,
children: const [
SizedBox(
width: 120,
height: 15,
child: LinearProgressIndicator(
value: 0.3,
backgroundColor: Color(0xff816840),
color: Color(0xffffc518),
),
),
Positioned(
right: 10,
top: 2,
child: Text(
"2918",
style: TextStyle(
fontSize: 10,
color: Colors.white,
),
),
),
],
),
],
),
],
),
)
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(
home: MyApp(),
));
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Center(
child: Container(
width: 180,
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: const Color(0xffe8d9c3),
border: Border.all(color: Colors.transparent),
borderRadius: const BorderRadius.all(
Radius.circular(4),
),
boxShadow: const [
BoxShadow(
color: Colors.black,
blurRadius: 2.0,
spreadRadius: 0.0,
offset: Offset(0, 1),
),
],
),
child: Row(
// crossAxisAlignment: CrossAxisAlignment.center,
//mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
const CircleAvatar(
backgroundImage: NetworkImage(
'https://www.woolha.com/media/2020/03/eevee.png',
),
),
const SizedBox(
width: 5,
),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
children: const [
Text(
"username",
style: TextStyle(
fontSize: 10,
color: Colors.black,
),
),
Spacer(),
Text(
"Class 8",
style: TextStyle(
fontSize: 10,
color: Colors.black,
),
),
],
),
Stack(
clipBehavior: Clip.none,
children: const [
SizedBox(
height: 15,
child: LinearProgressIndicator(
value: 0.5,
backgroundColor: Color(0xff816840),
color: Color(0xffffc518),
),
),
Positioned(
right: 10,
top: 2,
child: Text(
"2918",
style: TextStyle(
fontSize: 10,
color: Colors.white,
),
),
),
],
),
],
),
),
],
),
),
)),
);
}
}
you can use Spacer() widget between them

Flutter Tabs "Horizontal viewport was given unbounded height"

I use standard tabs after a few of my blocks. The content in the tabs is styled using a container. The main parent element is Column in which I build all my blocks. I have tried various options using Expanded.
The error sometimes changes to "RenderFlex children have non-zero flex but incoming height constraints are unbounded." This only happens when i try to add tabs, any other block is displayed correctly in my main Column.
body: SafeArea(
child: SingleChildScrollView(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/background.png"),
fit: BoxFit.fill,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: < Widget > [
SizedBox(height: 20),
Container(
margin: EdgeInsets.symmetric(horizontal: 15),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(32),
),
child: TextField(
decoration: InputDecoration(
hintStyle: TextStyle(fontSize: 14),
hintText: 'Найти услугу...',
suffixIcon: Icon(Icons.search),
border: InputBorder.none,
contentPadding:
EdgeInsets.symmetric(horizontal: 20, vertical: 15),
),
),
),
SizedBox(height: 20),
Container(
height: 450,
padding: EdgeInsets.only(top: 35),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/ps-bg.png"),
fit: BoxFit.cover,
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: < Widget > [
SvgPicture.asset(
'assets/ps-logo.svg',
),
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * 0.35,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color.fromRGBO(6, 85, 152, 0),
Color(0xFF084A82),
],
)
),
child: CarouselSlider(
options: CarouselOptions(
autoPlay: false,
aspectRatio: 16 / 10,
enlargeCenterPage: true,
viewportFraction: 0.6,
),
items: imgList.map((item) => LayoutBuilder(builder: (context, constraints) {
return ClipRRect(
borderRadius: BorderRadius.all(
Radius.circular(20.0),
),
child: Stack(
children: < Widget > [
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(20.0),
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: < Widget > [
Image.asset(
'assets/psplus-1month.png',
fit: BoxFit.cover,
width: constraints.maxWidth,
height: constraints.maxHeight / 2,
),
SizedBox(height: 23),
Text(
'Playstation Plus',
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xFF4F4F4F),
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 5),
Text(
'1 месяц',
style: TextStyle(
color: const Color(0xFFA5ABC8),
fontSize: 12,
),
),
SizedBox(height: 5),
Text(
'1 500 рублей',
style: TextStyle(
color: const Color(0xFF789EEB),
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
SizedBox(height: 5),
],
),
),
Positioned(
bottom: constraints.maxHeight / 2 - 18,
left: 0.0,
right: 0.0,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: < Widget > [
Container(
decoration: BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
blurRadius: 7,
color: Colors.black.withOpacity(0.10),
spreadRadius: 2)
],
),
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 18,
child: Icon(Icons.add),
),
)
],
),
),
],
),
);
}, ), ).toList()
)
),
]
),
),
SizedBox(height: 20),
DefaultTabController(
length: 3,
child: Column(
children: [
Container(
margin: EdgeInsets.symmetric(horizontal: 15.0),
child: TabBar(
indicator: BoxDecoration(
borderRadius: BorderRadius.circular(50), // Creates border
color: const Color(0xFF62A6E9)
),
labelColor: Colors.white,
unselectedLabelColor: Colors.grey,
labelStyle: TextStyle(fontSize: 13.0),
tabs: [
Tab(text: 'Инструкция'),
Tab(text: 'Оплаты'),
Tab(text: 'Информация'),
],
),
),
TabBarView(
children: [
Container(
margin: EdgeInsets.all(15.0),
padding: EdgeInsets.all(20.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(30))
),
child: Text(
'Text',
textAlign: TextAlign.left,
style: TextStyle(
color: const Color(0xFF4F4F4F),
height: 1.5,
fontSize: 15,
fontFamily: 'Montserrat',
fontWeight: FontWeight.w500,
),
),
),
Container(
margin: EdgeInsets.all(15.0),
padding: EdgeInsets.all(20.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(30))
),
child: Text(
'Text',
textAlign: TextAlign.left,
style: TextStyle(
color: const Color(0xFF4F4F4F),
height: 1.5,
fontSize: 15,
fontFamily: 'Montserrat',
fontWeight: FontWeight.w500,
),
),
),
Container(
margin: EdgeInsets.all(15.0),
padding: EdgeInsets.all(20.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(30))
),
child: Text(
'Text',
textAlign: TextAlign.left,
style: TextStyle(
color: const Color(0xFF4F4F4F),
height: 1.5,
fontSize: 15,
fontFamily: 'Montserrat',
fontWeight: FontWeight.w500,
),
),
),
],
),
]
)
),
GridView.count(
crossAxisCount: 2,
shrinkWrap: true,
physics: ScrollPhysics(),
scrollDirection: Axis.vertical,
children: List.generate(10, (index) {
return Container(
child: Container(
margin: EdgeInsets.all(15.0),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(30.0)),
child: Stack(
children: < Widget > [
Image.network(
'https://images.unsplash.com/photo-1519125323398-675f0ddb6308?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=94a1e718d89ca60a6337a6008341ca50&auto=format&fit=crop&w=1950&q=80',
fit: BoxFit.cover,
width: 1000.0),
Positioned(
bottom: 0.0,
left: 0.0,
right: 0.0,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: < Widget > [
Container(
decoration:
BoxDecoration(color: Colors.white),
padding: EdgeInsets.only(
top: 15.0,
bottom: 15.0
),
child: Text(
'PUBG',
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xFF4F4F4F),
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
Positioned(
bottom: 40.0,
left: 0.0,
right: 0.0,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment:
CrossAxisAlignment.stretch,
children: < Widget > [
CircleAvatar(
backgroundColor: Colors.white,
radius: 15,
child: Icon(Icons.add),
),
],
),
),
],
)),
),
);
}),
),
]
)
)
))
Ok i found solution, TabBarView need height, Expanded not help.
Container(
height: MediaQuery.of(context).size.height,
child: TabBarView(
children: [
Icon(Icons.directions_car),
Icon(Icons.directions_car),
Icon(Icons.directions_car)
],
),
)
Wrap in LayoutBuilder:
LayoutBuilder(
builder: (_, BoxConstraints viewportConstraints) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: viewportConstraints.maxHeight,
),
child: Column(),
);
},
),

handling application layout in flutter app

I have Entry page to my app like below, I am getting bottom overflow , image size issue , text font issue, when I run on the phone with less than 5 inches,
If I run the same app on over 5 inches I am getting like below
Can anyone who have worked on developing flutter apps help me on how I can adjust according to the screen?
also How to adjust text size, image size every other things as per the screen size?
below is my code:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
Color colorTheme;
class LoginPage extends StatefulWidget {
#override
_LoginPageState createState() => new _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
TextEditingController controllerEmail = TextEditingController();
TextEditingController controllerPassword = TextEditingController();
String username, password;
Widget loginButtonChild = const Text(
"Log in",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white, fontFamily: "OpenSans-Regular", fontSize: 16),
);
Widget loginButtonWithCircle = Row(
children: <Widget>[
const Text(
"Log in",
style: TextStyle(
color: Colors.white,
fontFamily: "OpenSans-Regular",
),
),
CircularProgressIndicator(),
],
);
#override
Widget build(context) {
double maxHeight = MediaQuery.of(context).size.height;
// ScreenUtil.instance = ScreenUtil.getInstance()..init(context);
return Scaffold(
resizeToAvoidBottomPadding: true,
body: SingleChildScrollView(
child: LimitedBox(
maxHeight: maxHeight * 1,
child: Stack(
//fit: StackFit.expand,
children: <Widget>[
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.only(
top: MediaQuery.of(context).size.height * 0.05,
left: MediaQuery.of(context).size.width * 0.05),
child: Image.asset('assets/Heat Map.png',
width: 100, height: 20, fit: BoxFit.fill),
)
],
),
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(15))),
padding: EdgeInsets.all(
// MediaQuery.of(context).size.width * 0.09,
MediaQuery.of(context).size.width * 0.1,
),
child: Image.asset(
'assets/layer_1_3.png',
// color: Color(0xFFe31735),
// width: 300,
width: MediaQuery.of(context).size.width * 0.72,
// height: 300,
height: MediaQuery.of(context).size.height * 0.5,
fit: BoxFit.contain,
),
),
Positioned(
left: 78.0,
bottom: 10.0,
child: RichText(
text: TextSpan(
text: 'APP',
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.black),
children: <TextSpan>[
TextSpan(
text: '\nDevelopment',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.normal,
),
),
TextSpan(
text: '\nFlutter',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.normal,
),
),
],
),
maxLines: 3,
overflow: TextOverflow.ellipsis,
softWrap: true,
),
),
],
),
SingleChildScrollView(
child: new Container(
padding: const EdgeInsets.fromLTRB(20.0, 0.0, 40.0, 40.0),
child: new Form(
child: new Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 20),
child: Icon(Icons.person_outline,
size: 38, color: Colors.black),
),
SizedBox(width: 10.0),
new Expanded(
child: new TextFormField(
style: TextStyle(color: Colors.black),
controller: controllerEmail,
//cursorColor: , make it yellow later TODO
decoration: new InputDecoration(
labelText: "Username",
enabledBorder: new UnderlineInputBorder(
borderSide: new BorderSide(
color: Colors.red,
))),
keyboardType: TextInputType.text,
),
),
],
),
Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 20),
child: Icon(
Icons.lock_outline,
size: 38,
color: Colors.black,
),
),
SizedBox(width: 10.0),
new Expanded(
child: new TextFormField(
controller: controllerPassword,
style: TextStyle(color: Colors.red),
decoration: new InputDecoration(
labelText: "Password",
enabledBorder: new UnderlineInputBorder(
borderSide: new BorderSide(
color: Colors.red,
))),
obscureText: true,
keyboardType: TextInputType.text,
),
),
],
),
Padding(
padding: EdgeInsets.only(
top: 0,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
FlatButton(
onPressed: () {
},
child: Text(
"Forgot password?",
style: TextStyle(
color: Colors.grey,
fontFamily: "OpenSans-Regular",
),
),
)
],
),
),
SizedBox(
height: MediaQuery.of(context).size.width * 0.04,
),
RaisedButton(
shape: RoundedRectangleBorder(
borderRadius:
new BorderRadius.circular(25.0),
side: BorderSide(color: Colors.red)),
color: Colors.red,
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 48),
child: loginButtonChild,
),
const SizedBox(
width: 45.0,
height: 45.0,
),
Icon(Icons.arrow_forward,
color: Colors.white),
],
),
onPressed: () {
}),
],
),
),
),
),
],
),
],
),
),
),
);
}
}
You can use SingleChildScrollView to avoid overflow error just wrap your widget with SingleChildScrollView
Example:-
SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height,
child:YourWidget();
)
)