Flutter - AnimatedSwitcher isn't smooth - flutter

I've implemented an animation of images, what I wanted to do was create a custom circular spinner with images that switch to give this effect, the problem is that with AnimatedSwitcher for a little fraction of time there's a black space between one image and another.
Here's the code of the animation:
AnimatedSwitcher(
duration: Duration(milliseconds: 200),
child: Image.asset(
values[_index % values.length],
key: UniqueKey(),
height: 50,
width: 50,
),
)
Is there a way to solve this issue or an alternative to AnimatedSwitcher?

The second image might need some time to be loaded into memory. I had the similar issue before but solved it with a workaround. I used a FadeInImage with a transparent placeholder on top of the previous image:
import 'package:transparent_image/transparent_image.dart';
Stack(
children: [
Image(
image: previousImage,
),
FadeInImage(
fadeInDuration: Duration(milliseconds: 300),
placeholder: MemoryImage(kTransparentImage),
image: currentImage,
)
],
),
transparent_image was a dependency I added in pubspec.yaml.

I think precacheImage would be help you. https://api.flutter.dev/flutter/widgets/precacheImage.html
I write a same function like you, but I have not get a black space between image. But if I do not set the Key of Image, then I would got a black space.

Related

how to change image opacity within Image() widget - flutter

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

Flutter place object on top of image

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
),
),
],
)

Image in Flutter streched FittedBox

i m a beginner to flutter and I was trying to Implement some image inside a Container in my app.
Here is my code :
Padding(
padding: const EdgeInsets.fromLTRB(20, 0, 20, 0),
child: Container(
width: 200,
height: 200,
child: FittedBox(
child: Image.asset(
'assets/images/' + i.toString() + ".jpg"),
fit: BoxFit.fill,
),
),
),
My image showed up and it did filled the Container , but it looks horrible . It is super stretched , I tried changing the fit: BoxFit to something like fit : BoxFit.contain but it won't work.
Here is how my UI Looks :
The picture (Display properly but just stretched)
How do I make this image fit without stretching it.
Any answer would be appreciated , and thanks for helping.
When we use Boxfit.fill, the image will take up the complete space of parent container. Aspect ratio here would be secondary. That is why the image looks stretched.
Try Boxfit.cover. Another option would be to equal Container width to double.infinity and adjust the height, as needed.
BoxFit.fill will stretch the image to fill the space.
You should use BoxFit.cover to fill the space without stretching the image.
If you want to make sure the full width of the image is visible, use BoxFit.fitWidth.
If you want to make sure the full height of the image is visible, use BoxFit.fitHeight.

Flutter grey lines around expanded

I am building a flutter web app, and I want to have a carousel slider widget with images. For this I use the carousel_pro package. I want the size to be the width of my carouselslider, which takes up the whole screen's width, and then set the size accordingly, to be the exact size needed. Is there a way to do this?
Now I am settling for a less option, which looks like this:
Flexible(
child: Container(
color: CustomColours.midBlue,
constraints: BoxConstraints(maxHeight: height / 2),
//height: height / 2,
width: width,
child: Carousel(
dotBgColor: Colors.transparent,
autoplayDuration: Duration(seconds: 5),
boxFit: BoxFit.cover,
images: [
AssetImage(
'lib/assets/create-esports-poster-design-in-48-hours.png'),
//AssetImage('lib/assets/Image from iOS.jpg'),
// AssetImage('lib/assets/banner.png'),
],
),
),
),
And I know I could not add a height for a container for it to work, but since this is in a column, it has to have a height. This solution would be good for me, however now the slider has grey lines on top and below it, like this: Is there a way to 1) do what I originally wanted or 2) fix this issue? Thank you very much!

Flare animation not showing up when running app

I am trying to run the below animation, however, it is not showing up on the screen when i run the app. I am using the mediaquery instead of hard coded numbers for the coordinates so that the animation renders in the same place regardless of screen size.
Is there something wrong with the way i am implementing this?
SizedBox(
child: FlareActor(
"assets/animations/finding-pizza.flr",
alignment: Alignment(MediaQuery.of(context).size.width * 0.8,
MediaQuery.of(context).size.height * 0.8,),
fit: BoxFit.contain,
animation: _animationName,
),
),