Pen Settings


Babel includes JSX processing.


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                import 'dart:async';
import 'dart:math';
import 'dart:ui';

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

/// max points.length

void main() {
    home: Scaffold(body: Board()),
    debugShowCheckedModeBanner: false,

final size = window.physicalSize / window.devicePixelRatio;

const maxPoints = 29;

class Board extends StatefulWidget {
  _BoardState createState() => _BoardState();

class _BoardState extends State<Board> {
  final List<Offset> _points = [];

  final StreamController<List<Offset>> _streamer =

  Stream<List<Offset>> get _point$ =>;

  void initState() {

  Widget build(BuildContext context) => MouseRegion(
        onHover: (details) => _streamer.add(_points..add(details.position)),
        child: StreamBuilder<List<Offset>>(
          initialData: _points,
          stream: _point$.map(
            (points) => points.skip(max(0, points.length - maxPoints)).toList(),
          builder: (context, snapshot) => CustomPaint(
            size: size,
            painter: Painter(,

  void dispose() {

class Painter extends CustomPainter {
  static const radius = 2.0;

  static final fill = Paint()..color =;

  static final stroke = Paint()
    ..color = Colors.grey = PaintingStyle.stroke;

  final List<Offset> points;

  const Painter(this.points);

  void paint(Canvas canvas, Size size) {
    if (points.isEmpty) return;

    for (final point in points) canvas.drawCircle(point, radius, fill);

    for (int i = 0; i < points.length - 1; i++) {
      canvas.drawLine(points[i], points[i + 1], stroke);

  bool shouldRepaint(Painter oldDelegate) =>
      !listEquals(points, oldDelegate.points);