Created
August 11, 2019 00:53
-
-
Save luizmarcus/4c2e5f1b344dcb3ffeabec74947b4f1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'fragment.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
title: 'Exemplo Drawer', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MyHomePage(title: 'Exemplo Drawer'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
final String title; | |
const MyHomePage({Key key, this.title}) : super(key: key); | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
int _selectedIndex = 0; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: new AppBar( | |
title: new Text(widget.title), | |
), | |
drawer: Drawer( | |
child: ListView( | |
padding: EdgeInsets.zero, | |
children: <Widget>[ | |
DrawerHeader( | |
child: Text('Cabeçalho'), | |
decoration: BoxDecoration( | |
color: Colors.blue, | |
), | |
), | |
ListTile( | |
title: Text('Item 1'), | |
selected: 0 == _selectedIndex, | |
onTap: () { | |
_onSelectItem(0); | |
}, | |
), | |
ListTile( | |
title: Text('Item 2'), | |
selected: 1 == _selectedIndex, | |
onTap: () { | |
_onSelectItem(1); | |
}, | |
), | |
], | |
), | |
), | |
body: _getDrawerItem(_selectedIndex), | |
); | |
} | |
_getDrawerItem(int pos) { | |
switch (pos) { | |
case 0: | |
return Fragment("Tela 1"); | |
case 1: | |
return Fragment("Tela 2"); | |
} | |
} | |
_onSelectItem(int index) { | |
setState(() => _selectedIndex = index); | |
Navigator.of(context).pop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment