Flutter container write text over background image - flutter

I want to make a design like following
I build the base layout with background image. Following is the code to achieve that. Now i want to put "Grocery store" Text on top of this image and other widgets. How can i do that ?
Widget build(BuildContext context) {
return Container(
height: 190.0,
width: size.width,
margin: const EdgeInsets.symmetric(
horizontal: 16.0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
child: Row(
children: <Widget>[
Expanded(
child: Container(
width: size.width,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(11.0),
image: DecorationImage(
image: NetworkImage(https://www.exampledomain.com/images/background.jpg),
fit: BoxFit.cover,
),
),
// child: ????
),
),
],
),
),
],
),
);}

child: Container(
width: size.width,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(11.0),
image: DecorationImage(
image: NetworkImage(https://www.exampledomain.com/images/background.jpg),
fit: BoxFit.cover,
),
),
child: Text('Grocery store'),
//padding: <-- Using to shift text position a little bit for your requirement
),

Stack/Align is your friend.
Take a look here https://api.flutter.dev/flutter/widgets/Stack-class.html
Here is a basic example (based in your code):
Widget build(BuildContext context) {
return Stack(
children: [
Align(
alignment: Alignment.center,
child: Container(
alignment: Alignment.center,
color: Colors.red,
height: 190.0,
width: size.width,
margin: const EdgeInsets.symmetric(
horizontal: 16.0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
child: Row(
children: <Widget>[
Expanded(
child: Container(
width: size.width,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(11.0),
image: DecorationImage(
image: NetworkImage(
"http://www.exampledomain.com/images/background.jpg"),
//fit: BoxFit.cover,
),
),
),
),
],
),
),
],
),
),
),
Align(
alignment: Alignment.center,
child: Text("Grocery store"))
]
);
}

Related

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

Flutter How to extend image in appbar?

