Custom card or container with border, shape and three parts - flutter

How can i create following flutter widget.
I want to use it in a column to navigate to the next page.
I've already tried a card or a container consisting of a row with three expandables. But either the red area with the icon overlaps the container with the rounded edges, or it is smaller than the container. What can I do or maybe someone has a code example?

You could create your own custom widget.
Here's a code sample you could use:
class MyWidget extends StatelessWidget {
final double height;
final Function onTap;
MyWidget({this.height = 40.0, this.onTap});
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => onTap(),
child: Container(
decoration: BoxDecoration(
color: Colors.red,
border: Border.all(color: Colors.red),
borderRadius: BorderRadius.circular(10),
),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(8),
child: Icon(Icons.inbox, color: Colors.white),
),
Expanded(
child: Container(
padding: const EdgeInsets.only(left: 8),
alignment: Alignment.centerLeft,
height: height,
decoration: BoxDecoration(color: Colors.white),
child: Text(
'ARCHIV',
style: TextStyle(
color: Colors.red,
fontWeight: FontWeight.bold,
),
),
),
),
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
BorderRadius.horizontal(right: Radius.circular(10)),
),
height: height,
child: Icon(Icons.arrow_forward_ios, color: Colors.red),
),
],
),
),
);
}
}
Try full code on DartPad
Result:

Related

How to add ripple effect to a Container with decoration in Flutter?

I want to add a ripple effect to a custom Container. I have used Inkwell and Material widgets to achieve this behavior, but it does not work. The code is as follows:
#override
Widget build(BuildContext context) {
return Center(
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: (){},
child: Container(
width: 150,
height: 100,
decoration: BoxDecoration(
border: Border.all(color: Colors.red, width: 2),
borderRadius: BorderRadius.circular(18),
color: Colors.deepPurpleAccent,
),
alignment: Alignment.center,
child: Text(
"A box container",
style: TextStyle(color: Colors.white),
),
),
),
),
);
}
The result is:
I also used a transparent color on Container and the purple color on Material as follows:
#override
Widget build(BuildContext context) {
return Center(
child: Material(
color: Colors.deepPurpleAccent,
child: InkWell(
onTap: () {},
child: Container(
width: 150,
height: 100,
decoration: BoxDecoration(
border: Border.all(color: Colors.red, width: 2),
borderRadius: BorderRadius.circular(18),
color: Colors.transparent,
),
alignment: Alignment.center,
child: Text(
"A box container",
style: TextStyle(color: Colors.white),
),
),
),
),
);
}
As a result, the ripple effect occurs, but the Container looks like this (not what I want):
I also swapped the Container and Material widgets with each other, applied clip on the Container as follows:
#override
Widget build(BuildContext context) {
return Center(
child: Container(
width: 150,
height: 100,
decoration: BoxDecoration(
border: Border.all(color: Colors.red, width: 2),
borderRadius: BorderRadius.circular(18),
color: Colors.transparent,
),
clipBehavior: Clip.hardEdge,
child: Material(
color: Colors.deepPurpleAccent,
child: InkWell(
onTap: () {},
child: Center(
child: Text(
"A box container",
style: TextStyle(color: Colors.white),
),
),
),
),
),
);
}
Again, the ripple effect occurs, but the Container does not look as I want to (you can spot the little difference between the following photo and the first photo, in the edges of the Container):
I want the Container to look exactly as in the first photo with a ripple effect.
Note: The behavior that I want, can be exactly achieved through using Ink and Inkwell widgets, but when used in a ListView, it causes item render problems.
You were very close. You needed to have borderRadius on Material and InkWell. Try it this way
child: Material(
color: Colors.deepPurpleAccent,
borderRadius: BorderRadius.circular(18),
child: InkWell(
borderRadius: BorderRadius.circular(18),
onTap: () {},
child: Container(
width: 150,
height: 100,
decoration: BoxDecoration(
border: Border.all(color: Colors.red, width: 2),
borderRadius: BorderRadius.circular(18),
color: Colors.transparent,
),
alignment: Alignment.center,
child: Text(
"A box container",
style: TextStyle(color: Colors.white),
),
),
),
),

