Diamond shaped button with border - flutter

anyone know how to design this button in flutter? It's a diamond shaped button with a border color.

result
full code
import 'dart:math' as math;
import 'package:flutter/material.dart';
class DimondButton extends StatelessWidget {
const DimondButton({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
body: Center(
child: Transform(
alignment: Alignment.center,
transform: Matrix4.rotationZ(
math.pi / 4,
),
child: Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: Colors.transparent,
border: Border.all(
width: 3,
color: Colors.amber,
),
),
child: InkWell(
splashColor: Colors.blueAccent,
onTap: () {},
child: Center(
child: Transform(
alignment: Alignment.center,
transform: Matrix4.rotationZ(
-math.pi / 4,
),
child: Text(
"Click",
style: TextStyle(color: Colors.white),
),
),
),
),
),
),
),
);
}
}

you have multiple approaches
you can create a container with border color and transparent inner and transform it using transform.translate
the other one is using custom paint which is a bit harder

You should try to use below code, add this dependency to your pubspec.yaml file flutter_custom_clippers: ^1.1.2 package found here
ClipPath(
clipper: ParallelogramClipper(),
child: Container(
height: 50,
width: 50,
color: Colors.pinkAccent,
child: TextButton(
onPressed: () {
print('object');
},
child: Text('OK'),
),
),
),

Related

button shadow when clicked is covered by other widget

Button's shadow is happened when click the button.
But, the shadow is covered by other widget.
How can I resolve this?
#override
Widget build(BuildContext context) {
int total = 0;
for (int i = 1; i <= count; i++) {
total += i;
}
return Stack(
clipBehavior: Clip.none,
children: [
Container(
width: 343.43,
height: 150.62,
decoration: RadiusAndShadow().getDecoration(),
child: Column(
children: <Widget>[
Header(text: name),
EcRow(t1: '칼로리', t2: '1회당 ${calorie}kcal'),
EcRow(t1: '카드개수', t2: '$count 개'),
EcRow(t1: '반복횟수', t2: '$total회'),
],
),
),
Positioned(
width: 343.43,
height: 150.62,
top: 17,
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
height: 40,
width: 40,
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: Colors.black,
),
child: IconButton(
padding: const EdgeInsets.all(0),
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) {
return ExEdit();
}));
},
icon: const Icon(
Icons.edit_outlined,
color: Colors.white,
size: 30,
),
),
),
),
),
],
);
}
I used Stack widget.
In Stack, there are Container and Positioned.
In Container, there are Header and Text.
In Positioned, there is an IconButton.
I didn't understand exactly what happens since you did not provide any code, but I think when you click on the IconButton a splash effect happens and not exactly a shadow so inside the IconButton add:
splashRadius: 20,
you can also disable this effect:
return Theme(
data: ThemeData.light().copyWith(
textTheme: GoogleFonts.poppinsTextTheme(),
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
),
child: const WelcomeScreen(),
);
Wrap your IconButton with widget Material
in Material
color: Colors.transparent,
in IconButton
splashRadius: 20,

How to create a sticky header from the container that is in the middle

import 'package:flutter/material.dart';
void main() {
runApp(Test());
}
class Test extends StatelessWidget {
#override
Widget build(context) {
return SingleChildScrollView(
child: Column(children: [
Container(
height: 100,
color: Colors.white,
child: const Text("Titleeeee"),
),
Container(
height: 300,
color: Colors.blue,
child: const Text("STICKEEEYYYY"),
),
Container(
height: 100,
color: Colors.orange,
child: const Text("CCCCCCC"),
),
Container(
height: 100,
color: Colors.orange,
child: const Text("CCCCCCC"),
),
]),
);
}
}
I have this Column widget. Trying to make the second container - Text('STICKEEEY') the sticky header. I've been trying to use the sticky_header package.
Container(
child: SingleChildScrollView(
child: Column(
children: [
Container(
height: 100,
color: Colors.white,
child: const Text("Titleeeee"),
),
StickyHeader(
header: Container(
height: 300,
color: Colors.blue,
child: const Text("STICKEEEYYYY"),
),
content: Column(children: [
Container(
height: 100,
color: Colors.orange,
child: const Text("CCCCCCC"),
),
Container(
height: 100,
color: Colors.orange,
child: const Text("CCCCCCC"),
),
]),
),
],
),
),
)
However, this does not hold the second container at the top. It bypasses when it scrolls down. How can I make it stick to the top in this case?
Slives maybe are what you are looking for.
Doc: https://docs.flutter.dev/development/ui/advanced/slivers
You can use SilverAppBar
Doc : https://api.flutter.dev/flutter/material/SliverAppBar-class.html

