JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
import 'dart:async';
import 'dart:ui';
import 'package:flutter/material.dart';
///
/// path
void main() {
runApp(MaterialApp(
home: Scaffold(body: Board()),
debugShowCheckedModeBanner: false,
));
}
final size = window.physicalSize / window.devicePixelRatio;
class Board extends StatefulWidget {
@override
_BoardState createState() => _BoardState();
}
class _BoardState extends State<Board> {
final List<Offset> _points = [];
// ignore: close_sinks
final StreamController<List<Offset>> _streamer =
StreamController<List<Offset>>();
Stream<List<Offset>> get point$ => _streamer.stream;
@override
Widget build(BuildContext context) => MouseRegion(
onHover: (details) => _streamer.add(_points..add(details.position)),
child: StreamBuilder<List<Offset>>(
initialData: _points,
stream: point$,
builder: (context, snapshot) =>
CustomPaint(size: size, painter: Painter(snapshot.data)),
),
);
@override
void dispose() {
_streamer.close();
super.dispose();
}
}
class Painter extends CustomPainter {
static const radius = 2.0;
static final fill = Paint()..color = Colors.red;
static final stroke = Paint()
..color = Colors.grey
..style = PaintingStyle.stroke;
final List<Offset> points;
const Painter(this.points);
@override
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);
}
}
@override
bool shouldRepaint(Painter oldDelegate) =>
true;
}
Also see: Tab Triggers