Is there some simple way display any image from folder in flutter? - image

I was googling but without luck, I found some stackoverflow with making list of images, randomizing it etc but it seems really long process of what I want and I'm thinking If there is some simpler way of doing this.
What I want is, instead of specifying images/image3.jpg. Can I say to display image from a folder called "bluethemedimages" ? - So it will display randomly/any image from this folder. What i want to create is to have 4 different themes, Blue, Yellow, Green, Grey (Each theme will have different coloured images) so later on when the user presses "blue" button it will display any random image from the "bluethemedimages" folder. Below is example of my page and box decoration with the image.
Widget build(BuildContext context) => Container(
//color: Colors.transparent,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("images/image3.jpg"), fit: BoxFit.cover)),
Thank you so much for help!

Here is a code that I used in my application
Widget build(BuildContext context) => Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("randomimage"), fit: BoxFit.cover)),)))
onclick(){
var _random = new Random();
setstate((){
randomimage="Bluethemedimage/$(_random.nextInt(no_of_pictures)+1)"}}
name your pictures as 1.png,2.png,3.png and so on

Related

How to fit image into a box of all aspect ratio?

I'm dealing with the template png which has a boxed place where I need to fit any size image within that box. How can fit all dimension image to fit in that box in flutter?. I have attached the image.
I need to add image in that black area which is PNG image and what I tried to implement is here.
body: Stack(
children: [
Positioned(
top: MediaQuery.of(context).size.height / 3.5,
right: MediaQuery.of(context).size.width / 10,
child: imagePicked == null
? SizedBox()
: AspectRatio(
aspectRatio: 1,
child: Image.file(imagePicked, fit: BoxFit.fill),
),
),
const Positioned.fill(
child: Align(
alignment: Alignment.centerRight,
child: Image(image: AssetImage('assets/images/notice.png')))),
],
),
But Here I couldn't manage all dimension images. Please help me sort to fit any dimension image into that black box which is also a template image.
The main issue is here overlaying with stack's widgets.
Widget render prioritize bottom to top level on Stack.
In your code-snippet, place-holder is the bottom widget, and it is being prioritized over the selected image.
That's why putting place-holder as 1st widget on stack solve the issue.

Card Carousel swipe with details in flutter

I want to create a stack of images with a carousel effect, details of the image will be displayed below in a different container. While swiping an image from the stack, details will be changed with the image.
Already done with the image carousel part and swiping.
CarouselSlider(
viewportFraction: 0.7,
aspectRatio: 1,
autoPlay: true,
enlargeCenterPage: true,
items: carouselList.map(
(image) {
return Container(
margin: EdgeInsets.all(5),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(10),
),
image:
DecorationImage(image: AssetImage(image), fit: BoxFit.cover),
),
);
},
).toList(),
);
How to change the details of the image while swiping an image from the stack?
Want to achieve a slider like the below image.
Have you checked out this in the package where you can create your own dynamic tree:
CarouselSlider.builder(
itemCount: 15,
itemBuilder: (BuildContext context, int itemIndex) =>
Container(
child: Text(itemIndex.toString()),
),
)
your carouselList will be list of class object where you have the title,release_date , ratings and the image. passing the list to the builder will render the every object up to that length.
Maybe I am late but check this package

Flutter CircleAvatar - Using Image object as (background) image / typecasting it to ImageProvider

I am trying to show a CircleAvatar at the top of the main screen of my App, but I am running into a rather silly issue. I am unable to figure out how to provide an object of the class Image (that is a property of a user) as an ImageProvider, which is what CircleAvatar expects. Is there an easy way to "typecast" here or some other way people have resolved this?
class _HomePageState extends State<PictureShowcaseHome>{
Appuser appuser = new Appuser();
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: InkWell(
child: CircleAvatar(
backgroundImage: appuser.img,
child: Text(appuser.name.substring(0,1).toUpperCase()),
) ,
),
...
To simplify things, assume an Appuser has just the following properties:
class Appuser{
String name;
Image img;
Appuser(){
this.name = "Unknown user";
this.img = Image.asset('assets/imgs/default1.jpg');
}
}
My idea is that I have a default image that is included in the assets, but the user can replace it with their own image (seems like a rather standard idea). I considered switching to AssetImage img; and img = new AssetImage('assets/imgs/default1.jpg'); in the constructor for Appuser, but that sort of seems backwards. It also gets me into the "opposite" problem, when I display the user image on a user information details page (I thought of just having a ListTile( title: appuser.img,),) or when I let the user take a new user picture with the camera. For those purposes, it is easiest to directly work with an object of class Image, not an AssetImage.
Or am I somehow looking at this the wrong way?
This
Image.asset('assets/imgs/default1.jpg').image
should work.
For the sake of clarity, the Image class has an ImageProvider property. Just get the ImageProvider using .image with any given Image class. This works for Image.asset, .file, .network, and .memory
.image will give you the ImageProvider that is needed.
CircleAvatar(
backgroundColor: Colors.red,
radius: radius,
child: CircleAvatar(
radius: radius - 5,
backgroundImage: Image.file(
profileImage,
fit: BoxFit.cover,
).image,
),
)

How to change RGB configuration of an image in Flutter

I want to put a color filter over an asset image.
As below, I currently have an image with colorBlendMode filter, but I want to be able to directly fix the RGB value of each pixel of the image.
Does anyone know how this can be done?
body: Center(
child: new Image.asset(
'assets/gallery/garrowby_hill.jpg',
width: size.width,
height: size.height,
fit: BoxFit.fill,
color: Color.fromRGBO(redCount, greenCount, blueCount, 1),
colorBlendMode: BlendMode.multiply,
),
),
You can use a ColorFiltered class and use your image as it's child and use colorFilter property ,
TODO:
Wrap your Image.asset in a new Widget called ColorFiltered
add a new property for this widget : colorFilter: ColorFilter.mode(your_color_here, BlendeMode.your_blendMode_here).
You can check those links : ColorFilter Class, colorFilter propery and it's used in this video

How to make specific part of image as background Image?

How can I make the selected part in the image below as my background image?
You can use alignment property of Image or DecorationImage combined with fit.
Image.network(
'url',
alignment: Alignment.center,
fit: BoxFit.cover,
);

Resources