Round Corner Cliper In Flutter

Round Corner Cliper In Flutter :

Round Corner Cliper Screenshot :

Round Corner Cliper In Flutter

round_corner_cliper.dart

import 'dart:ui';
import 'package:flutter/material.dart';

class InnerRoundCornerCliper extends CustomClipper<Path> {
  final double topLeftRadius;
  final double topRightRadius;
  final double bottomLeftRadius;
  final double bottomRightRadius;

  InnerRoundCornerCliper(
      {this.topLeftRadius = 0.0,
      this.topRightRadius = 0.0,
      this.bottomLeftRadius = 0.0,
      this.bottomRightRadius = 0.0});

  @override
  Path getClip(Size size) {
    Path path = new Path();
    double width = size.width;
    double height = size.height;

    path.moveTo(0, 0);
    if (topLeftRadius > 0) {
      path.moveTo(topLeftRadius, 0);
      path.arcToPoint(Offset(0, topLeftRadius),
          radius: Radius.circular(topLeftRadius));
    }

    path.lineTo(0.0, height / 2 - bottomLeftRadius);
    if (bottomLeftRadius > 0) {
      path.arcToPoint(Offset(bottomLeftRadius, height / 2),
          radius: Radius.circular(bottomLeftRadius));
    }

    path.lineTo(width - bottomRightRadius, height / 2);
    if (bottomRightRadius > 0) {
      path.arcToPoint(Offset(width, height / 2 - bottomRightRadius),
          radius: Radius.circular(bottomRightRadius));
    }

    path.lineTo(width, 0 + topRightRadius);
    if (topRightRadius > 0) {
      path.arcToPoint(Offset(width - topRightRadius, 0),
          radius: Radius.circular(topRightRadius));
    }
    path.close();
    return path;
  }

  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) => true;
}

main.dart

import 'package:flutter/material.dart';
import 'round_corner_cliper.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                'You have pushed the button this many times:',
              ),
              Text(
                '$_counter',
                style: Theme.of(context).textTheme.display1,
              ),
              ClipPath(
                clipper: new InnerRoundCornerCliper(
                    topLeftRadius: 12.0 + _counter,
                    bottomRightRadius: 20.0 - _counter),
                child: new Container(
                  width: 200,
                  height: 200,
                  color: Colors.red,
                ),
              ),
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: _incrementCounter,
          tooltip: 'Increment',
          child: Icon(Icons.add),
        ));
  }
}

The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application

For more information about Flutter. visit www.fluttertutorial.in