flutter : How to make Card Radio Button? - flutter

I want make card Radio Button.
I want make card Radio Button.I want make card Radio Button.
I want make card Radio Button.I want make card Radio Button.
I want make card Radio Button.
I want make card Radio Button.I want make card Radio Button.I want make card Radio Button.I want make card Radio Button.I want make card Radio Button.I want make card Radio Button.I want make card Radio Button.I want make card Radio Button.
This is my code
import 'package:cwc/ui/Home/homePage.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class LandingPage extends StatefulWidget {
const LandingPage({Key? key}) : super(key: key);
#override
_LandingPageState createState() => _LandingPageState();
}
class _LandingPageState extends State<LandingPage> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
height: MediaQuery.of(context).size.height,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/bg.png"),
fit: BoxFit.cover,
),
),
width: double.infinity,
child: SafeArea(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: 80,
),
Text(
'Membership Packages',
textAlign: TextAlign.center,
style: GoogleFonts.poppins(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.white),
),
Padding(
padding: const EdgeInsets.all(20.0),
child: Text(
'Choose a membership plan to unlock all the features of the CWC Wellness Resource App',
textAlign: TextAlign.center,
style: GoogleFonts.poppins(
fontSize: 14,
color: Colors.white,
),
),
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 13,
),
InkWell(
onTap: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => HomePage(),
),
);
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0),
child: Container(
decoration: const BoxDecoration(
// borderRadius: BorderRadius.circular(10),
image: DecorationImage(
image: AssetImage("assets/ona.png"),
fit: BoxFit.fill,
),
),
height: 147,
width: MediaQuery.of(context).size.width,
child: Row(
children: [
Container(
width: MediaQuery.of(context).size.width / 1.75,
color: Colors.transparent,
),
Image.asset(
'assets/onaa.png',
height: 114,
width: 114,
),
],
)),
),
),
const SizedBox(
height: 32,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0),
child: Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/onb.png"),
fit: BoxFit.fill,
),
),
height: 147,
width: MediaQuery.of(context).size.width,
child: Row(
children: [
Container(
width: MediaQuery.of(context).size.width / 1.75,
color: Colors.transparent,
),
Image.asset(
'assets/onbb.png',
height: 114,
width: 114,
),
],
)),
),
const SizedBox(
height: 32,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0),
child: Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/onc.png"),
fit: BoxFit.fill,
),
),
height: 147,
width: MediaQuery.of(context).size.width,
child: Row(
children: [
Container(
width: MediaQuery.of(context).size.width / 1.75,
color: Colors.transparent,
),
Image.asset(
'assets/oncc.png',
height: 114,
width: 114,
),
],
),
),
),
],
),
],
),
),
),
),
bottomNavigationBar: GestureDetector(
onTap: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => HomePage(),
),
);
},
child: Container(
color: Color(0xff3a99a4),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(topLeft: Radius.circular(60))),
width: double.infinity,
height: 57,
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(27, 0, 0, 0),
child: Container(
width: 18,
height: 18,
),
),
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
child: Text(
'Continue',
style: GoogleFonts.poppins(
fontSize: 14,
color: Color(0xFF158998),
fontWeight: FontWeight.w600),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 27, 0),
child: const Icon(
Icons.arrow_right_alt_outlined,
size: 18,
color: Color(0xFF158998),
),
),
],
),
)))));
}
}
I Created this.
But I want like this.

