Instantly share code, notes, and snippets.
Created May 30, 2020
Get navigation snippet
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 'package:get/get.dart'; | |
void main() => runApp(GetDemoApp()); | |
class GetDemoApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return GetMaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: FirstPage(), | |
); | |
} | |
} | |
class FirstPage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return CommonWidget("First Page"); | |
} | |
} | |
class SecondPage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return CommonWidget("Second Page"); | |
} | |
} | |
class DialogWidget extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Container(child: CommonWidget("Dialog"), margin: EdgeInsets.all(32)); | |
} | |
} | |
class CommonWidget extends StatelessWidget { | |
const CommonWidget(this.title); | |
final String title; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(title, style: TextStyle(fontSize: 20)), | |
), | |
body: Row(mainAxisAlignment: MainAxisAlignment.center, children: [ | |
Column(crossAxisAlignment: CrossAxisAlignment.center, children: [ | |
Text(title, style: TextStyle(fontSize: 30)), | |
Padding( | |
padding: const EdgeInsets.all(32.0), | |
child: Container( | |
child: Text("Demo Widget", style: TextStyle(fontSize: 24)), | |
), | |
), | |
Column(children: [ | |
MaterialButton( | |
child: Text("Go Back"), | |
color: Colors.blue, | |
onPressed: () { | |
Get.back(); | |
}), | |
MaterialButton( | |
child: Text("Go to First Page"), | |
color: Colors.blue, | |
onPressed: () { | |
Navigator.of( | |
MaterialPageRoute(builder: (context) => FirstPage())); | |
Get.to(FirstPage()); | |
}), | |
MaterialButton( | |
child: Text("Go to Second Page"), | |
color: Colors.blue, | |
onPressed: () { | |
Get.to(SecondPage()); | |
}), | |
MaterialButton( | |
child: Text("Show Dialog"), | |
color: Colors.blue, | |
onPressed: () { | |
Get.dialog(DialogWidget()); | |
}, | |
), | |
MaterialButton( | |
child: Text("Show Snackbar"), | |
color: Colors.blue, | |
onPressed: () { | |
Get.snackbar( | |
"Snackbar testobs", | |
"Hello this is Snackbar using awesome get Library by jonataslaw", | |
snackPosition: SnackPosition.BOTTOM, | |
); | |
}) | |
]) | |
]) | |
]), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment