Card with image on top and text below - flutter

Currently I have a card where the image fills the card because I have fit: BoxFit.fill. However I need text below my image. I've tried a few different ways to introduce the text,,Columns etc.. But to no available. The images are of different sizes loaded from the Internet so the fit property works well with the images.
Here is what I have so far. my build method:
#override
Widget build(BuildContext context) {
return Column(children: [
GestureDetector(
onTap: () {
},
child: Container(
width: 335,
height: 174,
child: Card(
clipBehavior: Clip.antiAliasWithSaveLayer,
child: Image.network(
'https://via.placeholder.com/300?text=DITTO',
fit: BoxFit.fill,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
elevation: 5,
margin: EdgeInsets.all(10),
),
),
),
]);
}
But I want to have text under the image like this design:
The process bar and timer are unnecessary.

You must place the image and text in a Column widget, in addition to specifying the image dimensions like this:
Column(children: [
GestureDetector(
onTap: () {},
child: Container(
width: 335,
height: 174,
child: Card(
clipBehavior: Clip.antiAliasWithSaveLayer,
child: Column(
children: [
SizedBox(
width: 335,
height: 110,
child: Image.network(
'https://via.placeholder.com/300?text=DITTO',
fit: BoxFit.fill,
),
),
SizedBox(height: 16,),
Column(children:[
Text('Title'),
Text('Subtitle')
])
],
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
elevation: 5,
margin: EdgeInsets.all(10),
),
),
),
]);

This worked for me unless you want the text to be overlay, then u gotta use a Stack() then wrap your text in a Positioned() widget:
Card(
clipBehavior: Clip.antiAliasWithSaveLayer,
child: Column(
children: [
Image.network(
'https://via.placeholder.com/300?text=DITTO',
fit: BoxFit.fill,
),
Text('Something'),
],
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
elevation: 5,
margin: EdgeInsets.all(10),
)

Accepted solution giving render overflow error, Above issue, can be solved using the Stack widget. I recommend using MediaQuery instead of hardcoded values.
SizedBox(
width: 335,
height: 174,
child: Stack(
children: <Widget>[
Card(
clipBehavior: Clip.antiAliasWithSaveLayer,
child: Column(
children: [
SizedBox(
width: 335,
height: 110,
child: Image.network(
'https://via.placeholder.com/300?text=DITTO',
fit: BoxFit.fill,
),
),
],
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
elevation: 5,
margin: EdgeInsets.all(10),
),
Positioned(
bottom: 0,
left: 10,
child: SizedBox(
height: 50,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Title'),
Text('Subtitle')
],
),
),
)
],
),
),
Output:

Related

Overlap widget inside card widget in Flutter

I wanted to place two widgets (a text and a picture) inside a card, however the picture should go over the card as the image shows:
But I don't know how to make the picture overlapping the card.
This is my code:
Card(
margin: EdgeInsets.zero,
color: Theme.of(context).colorScheme.primary,
clipBehavior: Clip.antiAlias,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
child: Row(
children: [
Container(
alignment: Alignment.bottomLeft,
margin: const EdgeInsets.all(12),
height: 70,
child: Text(
"This is a text widget.",
style: Theme.of(context).textTheme.bodyText1,
),
),
Image.asset(
'images/picture1.png',
scale: 5,
),
],
),
),
You can use stack widget along with positioned widget to achieve the UI
Stack
Card
Container
Card(
margin: EdgeInsets.zero,
color: Theme.of(context).colorScheme.primary,
clipBehavior: Clip.antiAlias,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
child: Stack(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
alignment: Alignment.bottomLeft,
margin: const EdgeInsets.all(12),
height: 70,
child: Text(
"This is a text widget.",
style: Theme.of(context).textTheme.bodyText1,
),
),
Image.asset(
'images/picture1.png',
scale: 5,
),
],
),
],
),
),
you can use stack under card widget

Texts visibly stacked on each other in flutter

Widget build(BuildContext context) {
return Swipable(
child: Column(
children: [
Container(
height: MediaQuery.of(context).size.height * 0.57,
child: Card(
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(14),
child: Image.network(
widget.urls,
fit: BoxFit.cover,
),
),
),
),
),
Center(
child: Expanded(
child: Text(
widget.usernames,
maxLines: 1,
)),
)
],
),
//onSwipeLeft: () => _returnString(index),
);
}
}
This is my code and i've been adjusting and readjusting for over 3hrs.. I just need the text to show on the image that can be swiped. Please help me. Thanks
image:
Hello I think what you are needing is to use a Stack Widget instead of a Column widget. When using Stacks you can use a Positioned widget to indicate exactly where you want your child widgets to be displayed inside of the stack as well.
Widget build(BuildContext context) {
return Swipable(
child: Stack(
alignment: Alignment.center,
children: [
Container(
height: MediaQuery.of(context).size.height * 0.57,
child: Card(
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(14),
child: Image.network(
widget.urls,
fit: BoxFit.cover,
),
),
),
),
),
Positioned(
top: 16,
right: 16,
child: Center(
child: Expanded(
child: Text(
widget.usernames,
maxLines: 1,
)),
),
)
],
),
//onSwipeLeft: () => _returnString(index),
);
}
}
Happy Coding!
You can use this way
Widget build(BuildContext context) {
return Column(
children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
widget.urls,
fit: BoxFit.cover,
),
),
height: MediaQuery.of(context).size.height * 0.57,
width: MediaQuery.of(context).size.height,
child: Align(
alignment: Alignment.bottomCenter,
child: Text(
widget.usernames,
style: TextStyle(color: Colors.orange),
),
),
),
],
);
//onSwipeLeft: () => _returnString(index),
}

