bezier.dart icon indicating copy to clipboard operation
bezier.dart copied to clipboard

Usage as Widget in Flutter

Open mariusbloemhof opened this issue 4 years ago • 2 comments

Hi,

How do I use this in a Widget in Flutter?

mariusbloemhof avatar Jul 31 '20 08:07 mariusbloemhof

import 'package:flutter/material.dart';
import "package:vector_math/vector_math.dart";
import "package:bezier/bezier.dart";

main() => runApp(MaterialApp(home: MyHomePage()));

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(''),
      ),
      body: CustomPaint(painter: MyPainter(),child: Container(height: 200, width: 200,),)
    );
  }
}

class MyPainter extends CustomPainter {
  final curve = CubicBezier([
    Vector2(10.0, 10.0),
    Vector2(70.0, 95.0),
    Vector2(25.0, 20.0),
    Vector2(15.0, 80.0)
  ]);

  @override
  void paint(Canvas canvas, Size size) {
    final points = curve.points;

    final path = Path()..moveTo(points[0].x, points[0].y)..cubicTo(curve.points[1].x, curve.points[1].y, curve.points[2].x,
        curve.points[2].y, curve.points[3].x, curve.points[3].y);
    canvas.drawPath(path, Paint());
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return false;
  }
}

idkq avatar May 03 '21 20:05 idkq

@mariusbloemhof check out this package if you need it for charts https://pub.dev/packages/smoothie

alxkzmn avatar May 29 '21 14:05 alxkzmn