Last active
September 21, 2020 15:32
-
-
Save roipeker/6336a86210a4986912d7b3a97d063270 to your computer and use it in GitHub Desktop.
Persistent menu in nav (for Katekko)
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/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:get/get.dart'; | |
void main() { | |
runApp(GetMaterialApp( | |
home: _MyHome(), | |
builder: MyRootWidget.builder, | |
)); | |
} | |
class _MyHome extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('page 1'), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Text('Hello world'), | |
FlatButton( | |
onPressed: () => Get.to(_MySecondPage()), | |
child: Text('To second page')) | |
], | |
), | |
), | |
); | |
} | |
} | |
class _MySecondPage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('second page'), | |
), | |
body: Center( | |
child: Text('Bye World!'), | |
), | |
); | |
} | |
} | |
/// custom utils. | |
/// | |
class MyPersistentDrawer extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
width: 300, | |
height: double.infinity, | |
color: Colors.grey.shade600, | |
padding: EdgeInsets.symmetric(vertical: 24, horizontal: 12), | |
child: Column( | |
children: [ | |
CircleAvatar( | |
child: Icon(Icons.ac_unit), | |
), | |
Text( | |
'My drawer', | |
style: TextStyle( | |
fontSize: 24, | |
color: Colors.white, | |
fontWeight: FontWeight.bold, | |
), | |
), | |
Divider( | |
color: Colors.white10, | |
height: 24, | |
), | |
/// menu data here. | |
], | |
), | |
); | |
} | |
} | |
class MyRootWidget extends StatelessWidget { | |
static Widget builder(BuildContext ctx, Widget child) => | |
MyRootWidget(child: child); | |
// define order to draw the Drawer menu. | |
final drawerOnTop = true; | |
const MyRootWidget({Key key, this.child}) : super(key: key); | |
final Widget child; | |
@override | |
Widget build(BuildContext context) { | |
final children = <Widget>[ | |
MyPersistentDrawer(), | |
Expanded(child: child), | |
]; | |
return Scaffold( | |
body: Row( | |
textDirection: drawerOnTop ? TextDirection.rtl : TextDirection.ltr, | |
children: drawerOnTop ? children.reversed.toList() : children, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment