Skip to content

Instantly share code, notes, and snippets.

@RipplesCode
Created January 5, 2021 11:48
Show Gist options
  • Save RipplesCode/acb6d6c57d5b1814b76c498280e22054 to your computer and use it in GitHub Desktop.
Save RipplesCode/acb6d6c57d5b1814b76c498280e22054 to your computer and use it in GitHub Desktop.
Navigation with named routes
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Home"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"This is Home Screen",
style: TextStyle(color: Colors.purpleAccent, fontSize: 30),
),
SizedBox(
height: 8,
),
RaisedButton(
child: Text(
"Next Screen",
style: TextStyle(fontSize: 18),
),
color: Colors.lightBlue,
textColor: Colors.white,
onPressed: () {
Get.toNamed("/nextScreen");
//Get.toNamed("/nextScreen/1234");
},
),
SizedBox(
height: 8,
),
RaisedButton(
child: Text(
"Back to Main",
style: TextStyle(fontSize: 18),
),
color: Colors.lightBlue,
textColor: Colors.white,
onPressed: () {
Get.back();
},
),
SizedBox(
height: 8,
),
// Text(
// "Channel name is ${Get.parameters['channel']} and content is ${Get.parameters['content']}",
// style: TextStyle(color: Colors.red, fontSize: 30),
// )
],
),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter_getx/next_screen.dart';
import 'package:flutter_getx/unknown_route.dart';
import 'package:get/get.dart';
import 'home.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return GetMaterialApp(
title: "Navigation",
initialRoute: "/",
defaultTransition: Transition.zoom,
getPages: [
GetPage(name: '/', page: () => MyApp()),
GetPage(name: '/home', page: () => Home()),
GetPage(
name: '/nextScreen',
page: () => NextScreen(),
// To control the transition route wise
// If specified will override the default transition
transition: Transition.leftToRight),
// GetPage(
// name: '/nextScreen/:someValue',
// page: () => NextScreen(),
// // To control the transition route wise
// // If specified will override the default transition
// transition: Transition.leftToRight)
],
//unknownRoute: GetPage(name: '/notfound', page: () => UnknownRoute()),
home: Scaffold(
appBar: AppBar(title: Text("Bottom Sheet")),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
RaisedButton(
child: Text("Go to Home"),
onPressed: () {
Get.toNamed(
"/home",
);
// Go to home screen but no option to return to previous screen
// Get.offNamed("/home");
// Go to home screen and cancel all previous screens/routes
//Get.offAllNamed("/home");
// Dynamic URL link
// Get.toNamed(
// "/home?channel=Ripples Code&content=Flutter GetX",
// );
},
),
],
)),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class NextScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Next Screen"),
),
body: Center(
child:
Text(
"This is next screen",
style: TextStyle(color: Colors.red, fontSize: 30),
),
// Text(
// "${Get.parameters['someValue']}",
// style: TextStyle(color: Colors.red, fontSize: 30),
// ),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment