persistent_bottom_sheet_demo.dart 2.5 KB
Newer Older
1 2 3 4 5 6
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';

7
class PersistentBottomSheetDemo extends StatefulWidget {
8 9
  static const String routeName = '/persistent-bottom-sheet';

10 11 12 13 14 15
  @override
  _PersistentBottomSheetDemoState createState() => new _PersistentBottomSheetDemoState();
}

class _PersistentBottomSheetDemoState extends State<PersistentBottomSheetDemo> {
  final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
16

17 18 19 20 21
  VoidCallback _showBottomSheetCallback;

  @override
  void initState() {
    super.initState();
22
    _showBottomSheetCallback = _showBottomSheet;
23 24 25
  }


26
  void _showBottomSheet() {
27 28 29 30
    setState(() { // disable the button
      _showBottomSheetCallback = null;
    });
    _scaffoldKey.currentState.showBottomSheet/*<Null>*/((BuildContext context) {
31
      final ThemeData themeData = Theme.of(context);
32 33
      return new Container(
        decoration: new BoxDecoration(
34
          border: new Border(top: new BorderSide(color: themeData.disabledColor))
35 36
        ),
        child: new Padding(
37
          padding: const EdgeInsets.all(32.0),
38
          child: new Text('This is a Material persistent bottom sheet. Drag downwards to dismiss it.',
39 40 41 42 43
            textAlign: TextAlign.center,
            style: new TextStyle(
              color: themeData.accentColor,
              fontSize: 24.0
            )
44
          )
45 46
        )
      );
47 48 49
    })
    .closed.then((_) {
      setState(() { // re-enable the button
50
        _showBottomSheetCallback = _showBottomSheet;
51
      });
52 53 54
    });
  }

55 56 57
  void _showMessage()  {
    showDialog(
      context: context,
58
      child: new AlertDialog(
59 60 61
        content: new Text('You tapped the floating action button.'),
        actions: <Widget>[
          new FlatButton(
62
            onPressed: () { Navigator.pop(context); },
63 64 65 66 67 68 69
            child: new Text('OK')
          )
        ]
      )
    );
  }

70
  @override
71
  Widget build(BuildContext context) {
72
    return new Scaffold(
73
      key: _scaffoldKey,
74
      appBar: new AppBar(title: new Text('Persistent bottom sheet')),
75
      floatingActionButton: new FloatingActionButton(
76
        onPressed: _showMessage,
77
        backgroundColor: Colors.redAccent[200],
Ian Hickson's avatar
Ian Hickson committed
78
        child: new Icon(Icons.add)
79
      ),
80 81 82 83 84
      body: new Center(
        child: new RaisedButton(
          onPressed: _showBottomSheetCallback,
          child: new Text('SHOW BOTTOM SHEET')
        )
85 86 87 88
      )
    );
  }
}