Flare animation not showing up when running app - flutter

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

Related

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!

How do I show more or less of an element depending on window size?

I would like to have a banner widget, probably a VideoPlayer (from the video_player plugin) or else just an image.
Depending on the size of the screen/window I want my banner to follow like this:
https://i.imgur.com/YADZSrV.mp4
Imagine that the scaling in the video is the window size changing.
Basically:
If aspect gets wider than the original -> show less on top and bottom (kinda zooming in)
If aspect gets taller than the original -> show less on the sides (kinda cropping while centering)
I got something to work partially. It works when making the window wider, but when it gets slimmer it just starts to scale everything down, it doesn't keep the full height while showing less on the sides.
Here is my work in progress:
return ClipRect(
child: OverflowBox(
maxWidth: double.infinity,
maxHeight: double.infinity,
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: VideoPlayer(_controller),
),
),
);
This can be solved very easily by using the FittedBox widget and the BoxFit enum.
FittedBox(
fit: BoxFit.cover,
child: Container(
width: 960,
height: 360,
child: VideoPlayer(_controller),
),
)
Using the VideoPlayer widget as a child of a Container where I set the size to the original size of the video.
Example using an image:
FittedBox(
fit: BoxFit.cover,
child: Image(
image: NetworkImage(
'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg'),
),
)
You can use LayoutBuilder to get the size of its content and render differently accordingly:
https://api.flutter.dev/flutter/widgets/LayoutBuilder-class.html
In you case, it would be something like this :
return ClipRect(
child: OverflowBox(
maxWidth: double.infinity,
maxHeight: double.infinity,
child: LayoutBuilder(
builder: (context, constraints) {
if (constaints.bigger.width > constaints.bigger.height) {
return Text('More width than height');
}
else {
return Text('More height than width');
}
}
)
),
);

How to avoid Image Area showing Blue before Loading App

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

Using flutter to make create card for UI that begins at very bottom of screen

I am trying to make a design similar to that in the picture below, where a card begins at the very bottom of the screen. Is there a way to do this formally with flutter?
Right now, moving the card low enough so that it flows over the bottom of the screen works but I am hoping there is a more elegant way to achieve this effect.
I think that the best solution for this is using a bottom sheet, with showBottomSheet or showModalBottomSheet (documentation here).
You can see two examples in the Flutter gallery:
https://github.com/flutter/flutter/blob/master/examples/flutter_gallery/lib/demo/material/persistent_bottom_sheet_demo.dart
https://github.com/flutter/flutter/blob/master/examples/flutter_gallery/lib/demo/material/modal_bottom_sheet_demo.dart
Another alternative is use the bottomSheet property of the Scaffold widget there you can set any Widget that you want.
Just wondering if you've considered this Align class
Center(
child: Container(
height: 120.0,
width: 120.0,
color: Colors.blue[50],
child: Align(
alignment: Alignment.bottomCenter,
child: FlutterLogo(
size: 60,
),
),
),
)

Flare and Flutter with different devices (screens)

i am doing my first steps with flare and flutter and right now its really nice to be able to put animations into flutter without coding them by hand. But i dont understand how to make the flare thingy responsive (how to support different screen sizes).
This is part of a splash screen:
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color.fromRGBO(250, 224, 61, 1.0),
body: Center(
child: Container(
child: FlareActor(
"assets/flare/splash.flr",
callback: (nameOfAnimation) =>
Navigator.pushReplacementNamed(context, "/login"),
fit: BoxFit.none,
animation: "splash",
)),
));
}
This works well on my iPhone X because the animation is designed for that size. Is there any way how a smaller device can be able to use this same flare animation? Testing this with iPhone SE resulted in a clipped animation.
I hope there is another way than creating several animations for several screen sizes.
Just add your animation as a child of a SizedBox and give it a width/height and you’ll be fine.
You can also use the MediaQuery.of(context).size.width or height to get the viewport dimensions and set your SizedBox to use a % of the screen accordingly, if you want to.
you can use MediaQuery with the current context of your widget and get width or height in your container or sizedbox like this
width: MediaQuery.of(context).size.width * 0.65
height: MediaQuery.of(context).size.width * 0.65
else If you have a single widget you can use a FractionallySizedBox widget to specify a percentage of the available space to fill
FractionallySizedBox(
widthFactor: 0.7,
heightFactor: 0.3,
child:FlareActor(
"assets/flare/splash.flr",
callback: (nameOfAnimation) =>
Navigator.pushReplacementNamed(context, "/login"),
fit: BoxFit.none,
animation: "splash",
)),
);