Skip to content

Instantly share code, notes, and snippets.

@RipplesCode
Created January 5, 2021 11:47
Show Gist options
  • Save RipplesCode/839669bd482503cb377aecebf1c52352 to your computer and use it in GitHub Desktop.
Save RipplesCode/839669bd482503cb377aecebf1c52352 to your computer and use it in GitHub Desktop.
Navigation without 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: () {},
),
SizedBox(
height: 8,
),
RaisedButton(
child: Text(
"Back to Main",
style: TextStyle(fontSize: 18),
),
color: Colors.lightBlue,
textColor: Colors.white,
onPressed: () {
//Get.back();
// Send data to previous screen must use result as name
// Get.back(result: 'This is from Home Screen');
},
),
SizedBox(
height: 8,
),
// Text(
// "${Get.arguments}",
// style: TextStyle(color: Colors.green, fontSize: 20),
// )
],
),
),
);
}
}
import 'package:flutter/material.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",
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.to(
Home(),
// To make the screen full dialog
// fullscreenDialog: true,
// To provide animations
//transition: Transition.zoom,
// Duration for transition animation
// duration: Duration(milliseconds: 4000),
// Curve Animation
// curve: Curves.bounceInOut,
);
// Go to home screen but no option to return to previous screen
// Get.off(Home());
// Go to home screen and cancel all previous screens/routes
//Get.offAll(Home());
// Go the next screen with some data
// Get.to(Home(),arguments:"Data from Main");
// Go to next screen and receive data sent from home screen
// var data=await Get.to(Home());
// print("The Received data is $data");
},
),
],
)),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment