我有一个容器,我需要剪裁它的高度,这看起来像所提供的图像。我也尝试过customPaint小部件,但无法使其工作。
child: Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 12,
offset: Offset(0, 3), // changes position of shadow
),
],
color: ColorConstants.redColor,
borderRadius: BorderRadius.all(Radius.circular(8))),
),
),
@override
Path getClip(Size size) {
var path = Path();
path.lineTo(size.width, 0.0);
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) => true;
}
答案 0 :(得分:0)
您可以轻松地CustomClipper
尝试这个Dartpad
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ClipPath(
clipper: ArcClipper(),
child: Container(
height: 60,
width: 200,
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.circular(10.0),
),
),
);
}
}
class ArcClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
Path path = Path();
path.lineTo(size.width, 0);
path.lineTo(size.width, size.height);
path.lineTo(size.width * .03, size.height);
path.quadraticBezierTo(size.width * .2, size.height * .5, size.width * .03, 0);
path.close();
return path;
}
@override
bool shouldReclip(CustomClipper old) => false;
}
答案 1 :(得分:0)