How to add ripples effect while using circleavatar in flutter

CircleAvatar(
backgroundColor: Colors.blue,
radius: 25,
child: Icon(Icons.add_call),
),
How to add ripples of different color inside circleavatar
You can use InkWell in this case, and import 'dart:math'; use get Random.
late Color _rippleColor = getRandomColor();
Color getRandomColor() =>
Color((Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: InkWell(
radius: 25,
splashColor: _rippleColor,
customBorder: const CircleBorder(),
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Icon(
Icons.add_call,
),
),
onTap: () {
setState(() {
_rippleColor = getRandomColor();
});
},
),
));
}
Use Ink and InkWell with Material on top of it and set Material shape with CircleBorder()
Material(
elevation: 4.0,
shape: CircleBorder(),
clipBehavior: Clip.antiAlias,
color: Colors.transparent,
child: Ink.image(
image: AssetImage('assets/profile_default.jpg'),
fit: BoxFit.cover,
width: 120.0,
height: 120.0,
child: InkWell(
onTap: () {},
),
),
)
you can change splash color in InkWell property
source: https://medium.com/#RayLiVerified/create-a-rounded-image-icon-with-ripple-effect-in-flutter-eb0f4a720b90

Designing a Flutter button with image and text

If I just throw together an image and some text in a rounded-corner rectangle, the user will not know that they can "click here". But I don't have to bake my own solution. InkWell covers this scenario, complete with a nice shadow.
I am positioning
a custom clickable icon using the
InkWell
class, itself requiring to be inside an
Ink
instance.
import 'package:flutter/material.dart';
const boat_url = ('https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/'
'Segelboot_Bodensee_Mainau_%28Foto_Hilarmont%29.JPG/'
'182px-Segelboot_Bodensee_Mainau_%28Foto_Hilarmont%29.JPG');
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Image',
home: Scaffold(
backgroundColor: Colors.grey,
body: MyImage(),
)));
}
class MyImage extends StatelessWidget {
MyImage({Key key,});
#override
Widget build(BuildContext context) {
Size sz = MediaQuery.of(context).size * 0.4;
double border = 4;
return Stack(children: [
Positioned(
top: 100,
left: 100,
width: sz.width,
height: sz.height,
child: Material(
child: Ink(
decoration: BoxDecoration(
boxShadow: <BoxShadow>[
new BoxShadow(
color: Colors.red,
blurRadius: 10.0,
offset: new Offset(30.0, 20.0),
),
],
border: Border.all(
color: Colors.blue,
width: border,
),
borderRadius: BorderRadius.circular(40),
),
child: InkWell(
onTap: (){/*..*/},
child: Column(
children: [
Container(
height: 4 * (sz.height - 2 * border) / 5,
alignment: Alignment.center,
child: Image.network(boat_url),
),
Container(
height: (sz.height - 2 * border) / 5,
child: FittedBox(
clipBehavior: Clip.antiAlias,
alignment: Alignment.centerLeft,
fit: BoxFit.fitHeight,
child: Text('A long descriptive sentence')),
)
],
)),
),
)),
]);
}
}
1- I'm not actually using Colors.white, and the Scaffold itself has
backgroundColor: Colors.grey. Where is the white background coming from?
2- When we talk of a "shadow", I'm expecting the shadow to be behind
the ink/inkwell object. Why does the shadow appear in front?
Related: 1
That white color is from the Material widget, to remove that you can use type param.
Material(
type: MaterialType.transparency,
child: Container(),
);
Here is code to achieve the custom button
Video link
Scaffold(
backgroundColor: Colors.blueGrey,
body: SafeArea(
child: Container(
decoration: BoxDecoration(
color: Colors.green.shade200,
border: Border.all(color: Colors.green),
borderRadius: BorderRadius.circular(5),
boxShadow: [
BoxShadow(
blurRadius: 5,
spreadRadius: 2,
color: Colors.black26,
)
]),
margin: const EdgeInsets.all(20),
child: Material(
type: MaterialType.transparency,
child: InkWell(
onTap: () {},
splashColor: Colors.black26,
child: IntrinsicHeight(
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(mainAxisSize: MainAxisSize.min, children: [
Image.asset(
'assets/images/marked_tyre_base.png',
fit: BoxFit.cover,
width: 80,
height: 80,
),
const SizedBox(
height: 10,
),
Text(
'Tyre 1',
style: TextStyle(color: Colors.white),
)
]),
),
),
),
),
),
),
);
Screenshot:
Create a class, ImageTextButton:
class ImageTextButton extends StatelessWidget {
final VoidCallback onPressed;
final ImageProvider image;
final double imageHeight;
final double radius;
final Widget text;
ImageTextButton({
#required this.onPressed,
#required this.image,
this.imageHeight = 200,
this.radius = 28,
#required this.text,
});
#override
Widget build(BuildContext context) {
return Card(
elevation: 8,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(radius)),
clipBehavior: Clip.hardEdge,
child: InkWell(
onTap: onPressed,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Ink.image(
image: image,
height: imageHeight,
fit: BoxFit.cover,
),
SizedBox(height: 6),
text,
SizedBox(height: 6),
],
),
),
);
}
}
Usage:
ImageTextButton(
onPressed: () {},
image: AssetImage('chocolate_image'),
text: Text('Chocolate'),
)

