How To Make Custom Clipper Example In Flutter Android App

admin_img Posted By Bajarangi soft , Posted On 24-09-2020

I have shown how to make Custom Clipper using Path. In other words it is also called quadratic bezier curves. See the example below and learn how to clip Custom Clipper using a custom path. Here, I have used quadraticBezierTo() to make bezier curves.

How To Make Custom Clipper Example In Flutter Android App

Lets start with creating a new flutter project in Android Studio by going to File => New => New Flutter Project.In order to download any custom package in our flutter project, all we need to do is to specify the package name into pubspec.yaml file.

Step 1
we will add  flutter_custom_clippers: ^1.1.2  dependency name to
our pubspec.yaml file as shown below:

dependencies:
  flutter:
    sdk: flutter
  flutter_custom_clippers: ^1.1.2


Step 2
You can install packages from the command line: with Flutter:
flutter pub get

Step 3
Now after adding the dependency and downloading, in order to use any package, we must import it before using it. So, in our case, we will import it in our main.dart file as:
import 'package:flutter_custom_clippers/flutter_custom_clippers.dart';

Step 4
 Now, We will create the Stateful Widget and inside the Scaffold widget we will add the following code:
YOu can add this Custom Clipper Example code :
ListView(
  padding: EdgeInsets.all(20.0),
  children: <Widget>[
    ClipPath(
      clipper: WaveClipperOne(flip: true, reverse: true),
      child: Container(
        height: 140,
        color: Colors.orange,
        child: Center(
            child: Text("flip: true,reverse: true")),
      ),
    ),
    SizedBox(height: 10.0),
    ClipPath(
      clipper: WaveClipperOne(flip: true),
      child: Container(
        height: 140,
        color: Colors.pink,
        child: Center(child: Text("flip: true")),
      ),
    ),
    SizedBox(height: 10.0),
    ClipPath(
      clipper: OvalBottomBorderClipper(),
      child: Container(
        height: 100,
        color: Colors.blue,
        child: Center(child: Text("BOttomBorderCliper")),
      ),
    ),
    SizedBox(height: 10.0),
    ClipPath(
      clipper: WaveClipperTwo(flip: true),
      child: Container(
        height: 140,
        color: Colors.red,
        child: Center(child: Text("true")),
      ),
    ),
    SizedBox(height: 10.0),
    ClipPath(
      clipper: SideCutClipper(),
      child: Container(
        height: 200,
        color: Colors.lightGreen,
        //play with scals to get more clear versions
        child: Center(child: Text("SideCutClipper")),
      ),
    ),
    SizedBox(height: 10.0),
    ClipPath(
      clipper: ArcClipper(),
      child: Container(
        height: 100,
        color: Colors.lime,
        child: Center(child: Text("ArcClipper")),
      ),
    ),
    SizedBox(height: 10.0),
    ClipPath(
      clipper: TriangleClipper(),
      child: Container(
        height: 100,
        color: Colors.deepOrange,
        child: Center(child: Text("TriangleClipper")),
      ),
    ),

  ],
),

Complete Code Custom Clipper Example  in flutter
Main.dart
import 'package:flutter/material.dart';
import 'package:flutter_custom_clippers/flutter_custom_clippers.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: "My App",
      home: CustomClipper(),
    );
  }
}


class CustomClipper extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return _CustomClipper();
  }
}

class _CustomClipper extends State<CustomClipper> with SingleTickerProviderStateMixin {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Custom Clipper Shapes Examples"),
        backgroundColor: Colors.deepPurple[400],
      ),
      body: ListView(
        padding: EdgeInsets.all(20.0),
        children: <Widget>[
          ClipPath(
            clipper: WaveClipperOne(flip: true, reverse: true),
            child: Container(
              height: 140,
              color: Colors.orange,
              child: Center(
                  child: Text("flip: true,reverse: true")),
            ),
          ),
          SizedBox(height: 10.0),
          ClipPath(
            clipper: WaveClipperOne(flip: true),
            child: Container(
              height: 140,
              color: Colors.pink,
              child: Center(child: Text("flip: true")),
            ),
          ),
          SizedBox(height: 10.0),
          ClipPath(
            clipper: OvalBottomBorderClipper(),
            child: Container(
              height: 100,
              color: Colors.blue,
              child: Center(child: Text("BOttomBorderCliper")),
            ),
          ),
          SizedBox(height: 10.0),
          ClipPath(
            clipper: WaveClipperTwo(flip: true),
            child: Container(
              height: 140,
              color: Colors.red,
              child: Center(child: Text("true")),
            ),
          ),
          SizedBox(height: 10.0),
          ClipPath(
            clipper: SideCutClipper(),
            child: Container(
              height: 200,
              color: Colors.lightGreen,
              //play with scals to get more clear versions
              child: Center(child: Text("SideCutClipper")),
            ),
          ),
          SizedBox(height: 10.0),
          ClipPath(
            clipper: ArcClipper(),
            child: Container(
              height: 100,
              color: Colors.lime,
              child: Center(child: Text("ArcClipper")),
            ),
          ),
          SizedBox(height: 10.0),
          ClipPath(
            clipper: TriangleClipper(),
            child: Container(
              height: 100,
              color: Colors.deepOrange,
              child: Center(child: Text("TriangleClipper")),
            ),
          ),

        ],
      ),
    );
  }
}

Related Post