how to add clipper to navigation drawer in flutter - flutter

I have created a navigation drawer.But I don't know how to add clipper using custom_clippers package
I want to add clipper image in the header section of my drawer.
here is the code
Widget _createHeader() {
return DrawerHeader(
// margin: EdgeInsets.zero,
// padding: EdgeInsets.zero,
child:ClipPath(
clipper: SideCutClipper(),
child: Container(
height: 600,
width: 500 ,
color: Colors.pink))
,
// decoration: BoxDecoration(
// image: DecorationImage(
// fit: BoxFit.fill,
// image: AssetImage('path/to/header_background.png'))),
child: Stack(children: <Widget>[
Positioned(
bottom: 12.0,
left: 16.0,
child: Text("Flutter Step-by-Step",
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.w500))),
]));
}

Just Few Edits to brackets and parentheses:
Widget _createHeader() {
return DrawerHeader(
child: ClipPath(
clipper: SideCutClipper(),
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: AssetImage('images/Rectangle-image.png'))),
child: Stack(
children: <Widget>[
Positioned(
bottom: 12.0,
left: 16.0,
child: Text(
"Flutter Step-by-Step",
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.w500),
),
),
],
),
),
),
);
}
Tip
Use , (comma) after parentheses and brackets and reformat your code (Alt + Shift + F in VSCode). This will make debugging a lot easier, helps with documentation, makes code pretty and ... .

Related

Make Container the same size of image in a different widget

I have a card widget which can be flipped. Image on the front side and text on the back.
The problem is that the images can be uploaded by the user, so sizes can vary.
How can I rescale the Container with the text to be the same size as the provided image?
Right now the container takes up all the space it can get, whereas the image is a bit smaller.
Code:
Widget getCardSide(isFlipped) {
if (isFlipped) {
return Container(
padding: const EdgeInsets.all(15),
child: Column(
children: [
Container(
alignment: Alignment.topCenter,
child: Text(widget.title,
style: const TextStyle(
color: textColor,
fontSize: 45,
decoration: TextDecoration.underline,
fontWeight: FontWeight.bold)),
),
Container(
padding: const EdgeInsets.only(top: 30),
child: Text(widget.text,
style: const TextStyle(
color: textColor,
fontSize: 25,
)),
),
],
));
} else {
return Container(
alignment: Alignment.center,
child: Image.file(
widget.image,
),
);
}
}
So how do I resize the container in the If-Block to the same size as the image in the Else-Block?
Try this
remove
alignment: Alignment.center, from the image.. replace your code with this
Widget getCardSide(isFlipped) {
if (isFlipped) {
return Container(
padding: const EdgeInsets.all(15),
child: Column(
children: [
Container(
alignment: Alignment.topCenter,
child: Text(widget.title,
style: const TextStyle(
color: textColor,
fontSize: 45,
decoration: TextDecoration.underline,
fontWeight: FontWeight.bold)),
),
Container(
padding: const EdgeInsets.only(top: 30),
child: Text(widget.text,
style: const TextStyle(
color: textColor,
fontSize: 25,
)),
),
],
));
} else {
return Container(
child: Expand(
child: Image.file(
widget.image,
),
)
);
}
}
After trying a bunch of different things, this seems to fix it:
return Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: FileImage(widget.image),
),
),
);
That way the Image is scaled to the same size as the other container, although it cuts up the edges. Not exactly what I wanted but that works too.

How to put image on top corner and trim it in flutter?

