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 esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM 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 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData.light().copyWith(
primaryColor: Color(0xFF090C22),
scaffoldBackgroundColor: Color(0xFF090C22),
appBarTheme: AppBarTheme(
color: Colors.red[900],
textTheme: TextTheme(
headline6: TextStyle(
fontSize: 24.0,
fontWeight: FontWeight.w500,
),
),
),
textTheme: TextTheme(
bodyText2: TextStyle(
fontSize: 22.0,
fontWeight: FontWeight.w600,
),
subtitle1: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.w600,
),
),
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'Movies',
),
),
body: MovieListView(),
// body: MovieScreen(),
);
}
}
class MovieListView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
padding: EdgeInsets.all(20),
children: <Widget>[
MovieTile(movieName: 'The Godfather'),
MovieTile(movieName: 'The Notebook'),
],
),
);
}
}
class MovieTile extends StatefulWidget {
final String movieName;
MovieTile({@required this.movieName});
@override
_MovieTileState createState() => _MovieTileState();
}
class _MovieTileState extends State<MovieTile> {
bool _isFavorite = false;
void _toggleFavorite() {
setState(() {
_isFavorite = !_isFavorite;
});
}
@override
Widget build(BuildContext context) {
return ListTile(
title: Text(
widget.movieName,
style: (_isFavorite)
? TextStyle(color: Colors.white)
: TextStyle(color: Colors.white38),
),
trailing: FavoriteIcon(
isFavorite: _isFavorite,
onPressedHandler: _toggleFavorite,
),
);
}
}
class FavoriteIcon extends StatelessWidget {
final bool isFavorite;
final Function onPressedHandler;
FavoriteIcon({
@required this.isFavorite,
@required this.onPressedHandler,
});
@override
Widget build(BuildContext context) {
return IconButton(
icon: (isFavorite)
? Icon(
Icons.favorite,
color: Colors.red,
)
: Icon(
Icons.favorite_border,
color: Colors.red,
),
onPressed: onPressedHandler,
);
}
}
Also see: Tab Triggers