Flutter draw clipPath - flutter

I want to draw two clip-paths on the same page. Unfortunately, I am not successful in it.
Sample

Separate your page into multiple layouts e.g. Stack as a parent and two widgets e.g. Container and clip each path with its own Clipper.
Example:
return Stack(
children: [
Container(
alignment: Alignment.center,
child: ClipPath(
clipper: MyCustomClipper1(),
child: SizedBox(
width: 320,
height: 240,
child: Container(),
),
),
Container(
alignment: Alignment.center,
child: ClipPath(
clipper: MyCustomClipper2(),
child: SizedBox(
width: 320,
height: 240,
child: Container(),
),
),
],
);
Maybe I have few mistakes since I wrote the code directly here, feel free to ask for more details, maybe I can help.

Related

Center-Align one flutter widget in column and position the rest around it

How do I align one widget of a column in the center and put the rest around it?
If I had a Container or so that holds the three input fields and the button and another one that is the box above. How do I align the Container in the middle and put the box in the remaining space without moving the center container?
I tried using Expanded or Flexible but couldnt figure out how to align the widgets in that kind of way.
You can use Column like this:
Column(
children: [
Expanded(
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
height: 40,
width: 40,
color: Colors.yellow,
),
)),
Container(
color: Colors.red,
height: 100,
width: double.infinity,
),
Expanded(
child: Align(
alignment: Alignment.topCenter,
child: Container(
height: 40,
width: 40,
color: Colors.green,
),
)),
],
),

Is there an easier way to adjust the size of an SVG?

I am looking to cut the image of the SVG in half. The SVG is the lighter wave at the bottom of the circle. It is currently too high, and I need to reduce the size by about half. I placed the SVG in a container of its own, but modifying the size of the container isn't exactly modifying the size of the image in ways I would expect. Any suggestion are appreciated.
return Container(
decoration: bubbleBoxDecoration,
height: bubbleDiameter.toDouble(),
width: bubbleDiameter.toDouble(),
child: Stack(
children: [
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
'Upper Body',
style: labelTextStyle,
),
Text(
'45',
style: weightTextStyle,
),
Text(
'lbs',
style: unitTextStyle,
),
],
),
),
Container(
height: bubbleDiameter.toDouble(),
width: bubbleDiameter.toDouble(),
child: SvgPicture.asset(
assetName,
alignment: Alignment.bottomCenter,
),
),
],
),
);
}
}
The key here is the fit parameter. Also, since you want to cut off the bottom and see the top, use Alignment.topCenter.
Container(
height: bubbleDiameter.toDouble() / 2,
width: bubbleDiameter.toDouble(),
child: SvgPicture.asset(
assetName,
fit: BoxFit.fitWidth,
alignment: Alignment.topCenter,
),
),
You can trick the UI while using Stack and make the image size the way you want. You need to resize the image and align properly. The only reason your code-snippet is not reflecting the size because Stack child require a positional widget like Positioned / Align to reflect custom size.
Positioned(
bottom: -100,// bubbleDiameter.toDouble() the way you like to align
child: SvgPicture.asset(
assetName,
height: bubbleDiameter.toDouble() * 2,
width: bubbleDiameter.toDouble() *2,
alignment: Alignment.bottomCenter,
),
),
You cannot modify an asset image in flutter. even if you can, it won't be ideal, because it's an asset, you can remove , edit and add it back, rather than modifying the asset every time you run your app.

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

Incorrect use of ParentDataWidget. I don't think I have much of a choice here, do I?

IgnorePointer(
child: cProtractor & darkModeOn
? Positioned.fill(
child: Align(
alignment: Alignment.center,
child: Center(
child:
Image.asset('lib/assets/img/cprot2white.png',
width: 500.0, height: 500.0),
)))
: SizedBox())
]));
}
}
The above function switches on and off a protractor overlay for my Google Map. Its parent is a body: Stack(children: [. Is there any way to fix this or get rid of the error? The function is working.
You have to remove Ignore pointer as parent widget of Positioned Widget as Positioned widgets are placed directly inside Stack widgets.
You can achieve the same using below code
Positioned.fill(
child: Align(
alignment: Alignment.center,
child: IgnorePointer(
child: Center(
child: Image.asset('lib/assets/img/cprot2white.png',
width: 500.0, height: 500.0),
),
))),
Here just the hierarchy of the widgets are changed

How can I get the Positioned widget to work in a Stack (flutter)?

Is something wrong with this snippet? The positioned element isn't showing up but the others are. deviceHeight is defined elsewhere as the height of the device.
The first container holds the other two containers under it. The second container appears at the top correctly, but the third one (positioned) which should be under the second one doesn't appear. Welcome to hear any alternatives.
Align(
alignment: Alignment.bottomCenter,
child: Stack(children: <Widget>[
Container(
color: Color(bgDark),
height: deviceHeight / 100 * 40,
),
Container(color: Colors.red, height: deviceHeight / 18),
Positioned(
top: 50,
child: Container(
color: Colors.green, height: deviceHeight / 1))
]))
Adding a width to the Positioned Container made it visible.
Align(
alignment: Alignment.bottomCenter,
child: Stack(
children: <Widget>[
Container(
color: Colors.blue,
height: 300,
),
Container(
color: Colors.red,
height: 200,
),
Positioned(
top: 50,
child: Container(
color: Colors.green,
height: 100,
width:100,
),
),
],
),
);
I am not sure about the exact cause of the issue but it seems Positioned needed both height and width dimensions.