To achieve that you need to wrap your widgets inside Stack widget and also have to assign position to each like below code below. Just replace you Column with this :
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
InkWell(
onTap: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => HomePage(),
),
);
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0),
child: SizedBox(
height: 147,
width: MediaQuery.of(context).size.width,
child: Stack(
alignment: Alignment.center,
children: [
Positioned(
left: 0,
right: 0,
bottom: 8,
top: 0,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
image: DecorationImage(
image: NetworkImage(
"https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg"),
fit: BoxFit.fill,
),
),
height: 147,
width: MediaQuery.of(context).size.width,
child: Row(
children: [
Container(
width: MediaQuery.of(context)
.size
.width /
1.75,
color: Colors.transparent,
),
Image.network(
"https://cdn.pixabay.com/photo/2017/07/08/09/49/red-2483933_960_720.jpg",
height: 114,
width: 114,
),
],
)),
),
Positioned(
width: 18,
bottom: 0,
child: Center(
child: Container(
height: 15,
width: 15,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(50),
),
child: Radio(
activeColor: Colors.green,
overlayColor: MaterialStateProperty.all(
Colors.red),
value: 1,
groupValue: 1,
onChanged: (int? value) {},
),
),
),
),
],
),
),
),
),
Divider(color: Colors.transparent,),
InkWell(
onTap: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => HomePage(),
),
);
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0),
child: SizedBox(
height: 147,
width: MediaQuery.of(context).size.width,
child: Stack(
alignment: Alignment.center,
children: [
Positioned(
left: 0,
right: 0,
bottom: 8,
top: 0,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
image: DecorationImage(
image: NetworkImage(
"https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg"),
fit: BoxFit.fill,
),
),
height: 147,
width: MediaQuery.of(context).size.width,
child: Row(
children: [
Container(
width: MediaQuery.of(context)
.size
.width /
1.75,
color: Colors.transparent,
),
Image.network(
"https://cdn.pixabay.com/photo/2017/07/08/09/49/red-2483933_960_720.jpg",
height: 114,
width: 114,
),
],
)),
),
Positioned(
width: 18,
bottom: 0,
child: Center(
child: Container(
height: 15,
width: 15,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(50),
),
child: Radio(
activeColor: Colors.green,
overlayColor: MaterialStateProperty.all(
Colors.red),
value: 1,
groupValue: 1,
onChanged: (int? value) {},
),
),
),
),
],
),
),
),
),
Divider(color: Colors.transparent,),
InkWell(
onTap: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => HomePage(),
),
);
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0),
child: SizedBox(
height: 147,
width: MediaQuery.of(context).size.width,
child: Stack(
alignment: Alignment.center,
children: [
Positioned(
left: 0,
right: 0,
bottom: 8,
top: 0,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
image: DecorationImage(
image: NetworkImage(
"https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg"),
fit: BoxFit.fill,
),
),
height: 147,
width: MediaQuery.of(context).size.width,
child: Row(
children: [
Container(
width: MediaQuery.of(context)
.size
.width /
1.75,
color: Colors.transparent,
),
Image.network(
"https://cdn.pixabay.com/photo/2017/07/08/09/49/red-2483933_960_720.jpg",
height: 114,
width: 114,
),
],
)),
),
Positioned(
width: 18,
bottom: 0,
child: Center(
child: Container(
height: 15,
width: 15,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(50),
),
child: Radio(
activeColor: Colors.green,
overlayColor: MaterialStateProperty.all(
Colors.red),
value: 1,
groupValue: 1,
onChanged: (int? value) {},
),
),
),
),
],
),
),
),
),
],
),

Related

How Can I resize image widget relatively?

