|
| 1 | +// 🐦 Twitter https://twitter.com/vandadnp |
| 2 | +// 🔵 LinkedIn https://linkedin.com/in/vandadnp |
| 3 | +// 🎥 YouTube https://youtube.com/c/vandadnp |
| 4 | +// 💙 Free Flutter Course https://linktr.ee/vandadnp |
| 5 | +// 📦 11+ Hours Bloc Course https://youtu.be/Mn254cnduOY |
| 6 | +// 🔶 7+ Hours MobX Course https://youtu.be/7Od55PBxYkI |
| 7 | +// 🦄 8+ Hours RxSwift Coursde https://youtu.be/xBFWMYmm9ro |
| 8 | +// 🤝 Want to support my work? https://buymeacoffee.com/vandad |
| 9 | + |
| 10 | +import 'package:flutter/material.dart'; |
| 11 | + |
| 12 | +void main() { |
| 13 | + runApp( |
| 14 | + const App(), |
| 15 | + ); |
| 16 | +} |
| 17 | + |
| 18 | +class App extends StatelessWidget { |
| 19 | + const App({ |
| 20 | + Key? key, |
| 21 | + }) : super(key: key); |
| 22 | + |
| 23 | + @override |
| 24 | + Widget build(BuildContext context) { |
| 25 | + return MaterialApp( |
| 26 | + theme: ThemeData( |
| 27 | + primarySwatch: Colors.blue, |
| 28 | + ), |
| 29 | + debugShowCheckedModeBanner: false, |
| 30 | + home: const HomePage(), |
| 31 | + ); |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +extension RemoveAll on String { |
| 36 | + String removeAll(Iterable<String> values) => values.fold( |
| 37 | + this, |
| 38 | + ( |
| 39 | + String result, |
| 40 | + String pattern, |
| 41 | + ) => |
| 42 | + result.replaceAll(pattern, '')); |
| 43 | +} |
| 44 | + |
| 45 | +extension AsHtmlColorToColor on String { |
| 46 | + Color htmlColorToColor() => Color( |
| 47 | + int.parse( |
| 48 | + removeAll(['0x', '#']).padLeft(8, 'ff'), |
| 49 | + radix: 16, |
| 50 | + ), |
| 51 | + ); |
| 52 | +} |
| 53 | + |
| 54 | +class Clipper extends CustomClipper<Path> { |
| 55 | + static const variance = 0.1; |
| 56 | + static const reverse = 1.0 - variance; |
| 57 | + |
| 58 | + @override |
| 59 | + Path getClip(Size size) { |
| 60 | + final path = Path(); |
| 61 | + |
| 62 | + path.moveTo(0.0, size.height * Clipper.variance); |
| 63 | + path.lineTo(size.width * Clipper.variance, 0.0); |
| 64 | + path.lineTo(size.width, 0.0); |
| 65 | + path.lineTo(size.width, size.height * Clipper.reverse); |
| 66 | + path.lineTo(size.width * Clipper.reverse, size.height); |
| 67 | + path.lineTo(0.0, size.height); |
| 68 | + path.lineTo(0.0, size.height * Clipper.variance); |
| 69 | + path.close(); |
| 70 | + return path; |
| 71 | + } |
| 72 | + |
| 73 | + @override |
| 74 | + bool shouldReclip(covariant CustomClipper<Path> oldClipper) => false; |
| 75 | +} |
| 76 | + |
| 77 | +class CutEdges extends StatelessWidget { |
| 78 | + final Widget child; |
| 79 | + |
| 80 | + const CutEdges({Key? key, required this.child}) : super(key: key); |
| 81 | + |
| 82 | + @override |
| 83 | + Widget build(BuildContext context) { |
| 84 | + return ClipPath( |
| 85 | + clipper: Clipper(), |
| 86 | + child: child, |
| 87 | + ); |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +class ElevatedNetworkImage extends StatelessWidget { |
| 92 | + final String url; |
| 93 | + const ElevatedNetworkImage({Key? key, required this.url}) : super(key: key); |
| 94 | + |
| 95 | + @override |
| 96 | + Widget build(BuildContext context) { |
| 97 | + return PhysicalShape( |
| 98 | + color: Colors.white, |
| 99 | + clipper: Clipper(), |
| 100 | + elevation: 20.0, |
| 101 | + clipBehavior: Clip.none, |
| 102 | + shadowColor: Colors.white.withAlpha(200), |
| 103 | + child: CutEdges( |
| 104 | + child: Image.network(url), |
| 105 | + ), |
| 106 | + ); |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +const imageUrl = 'https://wallpaperaccess.com/full/1326907.jpg'; |
| 111 | + |
| 112 | +class HomePage extends StatelessWidget { |
| 113 | + const HomePage({Key? key}) : super(key: key); |
| 114 | + |
| 115 | + @override |
| 116 | + Widget build(BuildContext context) { |
| 117 | + return Scaffold( |
| 118 | + backgroundColor: '24283b'.htmlColorToColor(), |
| 119 | + body: const Center( |
| 120 | + child: FractionallySizedBox( |
| 121 | + heightFactor: 0.7, |
| 122 | + child: ElevatedNetworkImage( |
| 123 | + url: imageUrl, |
| 124 | + ), |
| 125 | + ), |
| 126 | + ), |
| 127 | + ); |
| 128 | + } |
| 129 | +} |
0 commit comments