In my mobile app I am expecting the tennis ball image to be there in right top corner
Image Expected
But currently it looks like this,
Image Current
the code is as below,
Expanded(
flex: 9,
child: Column(
children: [
Container(
height: 66,
decoration: BoxDecoration(
color: const Color(0xff3e4982),
borderRadius: BorderRadius.circular(12),
image: DecorationImage(
image: AssetImage(
'assets/transperent_tennis_ball_icon_green.png'),
),
),
),
]
),
)
Please advise how can I get this done?
Try below code hope its help to you. You used Stack widget and Positioned Widget for that. just replace my image with your image.
Center(
child: Stack(
children: [
Container(
padding: EdgeInsets.all(20),
height: 100,
width: 200,
decoration: BoxDecoration(
color: const Color(0xff3e4982),
borderRadius: BorderRadius.circular(12),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Submit Score',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
Text(
'Game Report',
style: TextStyle(
fontSize: 14,
color: Colors.white,
),
),
],
),
),
Positioned(
right: -30,
top: -30,
child: Image.network(
'https://miro.medium.com/max/1400/1*-6WdIcd88w3pfphHOYln3Q.png',
height: 100,
width: 80,
),
),
],
),
),
Your result screen->
you can use stack
Expanded(
flex: 9,
child: Column(
children: [
Container(
height: 66,
decoration: BoxDecoration(
color: const Color(0xff3e4982),
borderRadius: BorderRadius.circular(12),
),
child: Stack(
children: [
Positioned(
top:-25,
right:-25,
child: Container(
height: 66,
width:66,
decoration: BoxDecoration(
shape:BoxShape.circle,
image: DecorationImage(
fit: BoxFit.fill,
image: NetworkImage("https://picsum.photos/500/300?random=1"),
),
),
)
)
])
)]
),
),
just use stack widget to achive this design .

flutter Problem : How to make Upcoming section in Top Right in card

I want to make Upcoming section in top right but I am not understatig how to do it.
I want to make Upcoming section in top right but I am not understatig how to do it.
I want to make Upcoming section in top right but I am not understatig how to do it.
This is ny code
InkWell(
onTap: () {
// Navigator.pushReplacement(
// context,
// MaterialPageRoute(
// builder: (context) => HomePage(),
// ),
// );
// setState(() {
// isSelect = 1;
// });
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0),
child: SizedBox(
height: 147,
width: MediaQuery.of(context).size.width,
child: Stack(
alignment: Alignment.center,
children: [
Stack(
children: [
Container(
padding: EdgeInsets.only(right: 15, left: 15),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
image: DecorationImage(
image: AssetImage("assets/orange_card.png"),
fit: BoxFit.fill,
),
),
height: 147,
width: MediaQuery.of(context).size.width,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(top: 16.0),
child:Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Explorer Package",
style: TextStyle(
fontSize: tSize18,
fontWeight: FontWeight.w500),
),
SizedBox(
height: 6,
),
Text(
"Best package for price",
style: TextStyle(
fontSize: tSize14,
),
),
SizedBox(
height: 13,
),
Text(
"\$99 USD",
style: TextStyle(
fontSize: tSize27,
fontWeight: FontWeight.w500),
),
],
),
),
Padding(
padding: EdgeInsets.only(bottom: 8),
child: Image.asset(
'assets/onbb.png',
height: 114,
width: 114,
),
),
],
),
),
Positioned(
bottom: 130,
right: 0,
child: Container(
decoration: BoxDecoration(
color: Color(0xff158998),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10),
topRight: Radius.circular(20),
),
),
width:160,
height: 25,
child: Center(
child: Text(
'Upcoming Plans',
style: TextStyle(
color: Colors.white,
fontSize: tSize14,
),
),
),
),
),
],
),
Positioned(
width: 18,
bottom: 0,
child: Center(
child: Container(
height: 15,
width: 15,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(50),
),
child: Theme(
data: ThemeData(
//here change to your color
unselectedWidgetColor:
Color(0xff3a99a4),
),
child: Radio(
activeColor: Colors.green,
overlayColor:
MaterialStateProperty.all(
Colors.red),
value: isSelect,
groupValue: 1,
onChanged: (int? value) {
// setState(() {
// isSelect = value!;
// });
},
),
),
),
),
),
],
),
),
),
),
In actuall i want like this
But It becoming like this. I want Upcoming section which is in top right.
It would probably make your life easier to clean up the code. You have multiple stacks, which is usually a sign the layout can be simplified. But your problem can be fixed in a couple of small changes. The explanation and an image of running app is below the code.
Upcoming Plans Changes:
Positioned(
// bottom: 130,
top: 0,
right: 0,
child: Container(
alignment: Alignment.center,
decoration: const BoxDecoration(
color: Color(0xff158998),
borderRadius: BorderRadius.all(Radius.circular(20)
),
),
width:160,
height: 28,
child: const Center(
child: Text(
'Upcoming Plans',
style: TextStyle(
color: Colors.white,
fontSize: 14,
),
),
),
),
),
Explorer Package container change
Container(
margin: const EdgeInsets.all(10),
padding: const EdgeInsets.only(right: 15, left: 15),
The container with "Explorer Package" and the one with "Upcoming plans" (layered above it) need to have offsets, either by Position or margin.
First, anchor the "Upcoming Plans" to the TOP, not the bottom. That way, no matter how high the explorer package is, it will look ok. Then, set the margin for the Explorer container to offset it from the package.
Finally, I think you want symmetric radii for the Upcoming Plans container border.
I've adapted the code and ran it. I changed some of the background colors so you can clearly see what I'm doing. I think you want it to look like this:
Again, it would make it MUCH easier for you and others in the future if you simplify the layout. Use one stack and try to remove the fixed heights. It makes your card harder to reuse (especially if you get new graphics assets). Good luck.

Flutter Layout :- how to build this layout

I want to align the text to the center inside the image as shown in the image.
I recently started working with flutter please help me to achieve the layout.
Container(
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.fromLTRB(24, 20, 24, 0),
child: Stack(
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.circular(16.0),
child: Image.asset(
'assets/images/car.jpg',
fit: BoxFit.cover,
),
),
Positioned.fill(
child: Align(
alignment: Alignment.center,
child: Text(
'Cars',
style: TextStyle(
fontFamily: 'Welcome',
fontSize: 30,
color: Colors.white),
),
),
)
],
),
)
With the help of the above code, the text is appearing in the bottom-center instead of the center.
return Container(
width: MediaQuery
.of(context)
.size
.width,
margin: EdgeInsets.fromLTRB(24, 20, 24, 0),
child: Stack(
alignment: Alignment.center,
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.circular(16.0),
child: Image.asset(
Images.image1,
fit: BoxFit.cover,
),
),
Text(
'Cars',
style: TextStyle(
fontFamily: 'Welcome',
fontSize: 30,
color: Colors.white),
)
],
),
);