adding rows and columns together using flutter

i am trying to add two-row and 4 columns, I added rows but couldn't add columns, I want them to take the same size so I used expanded()
here is a picture
here is what iam lokking for
i am done with rows but couldn't adds columns
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.black,
title: Text("homepage"),
),
backgroundColor: Colors.yellowAccent[700],
body: SafeArea(
child: Row(
children: [
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(75), // Image radius
child: Image.network('https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(15),
),
),
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(75), // Image radius
child: Image.network('https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(15),
),
),
],
),
),
),
);
Use GridView.
GridView.count(
crossAxisCount: 2,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
children: [
...List.generate(
6,
(index) => ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: Container(
color: Colors.yellowAccent[700],
child: SizedBox.fromSize(
size: Size.fromRadius(75), // Image radius
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
),
)
],
),
Using Row and Column, you need to provide fixed height for each Row.
body: SafeArea(
child: LayoutBuilder(
builder: (context, constraints) => Column(
children: [
SizedBox(
height: constraints.maxHeight * .3,
child: Row(
children: [
...List.generate(
2,
(index) => Expanded(
child: Container(
color: Colors.yellowAccent[700],
padding: EdgeInsets.all(12),
child: ClipRRect(
borderRadius:
BorderRadius.circular(20), // Image border
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
),
)
],
),
),
SizedBox(
height: constraints.maxHeight * .3,
child: Row(
children: [
...List.generate(
2,
(index) => Expanded(
child: Container(
color: Colors.yellowAccent[700],
padding: EdgeInsets.all(12),
child: ClipRRect(
borderRadius:
BorderRadius.circular(20), // Image border
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
),
)
],
),
),
],
),
),
),
return MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.black,
title: Text("homepage"),
),
backgroundColor: Colors.yellowAccent[700],
body: SafeArea(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
children: [
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(size), // Image radius
child: Image.network(
'https://picsum.photos/250?image=9' ,
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(margin),
),
),
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(size), // Image radius
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(margin),
),
),
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(size), // Image radius
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(margin),
),
),
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(size), // Image radius
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(margin),
),
),
],
),
Column(
children: [
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(size), // Image radius
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(margin),
),
),
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(size), // Image radius
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(margin),
),
),
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(size), // Image radius
child: Image.network(
'https://picsum.photos/250?image=9',
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(margin),
),
),
Expanded(
child: Container(
color: Colors.yellowAccent[700],
child: ClipRRect(
borderRadius: BorderRadius.circular(20), // Image border
child: SizedBox.fromSize(
size: Size.fromRadius(size), // Image radius
child: Image.network(
'https://t3.ftcdn.net/jpg/04/33/08/02/360_F_433080252_BWd42il6gVUmQaXIkASbUrHfKMV3fnqg.jpg',
fit: BoxFit.cover),
),
),
margin: EdgeInsets.all(margin),
),
),
],
),
],
),
),
),
);
}
}
this is the answer
I just added a column inside a row with expanded so it take the same size

how to position an image on top of another "card"?

This is my first time here
I face a little problem which is the image that I wanted to put on top of the card do not work properly, the rest of it didn't display
I used (stack & positioned)
What should I do ??
Note : I'm beginner 👀
this is the code :
SizedBox(
width: 500,
height: 100,
child: Container(
child: Padding(
padding:
EdgeInsets.symmetric(horizontal: 10, vertical: 10),
child: Card(
color: Colors.grey.shade400,
child: Stack(children: [
Positioned(
bottom: 40,
left: 150,
child: CircleAvatar(
child: ClipOval(
child: Image.asset(
"assets/images/guy.jpg",
width: 100,
height: 100,
fit: BoxFit.cover,
),
),
backgroundColor: Colors.transparent,
radius: 50,
),
),
]),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
elevation: 10),
),
)),
and this is the the output :
enter image description here
and i wanted to be like this : enter image description here
if you want like that, then you need to put SizedBox and add size (height and or width) on it it acts as invicible widget to put space on it.
Stack
--Positioned (top 0)
----Column
------SizedBox (add height here around 50x50 px)
------Image (100x100 px)
--Card
Try below code hope its helpful to you. refer for thar Stack class here
Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 10),
child: Container(
height: 320,
width: 420,
margin: EdgeInsets.all(16.0),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(18.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Your Other Widgets',
),
],
),
),
),
),
),
Container(
width: 50,
height: 50,
decoration: ShapeDecoration(
shape: CircleBorder(),
color: Colors.transparent,
),
child: Padding(
padding: EdgeInsets.all(1),
child: DecoratedBox(
decoration: ShapeDecoration(
shape: CircleBorder(),
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(
'assets/images/1.png',
),
),
),
),
),
)
],
),
Your Result screen->

making the circular avatar show at the top of the screen

How can I make the circleavatar to be placed at the top of the container
you can use Stack for this. like:
...
return Stack(
children: [
Positioned.filled( child:
Scaffold(
appBar: ...
body: Column([
DecoratedBox(
...
)
]),
)),
Positioned(
top: 24,
child:
CircleAvatar( child:
CachedNetworkImage(
...
),
),
),
],
);
something like that.
Try below code hope its helpful to you.refer Stack class here
Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 21),
child: Container(
height: 200,
width: double.infinity,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
color: Colors.white,
margin: EdgeInsets.all(
16,
),
),
),
),
Container(
width: 100,
height: 90,
decoration: ShapeDecoration(
shape: CircleBorder(),
color: Colors.transparent,
),
child: CircleAvatar(),
)
],
),
Your result screen->