Flutter add Text styling to a custom class

I want to add text styling to the Score class in this widget. I have another widget that uses this widget to generate a circle with a number in it.
Center(
child: Container(
width: 100.0,
height: 100.0,
decoration: BoxDecoration(
color: Colors.grey[600],
shape: BoxShape.circle,
),
child: Score(score: 'score',
// Are you looking for something like this
class CenterClass extends StatelessWidget {
const CenterClass({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
width: 100.0,
height: 100.0,
decoration: BoxDecoration(
color: Colors.grey[600],
shape: BoxShape.circle,
));
}
}
YOu can achieve same via Widgets
Widget circleContainer() {
return Container(
width: 100.0,
height: 50.0,
decoration: BoxDecoration(
color: Colors.grey[600],
shape: BoxShape.circle,
));
}
I think you wanted to like A BALL that show the score of ball like below image
If I Am Right then code is below
Container(
width: 27,
height: 27,
child: Padding(
padding: const EdgeInsets.all(1),
child: Container(
child: Center(
child: Text(
'4',
style: TextStyle(
color: Colors.white,
fontWeight:
FontWeight.bold,
fontSize: 11,
fontFamily: 'Tahoma',
),
),
),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Color(0xffffc11c), // inner circle color
),
),
),
),

Create circle around a letter in flutter

I was trying to create a circle around a letter here is my code, but it was not creating a perfect circle
Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
border: Border.all(color: Colors.white, width: 2)),
child: InkWell(
child: Text(
"A",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 15),
),
),
),
I've also tried with height and width of the Container then some portion of letter is hidden.
Container(
height: 30,
width: 30,
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
border: Border.all(color: Colors.white, width: 2)),
child: InkWell(
child: Text(
"A",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 15),
),
),
)
But if I use Icon Widget instead of text widget it was creating perfect circle,
Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
border: Border.all(color: Colors.white, width: 2)),
child: InkWell(
child: Icon(
Icons.add,
color: Colors.white,
),
),
),
Use this:
CircleAvatar(
backgroundColor: Colors.blue,
child: Text("A"),
);
You can also make use of the many other flags in CircleAvatar, like maxRadius or foregroundImage, like this:
CircleAvatar(
backgroundColor: Colors.blue,
child: Text("A"),
maxRadius: 30,
foregroundImage: NetworkImage("enterImageUrl"),
);
Looks like this:
For Containers, you can use the shape property to give it a circular shape.
It would be something like this :
Container(
decoration: BoxDecoration (
shape: BoxShape.circle,
),
child: ....
)
If I face multiple widget I prefer by creating a widget and wrapping others.
Container BoxShape.circle, depends on height
class WrapWithCircle extends StatelessWidget {
final Widget child;
late final EdgeInsets edgeInsets;
late final Color color;
WrapWithCircle({
Key? key,
required this.child,
this.edgeInsets = const EdgeInsets.all(8),
this.color = Colors.white,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.center,
padding: edgeInsets,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: 2,
color: color,
),
),
child: child,
);
}
}

How to build a proper card in flutter?

