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

Auto Save

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(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'SliverAppBar'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin{
  bool _snap = false;
  bool _floating = false;

  TabController _tabController;
  
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = TabController(length: 3, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: <Widget>[
          //sliversのリストにSliverAppBarを設定する
          SliverAppBar(
            snap: _snap,
            floating: _floating,
            //appbarの高さを設定
            expandedHeight: 150.0,
            title: Text(widget.title),
            //appbar内に表示するウィジェットを設定
            leading: Container(
              color: Colors.green,
              child: Center(child: Text("leading")),
            ),
            actions: <Widget>[
              Container(
                color: Colors.yellow,
                child: Center(child: Text("action1")),
              ),
              Container(
                color: Colors.red,
                child: Center(child: Text("action2")),
              )
            ],
            bottom: PreferredSize(
              preferredSize: Size(30.0, 30.0),
              child: TabBar(
              tabs: <Widget>[
                  Tab(
                    text: "Tab1",
                    icon: FlutterLogo(),
                  ),
                  Tab(
                    text: "Tab2",
                    icon: FlutterLogo(),
                  ),
                  Tab(
                    text: "Tab3",
                    icon: FlutterLogo(),
                  ),
                ],
                controller: _tabController,
              ),
            ),
          ),
          SliverFixedExtentList(
            //子ウィジェットの高さを設定
            itemExtent: 150.0,
            delegate: SliverChildBuilderDelegate(
              (BuildContext context, int index) {
                return Container(
                  alignment: Alignment.center,
                  color: Colors.lightBlue[100 * (index % 9)],
                  child: Text("list item $index"),
                );
              },
              //子ウィジェットの表示数を設定
              childCount: 10,
            ),
          ),
        ],
      ),
      //画面下部にナビゲーションバーを表示する
      bottomNavigationBar: BottomAppBar(
        child: Padding(
          padding: const EdgeInsets.all(8.0),
          child: OverflowBar(
            overflowAlignment: OverflowBarAlignment.center,
            children: <Widget>[
              Row(
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  const Text("snap"),
                  Switch(
                    value: _snap,
                    onChanged: (bool value) {
                      setState(() {
                        _snap = value;
                        //スナップはFloatingが有効の時だけ使える
                        _floating = _floating || _snap;
                      });
                    },
                  ),
                ],
              ),
              Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  const Text("floating"),
                  Switch(
                    value: _floating,
                    onChanged: (bool value) {
                      setState(() {
                        _floating = value;
                        _snap = _floating && _snap;
                      });
                    },
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

              
            
!
999px

Console