shape_of_view_null_safe 3.1.2
shape_of_view_null_safe: ^3.1.2 copied to clipboard
Give any Flutter widget a custom shape. Circle, rounded rect, cut corners, arc, diagonal, triangle, bubble, star, polygon, or your own path.
import 'package:flutter/material.dart';
import 'package:kenburns_nullsafety/kenburns_nullsafety.dart';
import 'package:shape_of_view_null_safe/shape_of_view_null_safe.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.grey[200],
body: const ShapesPage(),
),
);
}
}
/// A profile header cut by a [DiagonalShape], over a grid with one tile for
/// each of the other shapes.
class ShapesPage extends StatelessWidget {
const ShapesPage({super.key});
@override
Widget build(BuildContext context) {
return Stack(
children: [
// The header: a 300 px tall background whose bottom edge is cut at
// 15 degrees.
ShapeOfView(
elevation: 4,
height: 300,
shape: DiagonalShape(angle: DiagonalAngle.deg(angle: 15)),
child: Stack(
children: [
KenBurns(
maxScale: 5,
child: Image.asset(
'assets/diagonallayout_background.jpg',
fit: BoxFit.cover,
),
),
const Column(
children: [
Padding(
padding: EdgeInsets.only(left: 18, top: 120),
child: Text(
'Hugh Jackman',
style: TextStyle(
fontWeight: FontWeight.w200,
color: Colors.white,
fontSize: 20,
shadows: [
Shadow(
color: Colors.black,
blurRadius: 1,
offset: Offset(1, 1),
),
],
),
),
),
Padding(
padding: EdgeInsets.only(left: 16, top: 6.0),
child: Text(
'Actor Producer',
style: TextStyle(
fontWeight: FontWeight.w700,
color: Colors.white,
fontSize: 20,
shadows: [
Shadow(
color: Colors.black,
blurRadius: 1,
offset: Offset(1, 1),
),
],
),
),
),
],
),
],
),
),
// The grid, overlapping the bottom of the header.
Padding(
padding: const EdgeInsets.only(left: 20, top: 230),
child: Wrap(
spacing: 20,
runSpacing: 20,
children: [
ShapeTile(
shape: CircleShape(borderColor: Colors.white, borderWidth: 3),
),
ShapeTile(
shape: RoundRectShape(
borderRadius: BorderRadius.circular(12),
borderColor: Colors.white, // optional
borderWidth: 2, // optional
),
),
ShapeTile(
shape: CutCornerShape(borderRadius: BorderRadius.circular(12)),
),
ShapeTile(
shape: ArcShape(
direction: ArcDirection.Outside,
height: 20,
position: ArcPosition.Bottom,
),
),
ShapeTile(
shape: DiagonalShape(
position: DiagonalPosition.Bottom,
direction: DiagonalDirection.Right,
angle: DiagonalAngle.deg(angle: 10),
),
),
ShapeTile(
shape: TriangleShape(
percentBottom: 0.5,
percentLeft: 0,
percentRight: 0,
),
),
ShapeTile(
shape: BubbleShape(
position: BubblePosition.Bottom,
arrowPositionPercent: 0.5,
borderRadius: 20,
arrowHeight: 10,
arrowWidth: 10,
),
),
ShapeTile(shape: StarShape(noOfPoints: 5)),
ShapeTile(shape: PolygonShape(numberOfSides: 9)),
],
),
),
],
);
}
}
/// A 100 x 100 photo clipped to [shape].
class ShapeTile extends StatelessWidget {
const ShapeTile({super.key, required this.shape});
final Shape shape;
@override
Widget build(BuildContext context) {
return ShapeOfView(
height: 100,
width: 100,
elevation: 2,
shape: shape,
child: Image.asset(
'assets/diagonallayout_hughjackman.jpg',
fit: BoxFit.cover,
),
);
}
}