Pen Settings

JavaScript

Babel includes JSX processing.

Packages

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.

Behavior

Save Automatically?

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.

Flutter

              
                import 'package:flutter/material.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(
    MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Home(),
      // ignore: missing_return
      onGenerateRoute: (settings) {
        if (settings.name == Screen1.routeName) {
          return MaterialSlideOutRoute(
            builder: (context) => Screen1(),
            settings: settings,
          );
        }
        if (settings.name == Screen2.routeName) {
          return SlideInRoute(
            page: Screen2(),
            settings: settings,
          );
        }
      },
    ),
  );
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Home'), centerTitle: true),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Text('Screen 1 will enter using the default MaterialPageRoute transition'),
            SizedBox(height: 20),
            RaisedButton(
              child: Text('Go to Screen 1'),
              onPressed: () {
                Navigator.pushNamed(context, Screen1.routeName);
              },
            ),
          ],
        ),
      ),
    );
  }
}

class Screen1 extends StatelessWidget {
  static const routeName = '/screen1';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Screen 1'), centerTitle: true),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('Screen 1 will slide out when Screen 2 slides in'),
            SizedBox(height: 20),
            RaisedButton(
              child: Text('Go to Screen 2'),
              onPressed: () {
                Navigator.pushNamed(context, Screen2.routeName);
              },
            ),
          ],
        ),
      ),
    );
  }
}

class Screen2 extends StatelessWidget {
  static const routeName = '/screen2';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Screen 2'), centerTitle: true),
      body: Center(
        child: Text('Welcome to Screen 2'),
      ),
    );
  }
}

/// Extends [MaterialPageRoute] to use [secondaryAnimation] to slide out to the
/// left when transitioning to a [SlideInRoute].
class MaterialSlideOutRoute<T> extends MaterialPageRoute<T> {
  MaterialSlideOutRoute({builder, settings})
      : super(builder: builder, settings: settings);

  @override
  Widget buildTransitions(context, animation, secondaryAnimation, child) {
    return super.buildTransitions(
      context,
      animation,
      secondaryAnimation,
      SlideTransition(
        position: Tween<Offset>(begin: Offset.zero, end: Offset(-1, 0))
            .animate(secondaryAnimation),
        child: child,
      ),
    );
  }

  /// Ensure [secondaryAnimation] only runs when transitioning to a
  /// [SlideInRoute].
  @override
  bool canTransitionTo(TransitionRoute<dynamic> nextRoute) {
    return nextRoute is SlideInRoute;
  }
}

/// Uses the primary animation of a page route transition to slide the new page
/// in from the right.
class SlideInRoute<T> extends PageRouteBuilder<T> {
  SlideInRoute({Widget page, RouteSettings settings})
      : super(
          pageBuilder: (context, animation, secondaryAnimation) {
            return page;
          },
          transitionsBuilder: (context, animation, secondaryAnimation, child) {
            return SlideTransition(
              position:
                  Tween<Offset>(begin: const Offset(1, 0), end: Offset.zero)
                      .animate(animation),
              child: child,
            );
          },
          settings: settings,
        );
}
              
            
!
999px

Console