I want make this curve in the container - flutter

This image show what I want to do ,, I used container and made border radius to bottom right and this is ok , but in bottom left I don’t know how to make this curve

You can easily do it using CustomPainter.
Please check the following example.
import 'package:flutter/material.dart';
void main() async {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
home: new MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: SafeArea(
child: Container(
color: Colors.white,
child: CustomPaint(
painter: CurvePainterPage(),
),
),
),
);
}
}
class CurvePainterPage extends CustomPainter {
#override
void paint(Canvas canvas, Size size) {
var paint = Paint();
paint.color = Colors.blue[800];
paint.style = PaintingStyle.fill;
var path = Path();
path.moveTo(0, size.height * .70);
path.quadraticBezierTo(
0, size.height * .60, size.width * .1565, size.height * .60);
path.lineTo(size.width * .60, size.height * .60);
path.quadraticBezierTo(size.width * .69, size.height * .60,
size.width * .70, size.height * .50);
path.lineTo(size.width * .70, 0);
path.lineTo(0, 0);
canvas.drawPath(path, paint);
}
#override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
}
You can read about it more here

You can use BoxDecoration inside the Container.
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Colors.white,),
child:Text(
'Greetings, planet!',
style: TextStyle(
fontSize: 20,
color: Colors.grey[300],
),))

Related

How to place content inside custompaint widget?

import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: CustomPaint(
painter: RPSCustomPainter(),
child: Container(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.width * 0.73.toDouble(),
child: Text('Hi Nithya'))));
}
}
class RPSCustomPainter extends CustomPainter {
#override
void paint(Canvas canvas, Size size) {
Paint paint0 = Paint()
..color = const Color.fromARGB(255, 33, 150, 243)
..style = PaintingStyle.stroke
..strokeWidth = 1;
Path path0 = Path();
path0.moveTo(size.width * 0.3147368, size.height * 0.1385714);
path0.lineTo(size.width * 0.3145895, size.height * 0.4253429);
path0.quadraticBezierTo(size.width * 0.3334211, size.height * 0.4532571,
size.width * 0.3331895, size.height * 0.4633429);
path0.quadraticBezierTo(size.width * 0.3334526, size.height * 0.4708429,
size.width * 0.3147368, size.height * 0.4957143);
path0.lineTo(size.width * 0.3136842, size.height * 0.7828571);
path0.lineTo(size.width * 0.7378947, size.height * 0.7842857);
path0.lineTo(size.width * 0.7368421, size.height * 0.4985714);
path0.quadraticBezierTo(size.width * 0.7134000, size.height * 0.4737143,
size.width * 0.7131368, size.height * 0.4655000);
path0.quadraticBezierTo(size.width * 0.7134000, size.height * 0.4558571,
size.width * 0.7368421, size.height * 0.4271429);
path0.lineTo(size.width * 0.7357895, size.height * 0.1428571);
path0.lineTo(size.width * 0.3147368, size.height * 0.1385714);
path0.close();
canvas.drawPath(path0, paint0);
}
#override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return false;
}
}
I want the text to print inside the shape . But it is printing outside. How to increase or decrease the size of the shape based on content's width and height? I want the content to print only inside the custom shape. The shape should adjust to content's width and height automatically. How to achieve it?.
Wrapping your child Widget by Center Widget will solve the issue...
below code for your reference
CustomPaint(
painter: RPSCustomPainter(),
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.width * 0.73.toDouble(),
child: const Center(child: Text('Hi Hari'))
),
);
have a good day!!!

Shaping Container using Bezier Curve in Flutter

