How to expand Rive animation in Flutter? - flutter

I want to make rive animation background and feel whole screen.
Changing height and width to MediaQuery... does not work. It changes size but proportion stays the same
This is how rive widget looks like for me:
Center(
child: _riveArtboard == null
? const SizedBox()
: Rive(artboard: _riveArtboard),
),
thank you in advance
edit:
SOLUTION
Container(
height: h,
width: w,
child: Center(
child: _riveArtboard == null
? const SizedBox()
: Rive(fit: BoxFit.fill, artboard: _riveArtboard),
),
),

Just adding height and width to his parent Container and add a fit(cover, fill, whatever you need) to your Rive widget
Container(
width: w,
height: h,
child: Rive(
fit: BoxFit.cover,
artboard: ctrl.globalArtboard!,
),
),

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

Positioning widgets at specific image coordinates

I have a set of x/y coordinates which I'd like to use to show widgets on top of an Image widget at those specific coords, relative to the original image dimensions (i.e. coords of 100/100 would show a widget at 100/100 on the image).
I'm currently using a Stack containing the Image and some Positioned widgets, but I can't get them to display in the right place. The positioned widgets aren't displaying in the correct position on the image, possibly because of the image scaling?
Any ideas how I could achieve this? Thanks
For some context, the image is a map and the positioned widgets are pins on the map
Code for the pin widget (top/left is y/x):
Positioned(
top: top,
left: left,
child: GestureDetector(
child: IconTheme(
child: Icon(Icons.location_pin),
data: IconThemeData(
color: available ? Colors.green : Colors.red,
),
),
onTap: () => print("Selected space $spaceId"),
),
);
Code for the interactive viewer + stack:
transformationController: widget._controller,
maxScale: 4.0,
minScale: 0.2,
child: Stack(
children: [
Image.network(
"https://i.pinimg.com/736x/bd/d6/f5/bdd6f5247dbea0e5eedf33fe8cc491ee--office-layout-plan-office-floor-plan.jpg",
fit: BoxFit.cover,
alignment: Alignment.center,
height: double.infinity,
width: double.infinity,
),
...getSpacePins()
FutureBuilder<List<SpacePin>>(
future: spaces,
builder: (context, snapshot) {
if (snapshot.hasData)
return snapshot.data![1];
else if (snapshot.hasError) return Text("Error");
return const CircularProgressIndicator();
},
)
],
),
)
The method getSpacePins() returns a list of pin widgets in to the stack.
I don't have the reputation to directly comment. I've got the same problem but haven't solved it 100% yet, nor found anyone who has the answer. For this place the Image in a Stack Widget. Place layers of pins by looping through your list of pins. Wrap the pins in a positioned widget. The Issue I have here is the X and Y are correct and the math I have is correct but its off set by things like the app bar height and other padding in the scaffold. I can't seem to apply it to the X, Y of the Image on the stack.
for (Pins pin in listOfPins)
Positioned(
top: (pin.y ?? 0) * constraints.maxHeight,
left: (pin.x ?? 0) * constraints.maxWidth,
child: Image.asset(
DRAWINGS_PINS_PATH,
height: 40,
width: 40,
)

How to have Label text with graphics over image(product image of e commerce app) in flutter?

I am trying to get a text label with graphics over the image. Labels like new arrival, best seller, limited, on sale just like on the pic attached.
enter image description here
Here's what i think the skeletal layout would be :
return Stack(
children: [
Card(
color: Colors.black54,
child: Image.asset('assets/xyz.png'),
),
Align(
//for bottomRight
alignment: Alignment.bottomRight,
child: Image.asset(
'assets/fireimg.png',
), //can be an SVG converted to png
),
Align(
//for topLeft
alignment: Alignment.topLeft,
child: Image.asset(
'assets/label.png',
), //can be an SVG converted to png
),
],
);
Feel free to give the Padding of your choice.
it has so much code to write , so i will give some examples to achieve that output
in this image ,i mentioned 0 and one .
for all 1
solution 1
you can use image like this way
Stack(
children: [
Container(
width: 200,
height: 200,
color: Colors.amber,// added only for view this example
child:Image() // add Product image here
),
Positioned(
top: 20, //change according to your use case position
left: 0,// change according to your use case position
child: Container(
color: Colors.black, // added only for view this example
decoration: BoxDecoration(image: ),// add label image here
width: 100,
height: 50,
child: Row(
children: [Text('hi')],
),
))
],
)
solution 2
you can use custom paint for label layout
not that
in both solution you have to use stack and position widgets , you can control position according to your use case
for all 0
you can use RotationTransition widgets to achieve this
not that
you have to use stack and position widgets , you can control position according to your use case
for the vertical Text
use this example
String exText = "meta";
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('hi'),
),
body: Container(
width: 200,
height: 200,
color: Colors.amber,
child: Column(
children: exText.characters
.map((e) => Container(
child: Text('$e'),
))
.toList()),
),
out put will be

Why doesn't flutter properly blur the whole background image?

I'm trying to apply an ImageFilter on to my image but it only blurs part of it and fades off like this:
The Actual Image
Partly Blurred Image
As you can see, most of it is properly blurred but you can make out the bottom part.
How I'm blurring it:
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
ConstrainedBox(
constraints: const BoxConstraints.expand(),
child: Image(image: AssetImage(config.wallpaper), fit: BoxFit.cover),
),
Container(
child: ClipRect(
child: BackdropFilter(
filter: ImageFilter.blur(
sigmaX: config.blur['sigmaX'] ?? 50,
sigmaY: config.blur['sigmaY'] ?? 50),
child: Container(
color: Colors.transparent,
height: 1080,
width: 1920,
),
),
),
)
],
));
}
}
Maybe you can try stacking a translucent container above the image?
Something like this :
Stack(
Image(/*your image*/),
Container(color: Colors.grey.withOpacity(0.6)),
),
You can adjust the color and opacity according to your need. You won't exactly be blurring the image but it will do a good work of hiding that image.

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');
}
}
)
),
);