How to align text over image in flutter?

I want to align the text over the image to the bottomLeft corner, but even aligning it to the bottomLeft it still stays at topLeft corner. So, help me to know what's wrong or missing in my code to acheive the following image text layout.
My output
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: <Widget>[
Container(
width: 300,
height: 220,
alignment: Alignment.bottomLeft,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/image1.png'),
fit: BoxFit.cover),
),
child: Column(
children: <Widget>[
Text(
"Jerusalem",
style: TextStyle(
fontFamily: 'AirbnbCerealBold',
fontSize: 28,
fontWeight: FontWeight.bold,
color: Colors.white),
),
Text("1,243 Place", style: TextStyle(
fontFamily: 'AirbnbCerealBook',
fontSize: 14,
color: Colors.white),
),
],
),
),
Container(
width: 300,
height: 220,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/image3.png'),
fit: BoxFit.cover),
),
),
],
),
),
Use a stack with fixed height and width, then use a Positioned/Align/ any absolute positioning widgets to place anywhere in the box. Beware the stack order is last child is first on screen
The Stack widget will place widgets on top of each other with no responsiveness to each other only to the parent Stack - like Absolute child to relative parent in CSS/HTML
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: <Widget>[
Container(
width: 300,
height: 220,
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Image(
fit: BoxFit.cover,
image: AssetImage('assets/image1.png'),
),
Positioned(
bottom: 0,
left: 0,
child: Column(
children: <Widget>[
Text(
"Jerusalem",
style: TextStyle(
fontFamily: 'AirbnbCerealBold',
fontSize: 28,
fontWeight: FontWeight.bold,
color: Colors.white),
),
Text(
"1,243 Place",
style: TextStyle(
fontFamily: 'AirbnbCerealBook',
fontSize: 14,
color: Colors.white),
),
],
),
),
],
),
),
],
),
)