Skip to content

Instantly share code, notes, and snippets.

@erluxman
Created May 30, 2020 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erluxman/2d1723e3395325fb5511809f6f95e21b to your computer and use it in GitHub Desktop.
Save erluxman/2d1723e3395325fb5511809f6f95e21b to your computer and use it in GitHub Desktop.
Get navigation snippet
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