Is my network image still overflowing, despite the defined width, and why?
Here is a problematic part of the code:
Container(
height: 200,
width: MediaQuery.of(context).size.width, // This may be helpful, but not in my case...
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fitWidth,
image: NetworkImage("${module['thumbnail']}"),
),
),
),
How to fix overflow?
A RenderFlex overflowed by 28 pixels on the right.
Help, I am a newbie in Flutter. Thanks!
Ps. Updated code from top to problematic :
Widget build(BuildContext context) {
return InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SingleModule()),
);
},
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
clipBehavior: Clip.antiAlias,
child: Row(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 200,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage("${module['thumbnail']}"),
),
),
),
Try putting padding: EdgeInsets.only(right: 28), to your Container that wrap around your Image Widget.
Related
I want the container to be in the left side but i am always getting in the center of the screen. I tried using alignment and also used row,column but nothing worked.
Widget _guitarChord(BuildContext context) {
return GestureDetector(
child: Container(
height: 200,
width: 250,
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(12)),
image: DecorationImage(
image: AssetImage('images/worship.jpg'), fit: BoxFit.cover)),
),
onTap: () {},
);
}
I use your method as a child in a column in my body. Pay attention you should add these codes in your column before your children. avoid using of Center widget
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_guitarChord(context),
const Text('KM flutter',style: TextStyle(fontSize: 25),),
],
),
I figured I can draw ripple over an image by enclosing the image in Ink(decoration: BoxDecoration(image: ...)), but how can I do the same for Text?
This is supposed to be a card with an image on top and a title and some other information at the bottom:
#override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final post = _postModel.post;
return Material(
color: theme.colorScheme.background,
child: InkWell(
onTap: () {},
splashColor: Colors.red,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 5),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
if (post.imageUri != null)
// This image IS covered by the ripple (what I need)
AspectRatio(
aspectRatio: 5 / 3,
child: Ink(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3),
image: DecorationImage(
image: NetworkImage('https://picsum.photos/700'),
fit: BoxFit.cover,
),
),
),
),
// This must be underneath the ripple, but isn't.
Text(post.title, style: theme.textTheme.headline5),
Container(
padding: EdgeInsets.symmetric(horizontal: 0, vertical: 5),
color: Colors.transparent,
height: 60,
child: Row(
children: <Widget>[
// This is also covered by the ripple
Ink(
height: 35,
width: 35,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3),
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage('https://picsum.photos/100'),
),
),
),
SizedBox(width: 5),
// This must be underneath the ripple but isn't
Ink(
// decoration: Decoration,
child: Text(
post.author,
style: theme.textTheme.caption,
),
),
Spacer(),
],
),
),
],
),
),
),
);
}
When I press, the ripple covers both images as expected, however, I can't figure out how to make the ripple cover the text widgets as well. I tried wrapping the text in an Ink widget (the last one), but it doesn't work - the text is still displayed over the ripple.
Unpressed:
Pressed (the text is visible):
I am wondering if it is possible to resize an image that is inside of a BoxDecoration container and called by the AssetImage().
My code is:
Flexible(
child: Container(
height: size.height * .75,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(25.0),
image: DecorationImage(
image: AssetImage('assets/img/washing.png'),
fit: BoxFit.scaleDown,
)),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
and follows...
The image is too big. I would like it small and in the top right corner.
Thank you.
Its size depends on your container Size. If you reduce of your container size then The image size automatically reduced. But you must use BoxFit.cover as fit
Here is the code sample -
return Scaffold(
appBar: AppBar(
title: Text('Help'),
),
body: Center(
child: Container(
height: MediaQuery.of(context).size.height * .5,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(25.0),
image: DecorationImage(
image: AssetImage(
'asset/images/download.jpg',
),
fit: BoxFit.cover,
),
),
),
),
);
If you want to developed it without Decorated image I can help you. Please share your sample UI, I will created for you
I am trying to overlay a title on images in Card widget. I am trying to achieve this using Stack widget, it seems to be messing with my constraints. My original widget:
When I add Stack:
As you can see, the text appears but it destroys the layouts. Any idea to why is this happening? to my knowledge Stack is not supposed to affect any constraints(?), it should be floating on top of the existing widget.
My code:
return Card(
clipBehavior: Clip.antiAlias,
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(kDefaultPadding / 2)),
child: Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(kDefaultPadding / 2),
child: FittedBox(
fit: BoxFit.cover,
child: Image.network(widget.data.imageUrl),
),
),
Text("Test")
],
),
);
Add fit: StackFit.expand to the Stack:
Card(
clipBehavior: Clip.antiAlias,
elevation: 3,
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(kDefaultPadding / 2)),),
child: Stack(
fit: StackFit.expand, // this is new
children: [
ClipRRect(
...
Note: Instead of Stack you can use a Container with the image set as its decoration image and the text set as its child:
Card(
clipBehavior: Clip.antiAlias,
elevation: 3,
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(kDefaultPadding / 2)),),
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(widget.data.imageUrl),
),
),
child: Center(child: Text("Test"))),
),
...
I am new in flutter. I want to make the transparent Circle in side the semi transparent rectangle. Look like below,
I have not idea about that. So please help me to make this type of widget in flutter.
Using ColorFiltered and Stack you can achieve this.
(I took the answer mentioned in the comment and edited to your needs)
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: [
Image.network(
'https://lh3.googleusercontent.com/proxy/_wrP_GRGOkGw0FLMiR3qeMzlyC-qN8Dd4sND89_xxLZMDIZh204g8PCccS-o9WaL1RKyiVOLGVS9QpodSkMMhOh8kbNh1CY492197-im-4vlFRRdsVqT2g4QbRlNgljDIg',
fit: BoxFit.cover,
), //Give your Image here
ColorFiltered(
colorFilter: ColorFilter.mode(
Colors.black.withOpacity(0.5),
BlendMode.srcOut,
), // This one will create the magic
child: Stack(
fit: StackFit.expand,
children: [
Container(
decoration: BoxDecoration(
color: Colors.black,
backgroundBlendMode: BlendMode.dstOut,
), // This one will handle background + difference out
),
Align(
alignment: Alignment.center,
child: Container(
height: MediaQuery.of(context).size.width,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(
MediaQuery.of(context).size.width / 2,
),
),
),
),
],
),
),
],
),
);
}