Up to this point, I wasn't aware that we could make shapes of our choices in Flutter and hence I'm totally new to this. I would like to shape my container to resemble the below design but I am totally short of ideas as to how this can be done. I did a bit of reading to find out about the concepts of the Bezier Curve but upon trying to apply that knowledge to the container below, I ended up getting something pretty horrendous. The screenshots and the code are as follows:
This is what I ended up getting:
class ProfilePage extends StatefulWidget {
ProfilePageState createState() => ProfilePageState();
}
class ProfilePageState extends State<ProfilePage> {
#override
Widget build(BuildContext context) {
final height = MediaQuery.of(context).size.height;
final width = MediaQuery.of(context).size.width;
// TODO: implement build
return Scaffold(
body: Container(
height: height * 1,
width: width * 1,
color: Colors.red,
child: Column(
children: [
Stack(
children: [
ClipPath(
clipper: CurvedAppBar(),
child: Container(
height: height * 0.2,
width: double.infinity,
color: Colors.white,
),
),
Positioned(child: Image.asset('assets/images/logo-with-bg.png'))
],
)
],
),
),
);
}
}
import 'package:flutter/material.dart';
class CurvedAppBar extends CustomClipper<Path> {
#override
Path getClip(Size size) {
var path = Path();
path.lineTo(0, size.height);
var firstStart = Offset(size.width / 5, size.height);
var firstEnd = Offset(size.width / 2.25, size.height - 50);
path.quadraticBezierTo(
firstStart.dx, firstEnd.dy, firstEnd.dx, firstEnd.dy);
var secondStart =
Offset(size.width - (size.width / 3.24), size.height - 105);
var secondEnd = Offset(size.width, size.height - 10);
path.quadraticBezierTo(
secondStart.dx, secondStart.dy, secondEnd.dx, secondEnd.dy);
path.lineTo(size.width, 0);
path.close();
return path;
}
#override
bool shouldReclip(covariant CustomClipper<Path> oldClipper) {
// TODO: implement shouldReclip
return false;
}
}
Any ideas how this can be shaped?
Check this out:
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: Center(
child: Container(
color: Colors.grey,
child: ClipPath(
clipper: Clipp(),
child: Container(
width: 500,
height: 500,
color: Colors.pink,
),
),
),
),
),
);
}
}
class Clipp extends CustomClipper<Path> {
#override
Path getClip(Size size) {
Path path = Path();
path.moveTo(150, 0);
path.quadraticBezierTo(120, 150, 0, 150);
path.lineTo(0, 380);
path.quadraticBezierTo(size.width / 4, size.height, size.width, 270);
path.lineTo(size.width, 0);
return path;
}
#override
bool shouldReclip(covariant CustomClipper<Path> oldClipper) => true;
}
The output:
Edit: To make it dynamic, try this:
class Clipp extends CustomClipper<Path> {
#override
Path getClip(Size size) {
Path path = Path();
double firstFactor = size.width / 3.3333;
double secondFactor = size.height / 2;
double thirdFactor = size.width / 4.166;
double fourthFactor = size.height / 1.4285;
path.moveTo(firstFactor, 0);
path.quadraticBezierTo(thirdFactor, firstFactor, 0, firstFactor);
path.lineTo(0, fourthFactor);
path.quadraticBezierTo(
size.width / 3,
size.height,
size.width,
secondFactor,
);
path.lineTo(size.width, 0);
return path;
}
#override
bool shouldReclip(covariant CustomClipper<Path> oldClipper) => true;
}

How to create a hexagon clippath on flutter?