I have this flutter page
I want this flowers image background to go all over the app bar as well with text MyProfile with other app bar buttons such as drawer and search button overlaying it.
Here is code as of now
Container(
child: Stack(
alignment: Alignment.bottomCenter,
overflow: Overflow.visible,
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: Container(
height: 200.0,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
'https://timelinecovers.pro/facebook-cover/download/stunning-little-flowers-facebook-cover.jpg'))),
),
)
],
),
Positioned(
top: 100.0,
child: Container(
height: 190.0,
width: 190.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
'https://static.displate.com/280x392/displate/2020-06-20/97526a531e9ff32c26f7752ebc926941_07a032cb55575a397e6ba8c98804ad43.jpgD'),
),
border:
Border.all(color: Colors.white, width: 6.0)),
),
),
],
),
),
some change on your code and result:
Widget build(BuildContext context) {
var width = MediaQuery.of(context).size.width;
var height = MediaQuery.of(context).size.height;
return SafeArea(child: Scaffold(
body: Container(
child: Stack(
alignment: Alignment.bottomCenter,
overflow: Overflow.visible,
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: Container(
height: 240.0,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
'https://timelinecovers.pro/facebook-cover/download/stunning-little-flowers-facebook-cover.jpg'))),
),
)
],
),
Positioned(
top: 0.0,
child: Container(
width: width,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
IconButton(icon: Icon(Icons.menu,color: Colors.white,), onPressed: (){}),
Text('My Profile',style: TextStyle(color: Colors.white,fontSize: 22),),
],
),
IconButton(icon: Icon(Icons.notifications,color: Colors.white,), onPressed: (){}),
],
),
height: 52,
),
),
Positioned(
top: 120.0,
child: Container(
height: 190.0,
width: 190.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
'https://static.displate.com/280x392/displate/2020-06-20/97526a531e9ff32c26f7752ebc926941_07a032cb55575a397e6ba8c98804ad43.jpgD'),
),
border:
Border.all(color: Colors.white, width: 6.0)),
),
),
],
),
),
));
}```
You can easily achieve this by setting:
extendBodyBehindAppBar: true property in Scaffold widget.
backgroundColor: Colors.transparent and set elevation: 0.0 in AppBar widget to make it fully transparent.
If true, and an appBar is specified, then the height of the body is
extended to include the height of the app bar and the top of the body
is aligned with the top of the app bar.
This is useful if the app bar's AppBar.backgroundColor is not
completely opaque.
Source: extendBodyBehindAppBar property from Flutter Doc
After this, adjust the height for:
background image
profile image
I copied your code and adjust it with the above solution, see the example below:
#override
Widget build(BuildContext context) {
return Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
title: Text(widget.title),
leading: Icon(Icons.list),
backgroundColor: Colors.transparent,
elevation: 0.0,
),
body: Container(
child: Stack(
alignment: Alignment.bottomCenter,
overflow: Overflow.visible,
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: Container(
height: 300.0,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
'https://timelinecovers.pro/facebook-cover/download/stunning-little-flowers-facebook-cover.jpg'))),
),
)
],
),
Positioned(
top: 180.0,
child: Container(
height: 190.0,
width: 190.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
'https://static.displate.com/280x392/displate/2020-06-20/97526a531e9ff32c26f7752ebc926941_07a032cb55575a397e6ba8c98804ad43.jpgD'),
),
border: Border.all(color: Colors.white, width: 6.0)),
),
),
],
),
),
);
}
Please refer to this property of the Scaffold widget in Flutter. It will do what you want. You might have to resize things a bit. And maybe, make the AppBar color as transparent.

Flutter Row with two container with centered image and text above it. Like in image attached

How to create Row with two containers with centered image and text above image also centered.
Like in image attached.
enter image description here
Is this what you are trying to do:
class ExampleDesign extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Center(
child: Container(
height: 180,
padding: EdgeInsets.symmetric(
horizontal: 5,
),
child: Row(
children: <Widget>[
Expanded(
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
width: 3,
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
height: 60,
width: 120,
padding: EdgeInsets.only(left: 10),
decoration: BoxDecoration(
border: Border.all(
width: 3,
color: Colors.black,
),
),
child: Align(
alignment: Alignment.centerLeft,
child: Text('Image'),
),
),
Text('Some text centered'),
],
),
),
),
SizedBox(
width: 20,
),
Expanded(
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
width: 3,
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
height: 60,
width: 120,
padding: EdgeInsets.only(left: 10),
decoration: BoxDecoration(
border: Border.all(
width: 3,
color: Colors.black,
),
),
child: Align(
alignment: Alignment.centerLeft,
child: Text('Image'),
),
),
Text('Some text centered'),
],
),
),
),
],
),
),
);
}
}
OUTPUT:
I hope this answers your question.
Create a widget using this post How to to display text over the images in Flutter? which returns an image above and a text below, Wrap two of these widgets using a Row. That should work.

Problem in set position with Stack and Positioned in flutter

I'm trying to make a card with "balloon" in top of card Here a example of what i'm trying to do
I'm doin'g in Flutter, the last update, i've tried add stack with positioned, but i got this horrible thing
My code about this is:
Column(
children: <Widget>[
Stack(
children: <Widget>[
Container(
width: 40,
height: 40,
alignment: Alignment.center,
child: Text('1'),
decoration:
BoxDecoration(color: Colors.redAccent, shape: BoxShape.circle),
),
Positioned(
left: 19,
top: 37,
child: Container(
height: 20,
width: 20,
color: Colors.green,
),
),
],
),
Card(
child: Container(
color: Colors.blue,
child: Text('aaaaaaaa'),
),
)
],
);
And my expected response was the link above
Please try this :-
Column(
children: <Widget>[
Container(
alignment: Alignment.topLeft,
child: Column(
children: <Widget>[
Container(
width: 40,
height: 40,
alignment: Alignment.center,
child: Text('1'),
decoration: BoxDecoration(
color: Colors.redAccent, shape: BoxShape.circle),
),
Container(
height: 40,
width: 2,
color: Colors.green,
),
],
),
),
Container(
width: double.infinity,
child: Card(
child: Container(
color: Colors.blue,
child: Text('aaaaaaaa'),
),
),
)
],
)