Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/foundation.dart';
- import 'package:flutter/material.dart';
- void main() => runApp(MyApp());
- class MyApp extends StatefulWidget {
- MyApp({Key key}) : super(key: key);
- State createState() => _MyAppState();
- }
- class _MyAppState extends State<MyApp> {
- int _count = 0;
- final GlobalKey keyScaffold = new GlobalKey();
- String hasAppBar = '';
- String hasDrawer = '';
- String hasEndDrawer = '';
- String hasFloatingActionButton = '';
- String appBarMaxHeight = '';
- String isDrawerOpen = '';
- String isEndDrawerOpen = '';
- bool hadDrawerOpened = false;
- PersistentBottomSheetController<Null> sheet;
- @override
- Widget build(BuildContext context) {
- final title = 'Floating App Bar';
- final ThemeData theme = Theme.of(context);
- return MaterialApp(
- debugShowCheckedModeBanner: false,
- title: title,
- home: Scaffold(
- key: keyScaffold,
- appBar: AppBar(
- title: Text('Sample Code'),
- ),
- body: Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Text('You have pressed the button $_count times.'),
- RaisedButton(
- onPressed: () {
- ScaffoldState state = keyScaffold.currentState;
- if (hadDrawerOpened) {
- if (state.hasEndDrawer) state.openEndDrawer();
- } else {
- if (state.hasDrawer) state.openDrawer();
- }
- hadDrawerOpened = state.isDrawerOpen;
- setState(() {});
- sheet = state.showBottomSheet<Null>((BuildContext context) {
- return Container(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: <Widget>[
- Center(
- child: Text(
- 'Opened ${hadDrawerOpened ? 'left' : 'right'}-hand Drawer!',
- )),
- ],
- ));
- });
- },
- elevation: 20.0,
- textColor: theme.canvasColor,
- color: theme.primaryColor,
- child: Text('Open Drawers'),
- ),
- ],
- )),
- bottomNavigationBar: BottomAppBar(
- child: Container(
- height: 50.0,
- ),
- ),
- floatingActionButton: FloatingActionButton(
- onPressed: () => setState(() {
- _count++;
- }),
- tooltip: 'Increment Counter',
- child: Icon(Icons.add),
- ),
- floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
- drawer: _drawer,
- endDrawer: _drawer,
- ),
- );
- }
- Widget get _drawer => Drawer(
- // Add a ListView to the drawer. This ensures the user can scroll
- // through the options in the Drawer if there isn't enough vertical
- // space to fit everything.
- child: ListView(
- // Important: Remove any padding from the ListView.
- padding: EdgeInsets.zero,
- children: <Widget>[
- DrawerHeader(
- child: Text('Drawer Header'),
- decoration: BoxDecoration(
- color: Colors.blue,
- ),
- ),
- ListTile(
- title: Text('Item 1'),
- onTap: () {
- // Update the state of the app
- // ...
- // Then close the drawer
- Navigator.pop(context);
- },
- ),
- ListTile(
- title: Text('Item 2'),
- onTap: () {
- // Update the state of the app
- // ...
- // Then close the drawer
- Navigator.pop(context);
- },
- ),
- ],
- ),
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement