Possibility to randomise the clippers. And randomise the images

This commit is contained in:
Niklas 2024-11-29 22:56:41 +01:00
parent 3e92781bce
commit caa3bab10c
8 changed files with 119 additions and 18 deletions

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 40 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 76 KiB

View File

Before

Width:  |  Height:  |  Size: 240 KiB

After

Width:  |  Height:  |  Size: 240 KiB

Binary file not shown.

View File

@ -1,3 +1,5 @@
import 'dart:math';
import 'package:Emma_home/utils/clipper.dart';
import 'package:flutter/material.dart';
import 'package:Emma_home/utils/helper_functions.dart';
@ -197,7 +199,7 @@ class EventCard2Section extends StatelessWidget {
final Color color;
final MediaQueryData screen_size;
const EventCard2Section({
EventCard2Section({
super.key,
required this.title,
required this.description,
@ -206,6 +208,25 @@ class EventCard2Section extends StatelessWidget {
required this.color,
required this.screen_size,
});
List<CustomClipper<Path>> clippers = [
BowClipper(),
WaveClipper(),
ConcavClipper()
];
String getRandomImage() {
final List<String> images = [
'assets/images/Event_Images/image01.png',
'assets/images/Event_Images/image01.png',
];
final randomIndex = Random().nextInt(images.length);
return images[randomIndex];
}
CustomClipper<Path> _getRandomClipper() {
final randomIndex = Random().nextInt(clippers.length);
return clippers[randomIndex];
}
@override
Widget build(BuildContext context) {
return Container(
@ -246,9 +267,9 @@ class EventCard2Section extends StatelessWidget {
right: 0,
top: 0,
child: ClipPath(
clipper: MyClipper(),
clipper: _getRandomClipper(),
child: Image.asset(
'assets/images/Event_Images/unsplash_MxfcoxycH_Y.png', // Pfad zum Bild
getRandomImage(), // Pfad zum Bild
height: 110, // Höhe des Bildes
width: 130, // Breite des Bildes
fit: BoxFit.cover,

View File

@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
class MyClipper extends CustomClipper<Path> {
class WaveClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
Paint paint = Paint();
@ -35,3 +35,63 @@ class MyClipper extends CustomClipper<Path> {
@override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
class BowClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
Paint paint = Paint();
Path path = Path();
// Path number 1
path = Path();
path.lineTo(0, size.height);
path.cubicTo(0, size.height, 0, size.height, 0, size.height);
path.cubicTo(0, size.height, size.width * 0.89, size.height,
size.width * 0.89, size.height);
path.cubicTo(size.width, size.height, size.width, size.height, size.width,
size.height * 0.88);
path.cubicTo(size.width, size.height * 0.88, size.width, size.height * 0.11,
size.width, size.height * 0.11);
path.cubicTo(size.width, 0, size.width * 0.95, 0, size.width * 0.89, 0);
path.cubicTo(
size.width * 0.89, 0, size.width * 0.63, 0, size.width * 0.63, 0);
path.cubicTo(size.width * 0.11, size.height * 0.04, size.width * 0.04,
size.height * 0.68, 0, size.height);
path.cubicTo(0, size.height, 0, size.height, 0, size.height);
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
class ConcavClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
Paint paint = Paint();
Path path = Path();
// Path number 1
path.lineTo(size.width * 0.16, size.height * 0.58);
path.cubicTo(size.width * 0.16, size.height * 0.16, size.width * 0.08,
size.height * 0.1, size.width * 0.03, 0);
path.cubicTo(
size.width * 0.03, 0, size.width * 0.93, 0, size.width * 0.93, 0);
path.cubicTo(size.width, 0, size.width, size.height * 0.05, size.width,
size.height * 0.07);
path.cubicTo(size.width, size.height * 0.07, size.width, size.height * 0.9,
size.width, size.height * 0.9);
path.cubicTo(size.width, size.height * 0.98, size.width * 0.95, size.height,
size.width * 0.93, size.height);
path.cubicTo(
size.width * 0.93, size.height, 0, size.height, 0, size.height);
path.cubicTo(size.width * 0.12, size.height * 0.9, size.width * 0.15,
size.height * 0.68, size.width * 0.16, size.height * 0.58);
path.cubicTo(size.width * 0.16, size.height * 0.58, size.width * 0.16,
size.height * 0.58, size.width * 0.16, size.height * 0.58);
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}

View File

@ -37,18 +37,18 @@ packages:
dependency: transitive
description:
name: async
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63
url: "https://pub.dev"
source: hosted
version: "2.11.0"
version: "2.12.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
characters:
dependency: transitive
description:
@ -61,10 +61,10 @@ packages:
dependency: transitive
description:
name: clock
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b
url: "https://pub.dev"
source: hosted
version: "1.1.1"
version: "1.1.2"
collection:
dependency: transitive
description:
@ -101,10 +101,10 @@ packages:
dependency: transitive
description:
name: fake_async
sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc"
url: "https://pub.dev"
source: hosted
version: "1.3.1"
version: "1.3.2"
ffi:
dependency: transitive
description:
@ -396,10 +396,10 @@ packages:
dependency: transitive
description:
name: path
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"
url: "https://pub.dev"
source: hosted
version: "1.9.0"
version: "1.9.1"
path_provider:
dependency: transitive
description:
@ -601,10 +601,10 @@ packages:
dependency: transitive
description:
name: string_scanner
sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3"
sha256: "0bd04f5bb74fcd6ff0606a888a30e917af9bd52820b178eaa464beb11dca84b6"
url: "https://pub.dev"
source: hosted
version: "1.3.0"
version: "1.4.0"
supabase:
dependency: transitive
description:
@ -729,10 +729,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: f6be3ed8bd01289b34d679c2b62226f63c0e69f9fd2e50a6b3c1c729a961041b
sha256: "0968250880a6c5fe7edc067ed0a13d4bae1577fe2771dcf3010d52c4a9d3ca14"
url: "https://pub.dev"
source: hosted
version: "14.3.0"
version: "14.3.1"
web:
dependency: transitive
description: