Created
July 29, 2019 18:20
-
-
Save gladson/5c16f23b0945ba873a72d4177115e90c to your computer and use it in GitHub Desktop.
Drawer + PageView
This file contains hidden or 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'; | |
class Home extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Home', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
backgroundColor: Colors.white | |
), | |
home: HomePage(), | |
debugShowCheckedModeBanner: false, | |
); | |
} | |
} | |
class HomePage extends StatefulWidget { | |
@override | |
_HomePageState createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<HomePage> with TickerProviderStateMixin { | |
PageController controllerMenu; | |
@override | |
void initState() { | |
controllerMenu = new PageController( | |
initialPage: 0, | |
keepPage: false, | |
viewportFraction: 0.5, | |
); | |
super.initState(); | |
} | |
@override | |
void dispose() { | |
controllerMenu.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
// title: Text("Ola"), | |
), | |
body: Container( | |
child: Center( | |
child: Text( | |
"Vista Tecnologia", | |
style: TextStyle( | |
color: Colors.black, | |
fontSize: 50 | |
), | |
), | |
), | |
), | |
drawer: Drawer( | |
elevation: 25, | |
child: Column( | |
children: <Widget>[ | |
UserAccountsDrawerHeader( | |
accountName: Text("Gladson"), | |
accountEmail: Text("[email protected]"), | |
currentAccountPicture: CircleAvatar( | |
backgroundImage: NetworkImage( | |
"https://avatars0.githubusercontent.com/u/1013698?s=150" | |
), | |
), | |
), | |
Expanded( | |
child: Container( | |
color: Colors.amberAccent, | |
child: PageView( | |
controller: controllerMenu, | |
physics: AlwaysScrollableScrollPhysics(), | |
scrollDirection: Axis.horizontal, | |
onPageChanged: (value) { | |
setState(() { | |
menu = value; | |
print(menu); | |
}); | |
}, | |
children: <Widget>[ | |
Scaffold( | |
body: Container( | |
color: Colors.red, | |
child: Center( | |
child: RaisedButton( | |
color: Colors.white, | |
onPressed: () { | |
if (controllerMenu.hasClients) { | |
controllerMenu.animateToPage( | |
1, | |
duration: const Duration(milliseconds: 400), | |
curve: Curves.easeInOut, | |
); | |
} | |
}, | |
child: Text('Next'), | |
), | |
), | |
), | |
), | |
Container( | |
width: 350, | |
color: Colors.blue, | |
child: Center( | |
child: RaisedButton( | |
color: Colors.white, | |
onPressed: () { | |
if (controllerMenu.hasClients) { | |
controllerMenu.animateToPage( | |
0, | |
duration: const Duration(milliseconds: 400), | |
curve: Curves.easeInOut, | |
); | |
} | |
}, | |
child: Text('Previous'), | |
), | |
), | |
), | |
], | |
), | |
), | |
) | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment