I have a circleavatar within a card widget but the image is not displaying as intended, how can I fill the card with the image rather than getting this eyeball effect?
Card with image
[Card(
shape: CircleBorder(),
elevation: 10.0,
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 75.0,
child: ClipOval(
child: FadeInImage.assetNetwork(
placeholder:
'lib/screens/shared/defaultprofile.png',
image: userData.profilephoto,
fit: BoxFit.fill,
),
),
),
),
you are using ClipOval class A widget that clips its child using an oval.
By default, inscribes an axis-aligned oval into its layout dimensions and prevents its child from painting outside that oval, but the size and location of the clip oval can be customized using a custom clipper.You can remove it to have your desired view.
CircleAvatar(
Backgroundimage: NetworkImage(url)
...
Also see hw to add assets to you flutter app
Related
So am trying to change image opacity using the opacity property i found in Image() widget, this is a short code to be clear :
Padding(
padding: EdgeInsets.all(10.0),
child: Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(15),
child: Image(
image: NetworkImage(challengeImage),
fit: BoxFit.cover,
height: 150,
width: 350,
opacity: //not sure how to use
),
),
),
),
the image is a network image i retrieved from Firestore and am not sure what is the value i should put if its not double in order to apply opacity on the image. i thought to create a stack and insert asset image as a layer above my image and use the filter property but i would really like to know how the opacity can work with my code above, Thank you.
You can use AlwaysStoppedAnimation or create an Animation<double>
Image(
image: NetworkImage(""),
opacity: AlwaysStoppedAnimation(.1),
),
Another solution : wrap the widget with Opacity Widget
it accepts a double value in range [0,1] where 1 is fully displaying and 0 is not
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
),
),
],
)
I'm making a learning app with flutter.
In our app, you have to put a button over the picture.
So, using positioned on the picture, I made it like the picture below.
#override
Widget build(BuildContext context){
return Scaffold(
backgroundColor: Colors.white,
body: Stack(
fit: StackFit.expand,
children: <Widget>[
Image(
image: AssetImage("assets/oral_structure.png"),
fit: BoxFit.fitWidth
),
Positioned(
top:385, left:17,
child: FlatButton(
child: Text('ㅂ', style: TextStyle(fontSize: 30,fontWeight: FontWeight.bold)),
shape: CircleBorder(),
onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => B()),);
},
)
),//ㅂ
However, the problem with this is that the position of the buttons changes when using a phone with a large screen.
What can be done to prevent this?
The button seems always in the same place. It should be independent of screen size.
I suspect your problem is rather with the fontSize of the text.
Try to remove the fontSize:, it should fix your problem
EDIT 1:
the problem is with fit: StackFit.expand, that forces the button to expand. You can keep it but wrap your button inside a SizedBox
const SizedBox(
width: 200.0,
height: 100.0,
child: FlatButton(// your code here...),
)
Try to get the width and height of screen, and calculate base on that with a radio.
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 loading a rectangle logo saved as a .jpg into a CircleAvatar in my App.
When I am restarting my App, the area where the logo is loading appears blue for a few seconds. Then the real logo appears.
This Widget is found within a Stack.
This is how I transform my 1080x1073 image into a round logo within Flutter.
Container(
width: size.width * 0.5,
height: size.width * 0.5,
child: CircleAvatar(
backgroundImage: AssetImage('assets/images/logo.jpg'),
),
),
Does this happen because my image is too big? How should I handle this problem?
P.S. I am testing this on Visual Studio Code.
By default the background color is set to blue, you can modify the property and it will show whatever color you assign to it.
Container(
width: size.width * 0.5,
height: size.width * 0.5,
child: CircleAvatar(
backgroundColor: Colors.red, //here
backgroundImage: AssetImage('assets/images/logo.jpg'),
),
),
This has more to do with the delay it takes to load an image. You can change the background color like Yudhishthir suggested if the color is the actual problem or you can pre-fetch the image so that the image loads before anything is built.
This answer describes how to do the image pre-fetch using the precacheImage function.
This Cookbook solution is designed for this situation. Just replace the CircularProgressIndicator with whatever you want to show before the image is loaded.
https://flutter.dev/docs/cookbook/images/fading-in-images
Had similar blue background then changed to InkWell:
child: InkWell(
onTap: () async {
myFunc();
},
child: Container(
width: 50,
height: 50,
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(shape: BoxShape.circle),
child: Image.asset(
'assets/images/mybutton.png',
fit: BoxFit.cover,
),
),
),