I want my image resize relatively from parent Containerwidget and defined scale: 0.8,//here in AssetImage() but it doesn't work ? How Can I fix this ?
Container(
margin: const EdgeInsets.only(top: 30),
alignment: Alignment.centerLeft,
child: Wrap(
children: [
GestureDetector(
onTap: () {
print("test");
},
child: Container(
width: 50,
height: 50,
// color: Colors.green,
decoration: const BoxDecoration(
color: Colors.blue,
shape: BoxShape.circle,
image:
DecorationImage(
fit: BoxFit.fill,
image: AssetImage('images/prop/lock.png'),
scale: 0.8,//here
),
),
),
),
],
),
),
Additional comment
I think LayoutBuilder() doesn't work appropriately.
Container(
margin: const EdgeInsets.only(top: 30),
alignment: Alignment.centerLeft,
child: Wrap(
children: [
GestureDetector(
onTap: () {
print("test");
},
child: Container(
width: 50,
height: 50,
// color: Colors.green,
decoration: const BoxDecoration(
color: Colors.blue,
shape: BoxShape.circle,
),
child: LayoutBuilder(
builder: (context, constraints) {
return Image.asset(
'images/prop/lock.png',
fit: BoxFit.none,
height: constraints.maxHeight * 0.1,
width: constraints.maxWidth * 0.1,
);
},
),
),
),
],
),
),
You can use LayoutBuilder like this:
Container(
margin: const EdgeInsets.only(top: 30),
alignment: Alignment.centerLeft,
child: Wrap(
children: [
GestureDetector(
onTap: () {
print("test");
},
child: Container(
width: 50,
height: 50,
alignment: Alignment.center,// important part
decoration: const BoxDecoration(
color: Colors.blue,
shape: BoxShape.circle,
),
child: LayoutBuilder(
builder: (context, constraints) {
return Image.asset(
'images/prop/lock.png',
fit: BoxFit.contain,
height: constraints.maxHeight * 0.3,
width: constraints.maxWidth * 0.3,
);
},
),
),
),
],
),
)
You can Use AspectRatio Class for that use, like this
final double size = MediaQuery.of(context).size.aspectRatio;
You must change fit type to BoxFit.none, like this:
Container(
margin: const EdgeInsets.only(top: 30),
alignment: Alignment.centerLeft,
child: Wrap(
children: [
GestureDetector(
onTap: () {
print("test");
},
child: Container(
width: 100,
height: 100,
// color: Colors.green,
decoration: const BoxDecoration(
color: Colors.blue,
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.none, // change this line
image: AssetImage('images/prop/lock.png'),
scale: 0.8,
),
),
),
),
],
),
)

flutter background image carousel

I'm new to flutter and working on developing my flutter coding skills. I want to display 3 background images in a carousel while other texts and button remain same on the screen. in the below code, image carousel is working properly but my Get Started button and other texts not displaying at all. what should I do for correct this issue. appreciate your help on this.
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class Test extends StatelessWidget {
#override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.leanBack);
return Scaffold(
body: ListView(
children: [
CarouselSlider(
items: [
//1st Image of Slider
Container(
color: Colors.black,
child: Stack(
children: [
Positioned.fill(
child: Opacity(
opacity: 0.8,
child: Image.asset('assets/images/person1.png',
fit: BoxFit.cover),
),
),
Container(
color: Color.fromRGBO(5, 65, 196, 0.19),
),
],
),
),
//2nd Image of Slider
Container(
color: Colors.black,
child: Stack(
children: [
Positioned.fill(
child: Opacity(
opacity: 0.8,
child: Image.asset('assets/images/person2.png',
fit: BoxFit.cover),
),
),
Container(
color: Color.fromRGBO(5, 65, 196, 0.19),
),
],
),
),
//3rd Image of Slider
Container(
color: Colors.black,
child: Stack(
children: [
Positioned.fill(
child: Opacity(
opacity: 0.8,
child: Image.asset('assets/images/person3.png',
fit: BoxFit.cover),
),
),
Container(
color: Color.fromRGBO(5, 65, 196, 0.19),
),
],
),
),
],
//Slider Container properties
options: CarouselOptions(
height: 810.0,
enlargeCenterPage: true,
autoPlay: true,
aspectRatio: 16 / 16,
autoPlayCurve: Curves.fastOutSlowIn,
enableInfiniteScroll: true,
autoPlayAnimationDuration: Duration(milliseconds: 800),
viewportFraction: 1,
),
),
Padding(
padding: const EdgeInsets.only(left: 40, bottom: 230),
child: Align(
alignment: Alignment.bottomLeft,
child: Text('Meet \nYour Doctor\nHere',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 35,
color: Color(0xffFAFAFA),
fontWeight: FontWeight.w500,
))),
),
Padding(
padding: const EdgeInsets.only(left: 30, top: 26),
child: Align(
alignment: Alignment.topLeft,
child: Text('DOCTOR',
style: TextStyle(
fontFamily: 'Dubai',
fontSize: 30,
color: Colors.white,
fontWeight: FontWeight.w500,
))),
),
Padding(
padding: const EdgeInsets.only(bottom: 60),
child: Align(
alignment: Alignment.bottomCenter,
child: SizedBox(
width: 320,
height: 65,
child: ElevatedButton(
onPressed: () {},
child: Text(
'Get Started',
style: TextStyle(
color: Colors.white,
fontSize: 25,
fontWeight: FontWeight.normal),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(
Color(0xff05ABA3)),
shape: MaterialStateProperty.all<
RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(50.0),
),
))),
)),
),
Padding(
padding: const EdgeInsets.only(bottom: 20),
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0),
color: Colors.white,
),
height: 5,
width: 120,
))),
],
),
);
}
}
you can set image in background using BoxDecoration in container-
Container(
height: 120.0,
width: 120.0,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'imagename'),
fit: BoxFit.fill,
),
shape: BoxShape.circle,
),
)
On your Scaffold's body: you are using ListView. You can still find those widgets by scrolling down.
For your case, you like to have text and button widgets over the UI.
You need to replace ListView with Stack on body.
return Scaffold(
body: Stack( // this
children: [
CarouselSlider
More about Stack and ListView.

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(),
],
),
),
);
}
}