I'm trying to use a hexagon profile picture, but I'm having trouble using clip path with flutter.
The CSS code for the hexagon is this:
-webkit-clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
how can I do it on flutter?
Let's use ClipPath to get this shape and follow the css the way you did.
50% 0% mean (x, y) and also same forlineTo(x,y) and moveTo.
class HexagonClipper extends CustomClipper<Path> {
#override
Path getClip(Size size) {
Path path = Path();
path
..moveTo(size.width / 2, 0) // moving to topCenter 1st, then draw the path
..lineTo(size.width, size.height * .25)
..lineTo(size.width, size.height * .75)
..lineTo(size.width * .5, size.height)
..lineTo(0, size.height * .75)
..lineTo(0, size.height * .25)
..close();
return path;
}
#override
bool shouldReclip(covariant CustomClipper<Path> oldClipper) {
return false;
}
}
And use like
ClipPath(
clipper: HexagonClipper(),
child: Container(
width: 100, /// controll the size and color
height: 110,
color: Colors.amber,
),
)
Result
learn more about ClipPath
code
import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { #override Widget build(BuildContext context) { return MaterialApp( title: 'Hexagon', theme: ThemeData( primarySwatch: Colors.blue, ), home: MyHomePage(title: 'Hexagon'), ); } } class MyHomePage extends StatefulWidget { MyHomePage({Key key, this.title}) : super(key: key); final String title; #override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { #override Widget build(BuildContext context) { return Scaffold( body: Padding( padding: const EdgeInsets.all(50.0), child: ClipPath( child: Container( color: Colors.amber, ), clipper: _MyClipper(), ), ), ); } } class _MyClipper extends CustomClipper<Path> { #override Path getClip(Size size) { final path = Path(); path.lineTo(0, 0); path.lineTo(size.width, 0); path.lineTo(size.width, size.height * 0.8); path.lineTo(size.width * 0.8, size.height); path.lineTo(size.width * 0.2, size.height); path.lineTo(0, size.height * 0.8); path.lineTo(0, 0); path.close(); return path; } #override bool shouldReclip(CustomClipper<Path> oldClipper) => false; }
or you can use a package called
flutter_custom_clippers: ^2.0.0

How to fit any curved to screen? - Flutter

I am new to flutter and would like to learn how to fit any screen curved from photo.
I'am not able to fit curved to the left, how to fit this shape to every possible screen?
I don't know why but the left side won't fit
I needs help or hints.
class StartAfterRegister extends StatelessWidget {
static Route route() {
return MaterialPageRoute<void>(builder: (_) => StartAfterRegister());
}
#override
Widget build(BuildContext context) {
return Scaffold(body: _profilePage(context));
}
}
Widget _profilePage(BuildContext context) {
return SafeArea(
child: Center(
child: Column(
children: [
const SizedBox(height: 452),
_curved(),
],
),
),
);
// });
}
Widget _curved() {
return Container(
// padding: const EdgeInsets.all(8.0),
// child: Padding(
// margin: const EdgeInsets.only(left: 0.0, right: 28.0),
// const EdgeInsets.fromLTRB(0, 10, 25, 10),
child: CustomPaint(
size: Size(600, (320* 1.1617600000000001).toDouble()),
//You can Replace [WIDTH] with your desired width for
// Custom Paint and height will be calculated automatically
painter: RPSCustomPainter(),
),
);
}
Code was generated with this page :https://fluttershapemaker.com/
I don't know where I made a mistake, wrong portions?
import 'dart:ui' as ui;
import 'package:flutter/cupertino.dart';
import 'package:flutter_login/components/theme/colors.dart';
class RPSCustomPainter extends CustomPainter {
#override
void paint(Canvas canvas, Size size) {
Path path_0 = Path();
path_0.moveTo(size.width*1.071853,size.height*1.035738);
path_0.lineTo(size.width*0.07250032,size.height*1.035738);
path_0.lineTo(size.width*0.07250032,size.height*0.3868996);
path_0.cubicTo(size.width*0.07241850,size.height*0.3325917,size.width*0.09748933,size.height*0.2804976,size.width*0.1421620,size.height*0.2421464);
path_0.cubicTo(size.width*0.1969324,size.height*0.1950013,size.width*0.2692701,size.height*0.1829006,size.width*0.3079311,size.height*0.1816967);
path_0.cubicTo(size.width*0.5894098,size.height*0.1729377,size.width*0.8344350,size.height*0.1919213,size.width*0.9302565,size.height*0.1649115);
path_0.cubicTo(size.width*0.9696772,size.height*0.1538054,size.width*1.040485,size.height*0.1192928,size.width*1.071848,size.height*0.03573744);
path_0.cubicTo(size.width*1.069587,size.height*0.2428419,size.width*1.074102,size.height*0.8286341,size.width*1.071853,size.height*1.035738);
path_0.close();
Paint paint_0_fill = Paint()..style=PaintingStyle.fill;
paint_0_fill.color = teal ;
canvas.drawPath(path_0,paint_0_fill);
}
#override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
}
**There is a problem in your custom shape if you want to create more shape be sure you set in widht and size **
like this
simply add this code to custom painter
class RPSCustomPainter extends CustomPainter {
#override
void paint(Canvas canvas, Size size) {
Paint paint_0 = new Paint()
..color = Color.fromARGB(255, 33, 150, 243)
..style = PaintingStyle.fill
..strokeWidth = 1;
Path path_0 = Path();
path_0.moveTo(size.width, size.height);
path_0.lineTo(size.width * 0.0012500, size.height * 0.9942857);
path_0.lineTo(size.width * 0.0012500, size.height * 0.4271429);
path_0.quadraticBezierTo(size.width * 0.0740625, size.height * 0.2807143,
size.width * 0.1950000, size.height * 0.2800000);
path_0.quadraticBezierTo(size.width * 0.8515625, size.height * 0.3560714,
size.width * 0.9962500, size.height * 0.2828571);
path_0.quadraticBezierTo(size.width * 0.9990625, size.height * 0.2850000,
size.width, size.height * 0.2857143);
path_0.quadraticBezierTo(size.width * 1.0084375, size.height * 0.4992857,
size.width, size.height);
path_0.close();
canvas.drawPath(path_0, paint_0);
}
#override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
}
}
**add this in your child **
import 'package:flutter/material.dart';
class Demo extends StatefulWidget {
const Demo({Key? key}) : super(key: key);
#override
_DemoState createState() => _DemoState();
}
class _DemoState extends State<Demo> {
#override
Widget build(BuildContext context) {
/// this is the width of screen
var width = MediaQuery.of(context).size.width;
return Scaffold(
appBar: AppBar(),
body: Stack(
children: [
Align(
alignment: Alignment.bottomLeft,
child: Container(
color: Colors.red,
width: width,
child: CustomPaint(
size: Size((width).toDouble(), (width * 0.875).toDouble()),
painter: RPSCustomPainter(),
),
))
],
),
);
}
}

how to create a styling in button in flutter?

How make this styling for a button in flutter. Since I'm a newbie, I have no Idea on how to do it.
In image the triangle is somewhat irregular, I want that to be matched with the button box.
You can use the CustomPaint widget to get that effect. You can easily auto-generate the CustomPaint code from Flutter Shape Maker. Please see the code below. You can also run the code on DartPad at the following URL https://dartpad.dev/0171e4b838b740ea23f896f3b0be1f8e :
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: MyWidget(),
);
}
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
width: 360,
height: 100,
color: Colors.black,
child: CustomPaint(
size: Size(1200, 700),
painter: FlagPainter(),
child: Text(
"text",
style: TextStyle(color: Colors.black, fontSize:24),
),
),
),
),
);
}
}
class FlagPainter extends CustomPainter {
#override
void paint(Canvas canvas, Size size) {
Paint paint_0 = new Paint()
..color = Color.fromARGB(255, 255, 255, 255)
..style = PaintingStyle.fill
..strokeWidth = 1;
Path path_0 = Path();
path_0.moveTo(0, 0);
path_0.lineTo(0, size.height * 2.40);
path_0.lineTo(0, size.height * 0.72);
path_0.lineTo(size.width * 0.28, 0);
canvas.drawPath(path_0, paint_0);
}
#override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
}
}