persistent_bottom_sheet_demo.dart 2.07 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 8 9 10 11
final TextStyle _kTextStyle = new TextStyle(
  color: Colors.indigo[400],
  fontSize: 24.0
);

12
class PersistentBottomSheetDemo extends StatefulWidget {
13 14
  static const String routeName = '/persistent-bottom-sheet';

15 16 17 18 19 20
  @override
  _PersistentBottomSheetDemoState createState() => new _PersistentBottomSheetDemoState();
}

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

22 23 24 25 26 27 28 29 30 31 32 33 34 35
  VoidCallback _showBottomSheetCallback;

  @override
  void initState() {
    super.initState();
    _showBottomSheetCallback = showBottomSheet;
  }


  void showBottomSheet() {
    setState(() { // disable the button
      _showBottomSheetCallback = null;
    });
    _scaffoldKey.currentState.showBottomSheet/*<Null>*/((BuildContext context) {
36 37
      return new Container(
        decoration: new BoxDecoration(
Hixie's avatar
Hixie committed
38
          border: new Border(top: new BorderSide(color: Colors.black26))
39 40
        ),
        child: new Padding(
41
          padding: const EdgeInsets.all(32.0),
42 43 44 45
          child: new Text('This is a Material persistent bottom sheet. Drag downwards to dismiss it.',
            style: _kTextStyle,
            textAlign: TextAlign.center
          )
46 47
        )
      );
48 49 50 51 52
    })
    .closed.then((_) {
      setState(() { // re-enable the button
        _showBottomSheetCallback = showBottomSheet;
      });
53 54 55
    });
  }

56
  @override
57
  Widget build(BuildContext context) {
58
    return new Scaffold(
59
      key: _scaffoldKey,
60
      appBar: new AppBar(title: new Text('Persistent bottom sheet')),
61
      floatingActionButton: new FloatingActionButton(
62
        child: new Icon(icon: Icons.add),
63 64
        backgroundColor: Colors.redAccent[200]
      ),
65 66 67 68 69
      body: new Center(
        child: new RaisedButton(
          onPressed: _showBottomSheetCallback,
          child: new Text('SHOW BOTTOM SHEET')
        )
70 71 72 73
      )
    );
  }
}