Guest User

MaskLayer

a guest
Jun 26th, 2020
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.75 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() {
  4.   runApp(MaterialApp(
  5.     theme: ThemeData(primarySwatch: Colors.blueGrey),
  6.     home: PracticeApp(),
  7.   ));
  8. }
  9.  
  10. class PracticeApp extends StatelessWidget {
  11.   @override
  12.   Widget build(BuildContext context) {
  13.     return Scaffold(
  14.       backgroundColor: Colors.grey,
  15.       appBar: AppBar(
  16.         title: Text('PracticeApp'),
  17.         centerTitle: true,
  18.       ),
  19.       body: Stack(
  20.         children: [
  21.           Container(
  22.             decoration: BoxDecoration(
  23.               image: DecorationImage(
  24.                 image: NetworkImage(
  25.                     'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg'),
  26.                 fit: BoxFit.cover,
  27.               ),
  28.             ),
  29.           ),
  30.           CustomPaint(
  31.             painter: HolePainter(),
  32.             child: Container(),
  33.           ),
  34.           Row(
  35.             mainAxisAlignment: MainAxisAlignment.spaceBetween,
  36.             children: [
  37.               Container(
  38.                 decoration: BoxDecoration(
  39.                   borderRadius: BorderRadius.all(
  40.                     Radius.circular(50),
  41.                   ),
  42.                   color: Colors.grey.shade600.withOpacity(0.8),
  43.                 ),
  44.                 padding: EdgeInsets.all(10.0),
  45.                 margin: EdgeInsets.all(20),
  46.                 child: IconButton(
  47.                   icon: Icon(Icons.flash_on),
  48.                   onPressed: null,
  49.                 ),
  50.               ),
  51.               Container(
  52.                 decoration: BoxDecoration(
  53.                   borderRadius: BorderRadius.all(
  54.                     Radius.circular(50),
  55.                   ),
  56.                   color: Colors.grey.shade600.withOpacity(0.8),
  57.                 ),
  58.                 padding: EdgeInsets.all(10.0),
  59.                 margin: EdgeInsets.all(20),
  60.                 child: IconButton(
  61.                   icon: Icon(Icons.photo_camera),
  62.                   onPressed: null,
  63.                 ),
  64.               ),
  65.             ],
  66.           )
  67.         ],
  68.       ),
  69.     );
  70.   }
  71. }
  72.  
  73. class HolePainter extends CustomPainter {
  74.   @override
  75.   void paint(Canvas canvas, Size size) {
  76.     //print('${size.height},${size.width}');
  77.     final paint = Paint();
  78.     paint.color = Colors.grey.withOpacity(0.8);
  79.     canvas.drawPath(
  80.       Path.combine(
  81.         PathOperation.difference,
  82.         Path()
  83.           ..addRRect(RRect.fromLTRBR(
  84.               0, 0, size.width, size.height, Radius.circular(0))),
  85.         Path()
  86.           ..addOval(Rect.fromCircle(
  87.               center: Offset(size.width / 2, size.height / 2), radius: 180))
  88.           ..close(),
  89.       ),
  90.       paint,
  91.     );
  92.   }
  93.  
  94.   @override
  95.   bool shouldRepaint(CustomPainter oldDelegate) {
  96.     return false;
  97.   }
  98. }
Add Comment
Please, Sign In to add comment