I try to recreate the following image in Flutter web, I understand how to do almost everything, except the profile box that is above the image,
How can I put an object on top of an image?
Use Stack to put widgets on each other ,if you want to put widget on specific position use Positioned
i suggest you to read this article
This is an example of placing object on the top of an image:
Stack(
children: [
// Background image placed in the center of Stack
Center(
child: Image.network(
'https://interactive-examples.mdn.mozilla.net/media/cc0-images/grapefruit-slice-332-332.jpg'),
),
// Blue container 50x50 placed on the top of an image
Center(
child: Container(
width: 50,
height: 50,
color: Colors.blue
),
),
],
)
Related
I am trying to have a welcome screen like this:
I have all the lines from the bottom and the orange and blue bubbles as asset images. How can I stack them all together and then use Text() widget for the writing part?
You can use the Stack widget to stack its children if that answers your question:
Stack(
children: [
your_images_here,
your_text_here,
],
);
You can do it without using stack by using the image property in container decoration.
Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/images/bg.png',
),
fit: BoxFit.cover,
)),
child: Column(
children: [
// your text widgets
])
),
So I had three images, and I couldn't use Imageprovider to use it as a background image of my main Container(). But, I decided to make a difference in my design by wrapping them all together using adobe photoshop and getting one image instead of three so that I can use ImageProvider instead of a stack. Then I used Decoration image and made the image the background of my page.
I want to decorate a container with a single stripe down the middle with white on each side like in the picture, I'm guessing I need to use Linear Gradient but I am struggling to get it right.Any Ideas?
Single Stripe Pic
Easy, You need to create a container and make a child of it as Stack and further create a container with aligned it to center. Give it some width and decorate it with linear gradient that's all
Here's some code I've written to help you. Feel free to customize on top of it and use within your app. Cheers!
Container(
width: 200,
height: 150,
color: Colors.white,
child: Stack(
children: [
Align(
alignment: Alignment.center,
child: Container(
width: 50,
color: Colors.red,
),
)
],
),
);
Context
Let's imagine I'm building an app for an amusement park like Disney World or something. There's a tab where I want to display the map of the place so the visitor can find his way/position. I want the map to be huge for it is more easy to look at.
What I have
I'm displaying an image that exceed the width of my phone screen (on purpose) using InteractiveViewer to span and zoom in and out. With spanning the image I'm able to access every pixel of the image. It currently looks like this (I replaced my map with a pikachu image) :
What I want
What I would like is that when I land onto this page, the pikachu is automaticcaly displayed centered, like this, where I'd be able just like before to span left and right and zoom to access every desired pixel of the image :
My code
Container(
height: 650,
width: 420,
child: InteractiveViewer(
constrained: false,
panEnabled: true,
child : Container(
width: 830,
height: 650,
child: ClipRRect(
borderRadius:BorderRadius.circular(5) ,
child: Image.asset(
'assets/images/pikachu.png',
fit: BoxFit.cover,
),
),
)
),
)
Question
Is there a way to achieve this without relocating the Container ? The only solution I can imagine is to move the Container to the left, beginning before my phone screen.
You should try below code just change your image name and app bar name(Dashboard) replace by my
image name
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Dashboard'),
),
body: Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(5),
child: Image.asset(
'assets/images/log.png',
fit: BoxFit.cover,
),
),
),
);
}
}
Your Output look like this
I am trying to make a layout as seen in the image in Flutter, but I don't get how to create a background with two colors and an overlapping button.
I don't know if there is a widget able to do this or need some code...
Any suggest or help will be great! (this was my very first post ever, sorry if there is something wrong about it!!)
Thanks.
Do something like this.
body: Stack(
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width,
height: 300,
color: Colors.grey,
),
],
),
Positioned(
top: 280,
left: 50,
right: 50,
child: RaisedButton(
color: Colors.white,
child: Text("Your Button"),
onPressed: () {},
),
)
],
),
you will get
Let me know if it works
One possible approach is to use a Stack. Set the background color to your grey (i think, color blind), add the white piece as an image positioned at the bottom. Lastly add your button, again positioned at the bottom.
On closer inspection of your image, I now see that what I thought was an image at the bottom was actuall just a color. All you need are two Container s and a button in a Stack. The first Container should fill the whole space, the second Container should have a height setting (be responsive here for multiple device sizes) and lastly add your RaisedButton.
Basically I need to create some kind of Snackbar widget that can be created on any page. So I need to make it positioned relative to the screen. The only idea is to create the main Stack widget which will wrap all other pages. Do you have any other ideas? I found pretty similar question without any interesting answers
By using Mediaqueryto retrieve the screen size.
For example we can the screen width like this :
MediaQueryData screenSize = MediaQuery.of(context).size.width;
let's say i want my container's size to take up half the screen's size
One way to go about it is like this :
Container(
height: MediaQuery.of(context).size.height/2,
width: MediaQuery.of(context).size.width/2,
child: Text('This container is half this device screen's size');
);
What you are going for here is using the Positioned widget
Let's take the last example and leave a quarter of the screen on every side :
Container(
height: MediaQuery.of(context).size.height/2,
width: MediaQuery.of(context).size.width/2,
child: child: Stack(
children: <Widget>[
Positioned(
left: MediaQuery.of(context).size.width/4,
top: MediaQuery.of(context).size.height/4,
right: MediaQuery.of(context).size.width/4,
bottom: MediaQuery.of(context).size.height/4,
child: Text('This container is half this device screen's size'),
),
],
),