Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. import 'package:flutter/foundation.dart';
  2. import 'package:flutter/material.dart';
  3.  
  4. void main() => runApp(MyApp());
  5.  
  6. class MyApp extends StatefulWidget {
  7. MyApp({Key key}) : super(key: key);
  8. State createState() => _MyAppState();
  9. }
  10.  
  11. class _MyAppState extends State<MyApp> {
  12. int _count = 0;
  13. final GlobalKey keyScaffold = new GlobalKey();
  14. String hasAppBar = '';
  15. String hasDrawer = '';
  16. String hasEndDrawer = '';
  17. String hasFloatingActionButton = '';
  18. String appBarMaxHeight = '';
  19. String isDrawerOpen = '';
  20. String isEndDrawerOpen = '';
  21. bool hadDrawerOpened = false;
  22. PersistentBottomSheetController<Null> sheet;
  23. @override
  24. Widget build(BuildContext context) {
  25. final title = 'Floating App Bar';
  26. final ThemeData theme = Theme.of(context);
  27. return MaterialApp(
  28. debugShowCheckedModeBanner: false,
  29. title: title,
  30. home: Scaffold(
  31. key: keyScaffold,
  32. appBar: AppBar(
  33. title: Text('Sample Code'),
  34. ),
  35. body: Center(
  36. child: Column(
  37. mainAxisAlignment: MainAxisAlignment.center,
  38. children: <Widget>[
  39. Text('You have pressed the button $_count times.'),
  40. RaisedButton(
  41. onPressed: () {
  42. ScaffoldState state = keyScaffold.currentState;
  43. if (hadDrawerOpened) {
  44. if (state.hasEndDrawer) state.openEndDrawer();
  45. } else {
  46. if (state.hasDrawer) state.openDrawer();
  47. }
  48. hadDrawerOpened = state.isDrawerOpen;
  49. setState(() {});
  50. sheet = state.showBottomSheet<Null>((BuildContext context) {
  51. return Container(
  52. child: Column(
  53. mainAxisSize: MainAxisSize.min,
  54. children: <Widget>[
  55. Center(
  56. child: Text(
  57. 'Opened ${hadDrawerOpened ? 'left' : 'right'}-hand Drawer!',
  58. )),
  59. ],
  60. ));
  61. });
  62. },
  63. elevation: 20.0,
  64. textColor: theme.canvasColor,
  65. color: theme.primaryColor,
  66. child: Text('Open Drawers'),
  67. ),
  68. ],
  69. )),
  70. bottomNavigationBar: BottomAppBar(
  71. child: Container(
  72. height: 50.0,
  73. ),
  74. ),
  75. floatingActionButton: FloatingActionButton(
  76. onPressed: () => setState(() {
  77. _count++;
  78. }),
  79. tooltip: 'Increment Counter',
  80. child: Icon(Icons.add),
  81. ),
  82. floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
  83. drawer: _drawer,
  84. endDrawer: _drawer,
  85. ),
  86. );
  87. }
  88.  
  89. Widget get _drawer => Drawer(
  90. // Add a ListView to the drawer. This ensures the user can scroll
  91. // through the options in the Drawer if there isn't enough vertical
  92. // space to fit everything.
  93. child: ListView(
  94. // Important: Remove any padding from the ListView.
  95. padding: EdgeInsets.zero,
  96. children: <Widget>[
  97. DrawerHeader(
  98. child: Text('Drawer Header'),
  99. decoration: BoxDecoration(
  100. color: Colors.blue,
  101. ),
  102. ),
  103. ListTile(
  104. title: Text('Item 1'),
  105. onTap: () {
  106. // Update the state of the app
  107. // ...
  108. // Then close the drawer
  109. Navigator.pop(context);
  110. },
  111. ),
  112. ListTile(
  113. title: Text('Item 2'),
  114. onTap: () {
  115. // Update the state of the app
  116. // ...
  117. // Then close the drawer
  118. Navigator.pop(context);
  119. },
  120. ),
  121. ],
  122. ),
  123. );
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement