Ink.image not showing when used in a Column - flutter

The following code shows image
Ink.image(
image: AssetImage('some_image'),
)
but if I wrap it in a Column, it neither shows the image nor any error.
Column(
children: [
Ink.image(
image: AssetImage('some_image'),
),
],
)
What am I doing wrong?

Wrap your widget with Material like this:
Material(
child: Ink.image(
image: AssetImage('some_image'),
fit: BoxFit.cover,
height: 100.0,
width: 100,
),
),

You should add InkWell as the child parameter to Ink along with the onTap parameter to make it work.
Ink.image(
image: const AssetImage("assets/slider/2.jpg"),
height: 200,
fit: BoxFit.cover,
child: InkWell(
onTap: (){},
),
),

Column(
children: [
Container(child:
Ink.image(
image: AssetImage('some_image'),
),
),
],
)

Related

CachedNetworkImage sometimes does not show loaded image unless you interact with the view

As you can see on GIF, CachedNetworkImage() sometimes does not show the loaded image, unless you interact with the page. Please help me figure out why this is happening and how to fix it?
Imgur link for better resolution
SizedBox _buildImage(BuildContext context) {
return SizedBox(
height: MediaQuery.of(context).size.height / 3,
child: Stack(
children: [
Positioned.fill(
child: CachedNetworkImage(
imageUrl: event.pictureUrl,
imageBuilder: (context, imageProvider) {
return Ink.image(
image: imageProvider,
fit: BoxFit.cover,
child: Container(),
);
},
progressIndicatorBuilder: (context, url, downloadProgress) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: 50,
height: 50,
child: CircularProgressIndicator(
value: downloadProgress.progress,
color: Colors.black38,
)),
],
);
},
errorWidget: (context, url, error) {
// ignore: avoid_print
print(error);
return Image.asset('assets/images/error.png');
},
),
),
Container(
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
color: Colors.black,
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.grey.withOpacity(0.0),
Theme.of(context).scaffoldBackgroundColor,
],
stops: const [0.9, 1],
),
),
)
],
),
);
}
I have fixed the problem by changing Ink.image(...) imageBuilder return to:
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: imageProvider,
fit: BoxFit.cover,
),
),
);
Which, theoretically, should be the same. But the issue is now gone.
Please, answer the question if you have details on the issue I'll accept an explaination of this behaviour.

insert 2 images together

I am trying to make this design from figma ui design and need to make the 2 pic inside each other but when i do it there is a space between them also the shaded part in the right pic how can i make it
but it did not work so It comes in this shape
import 'package:flutter/material.dart';
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
Row(
children: [
Expanded(
child: Container(
width: 235,
height: 235,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/images/back1.png',
),
fit: BoxFit.cover,
),
),
),
),
Expanded(
child: Container(
width: 279,
height: 279,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/images/back1.png',
),
fit: BoxFit.cover,
),
),
),
),
],
),
],
),
);
}
}
So what widget or things to add to make the 2 pic mixed
Use Stack and Positioned ,try this:
Stack(
children: [
Positioned(
top: 0,
right: 0,
child: Image.asset(
'assets/images/back1.png',
fit: BoxFit.cover,
width: 235,
height: 235,
),
),
Positioned(
top: 0,
left: 0,
child: Image.asset(
'assets/images/back1.png',
fit: BoxFit.cover,
width: 279,
height: 279,
),
),
],
),
use Row Widget and size the first image to have half screen using MediaQuery
then wrap the Row it's self to stack and add other one over the stack and position it wherever you want !
I think the best way is to export the two images together in Figma, forming a single image. You can do this by selecting both images > Group > Export. So you don't need almost any code to put them together. I know that's not the point, but it's a creative and valid solution for your case. I hope it helps.

Problem I have space in listview between items (Container) with flutter

Problem I have space in listview between items (Container) with flutter
Problem I have space in listview between items (Container) with flutter
this code :
return Scaffold(
body: Column(
children: [
Expanded(
child: ListView(
children: [
Container(
width: width,
height: 220,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/exclusion.png'),
// fit: BoxFit.contain,
),
),
),
Container(
width: width,
height: 220,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/exclusion.png'),
// fit: BoxFit.contain,
),
),
),
],
),
),
],
),
);
The height of the container you provided does not reflect the image height, so the image gets centered try to set fit: BoxFit.fill in the DecorationImage so that you see the actual height you need

How to setup the 3dots menu inside Image.network in flutter

I'm looking an example to implement the 3 dots menu inside a picture on my feed of my app... any ideas?
Example
The example in the question is not to use an icon in the photo. Like this:
Column(
children: [
Row(children: [...,Icon()],),
Image.network(),
],
)
But if you want to use icon in the photo, you can use Stack. Like this:
Container(
height: 250,
width: 250,
child: Stack(
children: [
Container(
child: Image.network(
"https://upload.wikimedia.org/wikipedia/commons/e/eb/Ash_Tree_-_geograph.org.uk_-_590710.jpg",
fit: BoxFit.cover,
),
width: MediaQuery.of(context).size.width,
),
Container(
alignment: Alignment.topRight,
child: Icon(
Icons.more_horiz,
color: Colors.white,
),
),
],
),
)

Flutter Container with Network Image and an Aligned Container at the bottom

So, I have to display an image in a container and some description at the bottom of the container. The image is supposed to fill the entire screen. The image is being fetched from the network.
This is my intial approach
Stack(
fit: StackFit.expand,
children: <Widget>[
Container(
child: ClipRRect(
child: Image.network(category.imageURL,
height: maxHeight * 1, fit: BoxFit.cover),
),
),
Align(
alignment: Alignment.bottomLeft,
child: getNameAndDeleteSection(context),
)
],
),
),
where getNameAndDeleteSection is basically this
return Container(
color: Colors.yellow,
margin: EdgeInsets.fromLTRB(5, 0, 5, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
category.name,
maxLines: 1,
style: TextStyle(color: Colors.white),
),
Spacer(),
IconButton(
icon: Icon(Icons.delete, size: 18.0, color: Colors.white,),
onPressed: () {
deleteTap(category);
},
)
],
),
);
}
When the network image is loaded, it hides the yellow container , but keeps the children. What I want is the image to remain at the background and the yellow container to remain above it. The idea is that the yellow container will have a transparent color of sorts , to make it look floating on the image.
The max height is the height provided by the listView. I'm trying to make the UI adaptive. Any help?
Why not puting your image as a BoxDecoration in your container like this:
Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(url), fit: BoxFit.cover,
),
),
),
Align(
alignment: Alignment.bottomLeft,
child: getNameAndDeleteSection(context),
)
],
),
Instead of using a Container that always seems to get hidden by the Network Image, I decided to use Card that will envelop the container. And it worked.
So, the change was done in the getNameAndDeleteSection and basically wrapped the entire code in a Card. And bingo, it worked.