I am developing a flutter application where I want to use a card but I am not getting the desired result.
I want the this with an image to left side also:
But what I am getting is:
Following is my code:
class CommunityCard extends StatelessWidget {
#override
Widget build(BuildContext context) {
// TODO: implement build
return Card(
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
),
borderRadius: BorderRadius.all(Radius.circular(20))),
child: Wrap(
direction: Axis.horizontal,
children: [
SizedBox(
width: 5,
),
Container(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
),
borderRadius: BorderRadius.all(Radius.circular(20))),
child: Icon(
Icons.sports_cricket,
size: 15,
color: Colors.blue,
),
),
Text(
'Sports',
style: TextStyle(fontSize: 15),
),
Icon(
Icons.cancel_outlined,
size: 15,
)
],
),
),
);
}
}
Can someone help me how to do this please?
class CommunityCard extends StatelessWidget {
#override
Widget build(BuildContext context) {
// TODO: implement build
return Card(
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
),
borderRadius: BorderRadius.all(Radius.circular(20))),
child: Padding(
EdgeInsets.symmetric(horizontal:10.0,vertical:8.0), //Keep experimenting with values till you get the correct one
child: Wrap(
direction: Axis.horizontal,
crossAxisAlignment: WrapCrossAlignment.center,//The change
children: [
SizedBox(
width: 5,
),
Container(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
),
borderRadius: BorderRadius.all(Radius.circular(20))),
child: Icon(
Icons.sports_cricket,
size: 12,
color: Colors.blue,
),
),
Text(
'Sports',
style: TextStyle(fontSize: 15),
),
Icon(
Icons.cancel_outlined,
size: 15,
)
],
),
),
),
);
}
}
I have added crossAxisAlignment: WrapCrossAlignment.center, which makes it align to the center on the other axis
Also I have added some padding for aesthetics
write crossAxisAlignment: WrapCrossAlignment.center, in wrap widget property
Use ListTile in ClipRRect for the curve and proper alignment.
ClipRRect(
borderRadius: BorderRadius.circular(25.0),
child:Container(
color:Colors.green,
child:ListTile(
leading:Icon(Icons.sports_cricket,),
title:Text('Sports'),
trailing:Icon(Icons.close)
),
)
),
You just need a chip Here's an example:-
Chip(
onDeleted: () => (redirection call here),
deleteIcon: Icon(
Icons.sports_cricket,
size: rowIconSize,
color: companyThemeData.primaryColor,
),
labelStyle:
normal12blackish.copyWith(color: companyThemeData.primaryColor),
backgroundColor: companyThemeData.primaryColorLight,
label: Text('Sports'),
);

How do I expand the positioned Container downwards?

I am trying to replicate a design but I am having difficulty doing so.
On this page, I am trying to stack the blue container over an image and expand it downwards but I can't expand it downwards. I am using weird colours so the contrast can be there to see. I don't want to use a column because it doesn't have the 'stacked' effect. I feel like there is a more elegant way of doing this.
This is what it currently looks like
class IndividualNewsPage extends StatelessWidget {
final String articleURL;
IndividualNewsPage({this.articleURL});
#override
Widget build(BuildContext context) {
final screenHeight = MediaQuery.of(context).size.height;
return SafeArea(
child: Scaffold(
backgroundColor: Colors.red,
body: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.all(30),
child: Row(
children: <Widget>[
Material(
color: Colors.transparent,
child: InkWell(
onTap: () => Navigator.pop(context),
child: Icon(
Icons.arrow_back_ios,
color: Colors.grey,
))),
Spacer(),
Text(
DateFormat.yMMMMd("en_US").format(DateTime.now()),
style: TextStyle(
color: Colors.black54,
fontWeight: FontWeight.w600,
fontSize: 15),
),
],
),
),
SizedBox(
height: 10,
),
Stack(
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20)),
child: Container(
height: 400,
decoration: BoxDecoration(
color: Colors.blue,
image: DecorationImage(
image: NetworkImage(articleURL),
fit: BoxFit.fill)),
),
),
),
],
),
Positioned(
bottom: 30.0,
left: 0,
right: 0,
child: Container(
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.only(
topRight: Radius.circular(20),
topLeft: Radius.circular(20))),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
"New York",
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
),
Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."),
),
],
),
),
),
],
)
],
),
),
);
}
}
Wrap Stack inside an Expanded widget. It will fill the available height and the blue widget will be positioned at the bottom of the Column.
...,
Expanded(
child: Stack(...)
),
...
You can set debugPaintSizeEnabled to true in the main method in order to see Widgets borders, margins, positions... It helps with Widget positioning and sizing problems when building UIs.
import 'package:flutter/rendering.dart'
void main() {
debugPaintSizeEnabled = true;
runApp();
}