Pen Settings

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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() => runApp(App());

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Expanded/Flexible Demo',
      home: Scaffold(
        body: Scaffold(
          appBar: AppBar(),
          body: ExpandedVsFlexible(),
        ),
      ),
    );
  }
}

class ExpandedVsFlexible extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView(
      children: <Widget>[
        getWidget(0, 1),
        getWidget(2, 3),
        getWidget(4, 5),
        getWidget(3, 6),
        getWidget(2, 7),
      ],
    );
  }

  Widget getWidget(int first, int second) {
    return Column(
      children: <Widget>[
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: Text("Using weight $first and $second"),
        ),
        Row(children: <Widget>[fleWid(first), fleWid(first)]),
        Row(children: <Widget>[fleWid(first), fleWid(second)]),
        Row(children: <Widget>[expWid(first), expWid(first)]),
        Row(children: <Widget>[expWid(first), expWid(second)]),
        //
        Row(children: <Widget>[fleWid(second), fleWid(second)]),
        Row(children: <Widget>[fleWid(second), fleWid(first)]),
        Row(children: <Widget>[expWid(second), expWid(second)]),
        Row(children: <Widget>[expWid(second), expWid(first)]),
        //
        Row(children: <Widget>[fleWid(first), expWid(first)]),
        Row(children: <Widget>[expWid(first), fleWid(first)]),
        Row(children: <Widget>[fleWid(second), expWid(second)]),
        Row(children: <Widget>[expWid(second), fleWid(second)]),
        //
        Row(children: <Widget>[expWid(first), fleWid(first)]),
        Row(children: <Widget>[fleWid(first), expWid(first)]),
        Row(children: <Widget>[expWid(second), fleWid(second)]),
        Row(children: <Widget>[fleWid(second), expWid(second)]),
        //
      ],
    );
  }

  Widget expWid(int weight) {
    return Expanded(
      flex: weight,
      child: Padding(
        padding: const EdgeInsets.all(2.0),
        child: Container(
          color: Colors.green,
          child: Text("Expanded $weight"),
        ),
      ),
    );
  }

  Widget fleWid(int weight) {
    return Flexible(
      flex: weight,
      child: Padding(
        padding: const EdgeInsets.all(2.0),
        child: Container(
          color: Colors.red,
          child: Text("Flexible $weight"),
        ),
      ),
    );
  }
}

              
            
!
999px

Console