How to overlap two circles?

Can someone help me get this layout with the first circle over the second?
image
I have this function:
Widget overlapped() {
final overlap = 25;
final items = [
Container(
padding: EdgeInsets.only(right: 2),
decoration: new BoxDecoration(
color: Colors.blue,
shape: BoxShape.circle,
),
child: CircleAvatar(
radius: 22,
backgroundImage: AssetImage('assets/example_logo.png'),
backgroundColor: Colors.black,
),
),
CircleAvatar(
radius: 22,
backgroundColor: Colors.white,
child: ClipOval(
child: Image.network(
"https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Google_%22G%22_Logo.svg/1200px-Google_%22G%22_Logo.svg.png",
errorBuilder: (context, exception, stackTrace) {
return Container(color: Colors.white);
},
height: 35,
))),
CircleAvatar(
child: Text('+2', style: TextStyle(color: Colors.white)),
backgroundColor: Theme.of(context).canvasColor),
];
List<Widget> stackLayers = List<Widget>.generate(items.length, (index) {
return Container(
padding: EdgeInsets.fromLTRB(index.toDouble() * overlap, 0, 0, 0),
child: items[index],
);
});
return Stack(children: stackLayers);
}
This function whenever I add an item to the array, it adds a widget on the right. But I want the first to be above the second, the second of the third, etc ...
you could use the Stack widget :
Stack(
children:<Widget>:[
Positioned(
right: 130.0,
child:Container(
shape: BoxShape.circle,
)
),
Positioned(
left: 130.0,
child:Container(
shape: BoxShape.circle,
)
),
]
)
Use Stack and Positioned together.
import 'package:flutter/material.dart';
class OverLap extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Overlap'),
),
body: Container(
padding: const EdgeInsets.all(8.0),
width: 500.0,
child: Stack(
children: <Widget>[
//Change according to your icon
Icon(
Icons.flaky,
size: 50.0,
color: Colors.red,
),
Positioned(
left: 20.0,
//Change according to your icon
child: Icon(
Icons.flaky,
size: 50.0,
color: Colors.blue,
),
),
],
),
),
);
}
}