Widgets in a row not spacing themselves out evenly

I'm trying to make a widget to display posts by users on a social media platform, I have certain elements I want to include in the post, one of them being the external links he might have attached while creating the posts.
I want these links to be represented by rounded buttons(which I've managed to achieve through the use of ClipOval) and I want these ovals to be in a row spaced evenly from the center.
So far, the only way I've been able to space them out is by adding SizedBox(s) of a certain width. But this is not efficient for different posts may differ in the number of links and thus the number of Ovals. This would look messy then.
I have overlaid the row on top of the post's image(to which I've applied a linear gradient to make the buttons visible) using a stack.
Here's my code
class postTemplate extends StatelessWidget {
List <String> tags = ['tag1','tag2','tag3','tag4','tag5','tag6','tag7','tag8'];
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
SizedBox(height: 150,),
Container(
height: 450,
child: Stack(
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(height: 20,),
Card(
elevation: 8.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(32)
),
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
ListTile(
title: Padding(
padding: const EdgeInsets.only(left : 70.0),
child: Text("Username"),
),
subtitle: Padding(
padding: const EdgeInsets.only(top: 10.0,left: 80.0),
child: Text("Hello"),
),
),
Stack(
children: [
Container(
child: Container(
foregroundDecoration:BoxDecoration(
gradient: LinearGradient(
colors: [Colors.white, Colors.transparent],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
stops: [0, 0.3],
),),
child: Image(image: AssetImage('assets/images/modelPostImage.png'),fit: BoxFit.contain,)),
),
Positioned(
bottom: 10.0,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(width: 15,),
Container(
width: 56,
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 2.0,
spreadRadius: 1.0,
)
]
),
child: ClipOval(
child: Material(// button color
child: InkWell(
splashColor: Colors.red, // inkwell color
child: SizedBox(width: 56, height: 56, child:Image(
image: new AssetImage("assets/Icons/browser.jpg"),
width: 32,
height:32,
color: null,
fit: BoxFit.scaleDown,
),),
onTap: () {},
),
),
),
),
SizedBox(width: 15,),
Container(
width: 60,
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 2.0,
spreadRadius: 1.0,
)
]
),
child: ClipOval(
child: Material(// button color
child: InkWell(
splashColor: Colors.red, // inkwell color
child: SizedBox(width: 56, height: 56, child:Image(
image: new AssetImage("assets/Icons/browser.jpg"),
width: 32,
height:32,
color: null,
fit: BoxFit.scaleDown,
),),
onTap: () {},
),
),
),
),
SizedBox(width: 15,),
Container(
width: 60,
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 2.0,
spreadRadius: 1.0,
)
]
),
child: ClipOval(
child: Material(// button color
child: InkWell(
splashColor: Colors.red, // inkwell color
child: SizedBox(width: 56, height: 56, child:Image(
image: new AssetImage("assets/Icons/browser.jpg"),
width: 32,
height:32,
color: null,
fit: BoxFit.scaleDown,
),),
onTap: () {},
),
),
),
),
],
),
),
],
),
Container(
height: 44,
width: 350,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(22))
),
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: tags.length,
itemBuilder: (BuildContext context, int index){
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(22),
border: Border.all(color: Colors.black)
),
margin: EdgeInsets.only(right: 13, left: 13),
child: Padding(
padding: const EdgeInsets.only(
top: 10.0, bottom: 5.0, right: 20, left:20
),
child: Text(tags[index],
style: TextStyle(
color: Colors.black
),),
),
);
},
),
),
],
),
)
],
),
CircleAvatar(
radius: 42,
backgroundImage: AssetImage('assets/Icons/profileLogo.jpg')
)
],
),
),
],
),
);
}
}
Any help would be appreciated.
Wrap with a container and give it full width and remove sizing
Positioned(
bottom: 10.0,
child: Container(
width:MediaQuery.of(context).size.width,
child :Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 56,
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 2.0,
spreadRadius: 1.0,
)
]
),
child: ClipOval(
child: Material(// button color
child: InkWell(
splashColor: Colors.red, // inkwell color
child: SizedBox(width: 56, height: 56, child:Image(
image: new AssetImage("assets/Icons/browser.jpg"),
width: 32,
height:32,
color: null,
fit: BoxFit.scaleDown,
),),
onTap: () {},
),
),
),
),
Container(
width: 60,
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 2.0,
spreadRadius: 1.0,
)
]
),
child: ClipOval(
child: Material(// button color
child: InkWell(
splashColor: Colors.red, // inkwell color
child: SizedBox(width: 56, height: 56, child:Image(
image: new AssetImage("assets/Icons/browser.jpg"),
width: 32,
height:32,
color: null,
fit: BoxFit.scaleDown,
),),
onTap: () {},
),
),
),
),
Container(
width: 60,
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 2.0,
spreadRadius: 1.0,
)
]
),
child: ClipOval(
child: Material(// button color
child: InkWell(
splashColor: Colors.red, // inkwell color
child: SizedBox(width: 56, height: 56, child:Image(
image: new AssetImage("assets/Icons/browser.jpg"),
width: 32,
height:32,
color: null,
fit: BoxFit.scaleDown,
),),
onTap: () {},
),
),
),
),
],
),
),
),
],
),
There is a specialized widget to create even space instead of using SizedBox. Replace SizedBox with Spacer.

