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: Container( | |
decoration: BoxDecoration( | |
image: DecorationImage( | |
fit: BoxFit.cover, | |
image: NetworkImage( | |
"https://homepages.cae.wisc.edu/~ece533/images/watch.png"), | |
colorFilter: ColorFilter.mode( | |
Colors.white.withOpacity(0.3), BlendMode.dstIn))), | |
child: ListView( | |
padding: EdgeInsets.zero, | |
children: <Widget>[ | |
DrawerHeader( | |
child: Text('Cabeçalho'), | |
decoration: BoxDecoration( | |
color: Colors.white, | |
image: DecorationImage( | |
fit: BoxFit.cover, | |
image: NetworkImage( | |
"https://homepages.cae.wisc.edu/~ece533/images/monarch.png" | |
), | |
colorFilter: ColorFilter.mode( | |
Colors.white.withOpacity(0.3), BlendMode.dstIn))), | |
), | |
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