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:math';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
main() {
runApp(MainApp());
}
class MainApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: MainPage(),
),
);
}
}
class MainPage extends StatefulWidget {
@override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
Color currentColor = Colors.blue;
var height = 150;
var width = 150;
var borderRadius = 10;
var alignment = Alignment.center;
var icon = Icons.home;
var backgroundColor = Colors.white;
@override
void initState() {
super.initState();
_init();
}
_init() async {
for (int i = 0; i < 100; i++) {
await Future.delayed(Duration(seconds: 1));
_randomizeParameters();
}
}
_randomizeParameters() {
setState(() {
height = Random().nextInt(100) + 80;
width = Random().nextInt(100) + 80;
var randomIndex = Random().nextInt(colors.length);
currentColor = colors[randomIndex];
backgroundColor = backgroundColors[randomIndex];
borderRadius = Random().nextInt(50) + 5;
var currentAlignment = Random().nextInt(alignments.length);
alignment = alignments[currentAlignment];
var iconsIndex = Random().nextInt(icons.length);
icon = icons[iconsIndex];
});
}
@override
Widget build(BuildContext context) {
return AnimatedContainer(
duration: Duration(milliseconds: 700),
alignment: alignment,
color: backgroundColor,
child: AnimatedPadding(
duration: Duration(milliseconds: 700),
padding: EdgeInsets.all(
height > width ? height.toDouble() : width.toDouble()),
child: AnimatedContainer(
duration: Duration(milliseconds: 700),
height: height.toDouble(),
width: width.toDouble(),
alignment: alignment,
curve: Curves.easeInCubic,
padding: EdgeInsets.all(height > width ? width / 10 : height / 10),
transform: Matrix4.rotationZ(height.toDouble() / 30),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Icon(
Icons.ac_unit,
color: Colors.white,
size: 30,
),
),
decoration: BoxDecoration(
color: currentColor,
borderRadius: BorderRadius.circular(borderRadius.toDouble())),
),
),
);
}
}
var colors = [
Colors.blue,
Colors.red,
Colors.pink,
Colors.green,
Colors.yellow,
Colors.black,
Colors.indigo
];
var backgroundColors = [
Colors.white,
Colors.black12,
Colors.grey,
Colors.cyanAccent,
Colors.lightBlueAccent,
Colors.purpleAccent,
Colors.yellowAccent
];
var icons = [
Icons.map,
Icons.add,
Icons.home,
Icons.person_outline,
Icons.extension,
Icons.ac_unit,
Icons.add_a_photo
];
var alignments = [
Alignment.center,
Alignment.centerLeft,
Alignment.centerRight,
Alignment.bottomCenter,
Alignment.bottomLeft,
Alignment.bottomRight,
Alignment.topCenter,
Alignment.topRight,
Alignment.topLeft,
];
Also see: Tab Triggers