Flutter Positioning Stack Complex Design

I am struggling with this, How Can I achieve this design? My code included stack widget with container background image but it's not showing properly.
I tried and it's showing like bellow image,
I want to design exactly like first image, I am stucking on positioning of small camera icon, background image, buy now banner etc, here's my code-
Stack(
children: [
Container(
decoration: new BoxDecoration(
// color: Colors.transparent,
image: new DecorationImage(
fit: BoxFit.fill,
image: new AssetImage(
'images/icons/egle2.png',
),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
children: [
Stack(
alignment: Alignment.topCenter,
children: [
Container(
height: 100,
width: 100,
),
Positioned(
// right: 1.0,
child: Material(
elevation: 8.0,
color: Colors.blue,
shape: CircleBorder(),
child: CircleAvatar(
maxRadius: 50,
minRadius: 40,
backgroundColor: Colors.transparent,
backgroundImage: AssetImage(
'images/icons/jully.png'),
),
),
),
// SizedBox(
// width: 20,
// ),
Positioned(
right: 0.0,
top: 0.0,
child: Align(
alignment: Alignment.topRight,
child: Image.asset(
'images/icons/camera.png',
// height: ,
// width: 25,
),
),
),
],
),
SizedBox(
height: 5,
),
Text(
'Jully',
style: TextStyle(
color: Colors.white, fontSize: 18),
),
SizedBox(
height: 5,
),
GestureDetector(
onTap: null,
child: Container(
padding: EdgeInsets.all(5),
height: 25,
// width: 30,
decoration: BoxDecoration(
color: UniversalVariables.yellowColor,
borderRadius: BorderRadius.circular(4),
),
child: Row(
children: [
Icon(
Icons.card_giftcard,
size: 15,
),
SizedBox(
width: 2,
),
Text(
'ID: 123875',
style: TextStyle(fontSize: 12),
),
],
),
),
),
SizedBox(
height: 200,
),
],
),
Column(
children: [
Stack(
alignment: Alignment.topCenter,
children: [
Container(
height: 100,
width: 100,
),
Positioned(
right: 1.0,
child: Material(
elevation: 8.0,
color: Colors.blue,
shape: CircleBorder(),
child: CircleAvatar(
maxRadius: 50,
minRadius: 40,
backgroundColor: Colors.transparent,
backgroundImage:
AssetImage('images/icons/king.png'),
),
),
),
SizedBox(
width: 20,
),
Positioned(
right: 0.0,
top: 0.0,
child: Align(
alignment: Alignment.topRight,
child: Image.asset(
'images/icons/camera.png',
// height: ,
// width: 25,
),
),
),
],
),
SizedBox(
height: 5,
),
Text(
'King_20',
style: TextStyle(
color: Colors.white, fontSize: 18),
),
SizedBox(
height: 5,
),
GestureDetector(
onTap: null,
child: Container(
padding: EdgeInsets.all(5),
height: 25,
// width: 30,
decoration: BoxDecoration(
color: UniversalVariables.yellowColor,
borderRadius: BorderRadius.circular(4),
),
child: Row(
children: [
Icon(
Icons.card_giftcard,
size: 15,
),
SizedBox(
width: 2,
),
Text(
'ID: 123875',
style: TextStyle(fontSize: 12),
),
],
),
),
),
],
),
Column(
children: [
Stack(
alignment: Alignment.topCenter,
children: [
Container(
height: 100,
width: 100,
),
Positioned(
right: 1.0,
child: Material(
elevation: 8.0,
color: Colors.blue,
shape: CircleBorder(),
child: CircleAvatar(
maxRadius: 50,
minRadius: 40,
backgroundColor: Colors.transparent,
backgroundImage:
AssetImage('images/icons/hulk.png'),
),
),
),
SizedBox(
width: 20,
),
Positioned(
// top: 5.0,
right: 0.0,
child: Container(
child: Image.asset(
'images/icons/camera.png',
// height: ,
// width: 25,
),
),
),
],
),
SizedBox(
height: 5,
),
Text(
'Hulk',
style: TextStyle(
color: Colors.white, fontSize: 18),
),
SizedBox(
height: 5,
),
GestureDetector(
onTap: null,
child: Container(
padding: EdgeInsets.all(5),
height: 25,
// width: 30,
decoration: BoxDecoration(
color: UniversalVariables.yellowColor,
borderRadius: BorderRadius.circular(4),
),
child: Row(
children: [
Icon(
Icons.card_giftcard,
size: 15,
),
SizedBox(
width: 2,
),
Text(
'ID: 123875',
style: TextStyle(fontSize: 12),
),
],
),
),
),
SizedBox(
height: 200,
),
// Stack(
// alignment: Alignment.topCenter,
// children: [
// Container(
// height: 100,
// width: 100,
// ),
// Positioned(
// right: 1.0,
// child: Material(
// elevation: 8.0,
// color: Colors.blue,
// shape: CircleBorder(),
// child: CircleAvatar(
// maxRadius: 50,
// minRadius: 40,
// backgroundColor: Colors.transparent,
// backgroundImage: AssetImage(
// 'images/icons/happyman.png'),
// ),
// ),
// ),
// SizedBox(
// width: 20,
// ),
// Positioned(
//// top: 5.0,
// right: 0.0,
// child: Container(
// child: Image.asset(
// 'images/icons/camera.png',
//// height: ,
//// width: 25,
// ),
// ),
// ),
// ],
// ),
// SizedBox(
// height: 5,
// ),
// Text(
// 'Happy Man',
// style: TextStyle(
// color: Colors.white, fontSize: 18),
// ),
// SizedBox(
// height: 5,
// ),
// GestureDetector(
// onTap: null,
// child: Container(
// padding: EdgeInsets.all(5),
// height: 25,
//// width: 30,
// decoration: BoxDecoration(
// color: UniversalVariables.yellowColor,
// borderRadius: BorderRadius.circular(4),
// ),
// child: Row(
// children: [
// Icon(
// Icons.card_giftcard,
// size: 15,
// ),
// SizedBox(
// width: 2,
// ),
// Text(
// 'ID: 123875',
// style: TextStyle(fontSize: 12),
// ),
// ],
// ),
// ),
// ),
],
),
],
),
),
Positioned.fill(
top: 280,
child: Container(
color: Colors.yellow,
height: 100,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(left: 20),
child: Container(
child: Row(
children: [
Image.asset('images/icons/badge4.png',),
SizedBox(width: 10,),
Text(
"X 70 = \$10",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold),
),
],
),
),
),
Padding(
padding: const EdgeInsets.only(right: 20),
child: GestureDetector(
onTap: null,
child: Container(
padding: EdgeInsets.all(8),
height: 35,
// width: 30,
decoration: BoxDecoration(
color: UniversalVariables.blackColor,
borderRadius: BorderRadius.circular(4),
),
child: Row(
children: [
Text(
'Buy Now',
textAlign: TextAlign.center,
style:
TextStyle(color: Colors.white),
),
],
),
),
),
),
],
),
),
),
],
),
As usual, there might be better examples on how to achieve this result.
Here's a fast attempt to recreate it. It needs some fine tuning to fit any screen size, using AutoSizeText and rewriting PersonDrawer to be responsive too.
But I hope that it will help you to move in the right direction.
class MySuperCoolStackWidget extends StatelessWidget {
final double baseWidth = 520.0;
final double baseHeight = 345.0;
double fromWidth(double size, BoxConstraints constraints) {
return size / baseWidth * constraints.maxWidth;
}
double fromHeight(double size, BoxConstraints constraints) {
return size / baseHeight * constraints.maxHeight;
}
#override
Widget build(BuildContext context) {
return AspectRatio(
aspectRatio: baseWidth / baseHeight,
child: LayoutBuilder(
builder: (context, constraints) {
return Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.black,
),
),
AspectRatio(
aspectRatio: 520.0 / 260.0,
child: Container(
padding: EdgeInsets.fromLTRB(
fromWidth(20.0, constraints),
fromHeight(40.0, constraints),
fromWidth(20.0, constraints),
fromHeight(20.0, constraints),
),
child: LayoutBuilder(
builder: (_, innerConstraints){
return Row(
children: <Widget>[
Expanded(
child: PersonDrawer(),
),
SizedBox(
width: fromWidth(20.0, constraints),
),
Expanded(
child: Transform.translate(
offset: Offset(0.0, innerConstraints.maxHeight / 2.0),
child: PersonDrawer(),
),
),
SizedBox(
width: fromWidth(20.0, constraints),
),
Expanded(
child: PersonDrawer(),
),
],
);
},
),
),
),
Positioned(
left: 0,
right: 0,
bottom: fromHeight(20.0, constraints),
child: AspectRatio(
aspectRatio: 520.0 / 65.0,
child: Container(
padding: EdgeInsets.symmetric(
vertical: fromHeight(16.0, constraints),
horizontal: fromWidth(32.0, constraints),
),
color: Colors.orange[400],
child: Row(
children: <Widget>[
Expanded(
child: Row(
children: <Widget>[
Icon(Icons.local_florist),
Text('x 70 = \$10'),
],
),
),
RaisedButton(
color: Colors.black,
textColor: Colors.white,
onPressed: () {},
child: Text('Buy now'),
),
],
),
),
),
),
],
);
},
),
);
}
}
class PersonDrawer extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: Colors.white10,
border: Border.all(color: Colors.white12),
borderRadius: BorderRadius.circular(10.0),
),
child: Column(
children: <Widget>[
Expanded(
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Container(
padding: EdgeInsets.all(10.0),
child: AspectRatio(
aspectRatio: 1.0,
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
),
),
),
),
Positioned(
top: 5.0,
right: 5.0,
child: Icon(
Icons.camera,
color: Colors.white,
),
),
],
),
),
SizedBox(height: 5.0),
Container(
padding: EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
Text(
'King_20',
style: TextStyle(
color: Colors.white,
),
),
SizedBox(height: 5.0),
Container(
padding: EdgeInsets.all(2.0),
decoration: BoxDecoration(
color: Colors.orange[400],
borderRadius: BorderRadius.circular(5.0),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(Icons.perm_identity, size: 10.0),
Text(
'ID: 1234567',
style: TextStyle(
fontSize: 10.0,
),
),
],
),
),
],
),
)
],
),
);
}
}