Skip to main content

how to send one screen to another screen in flutter ?

 In Flutter, you can navigate between screens by using the Navigator widget. The Navigator provides a stack-based navigation system that allows you to push and pop routes (screens) from the stack.

To navigate to a new screen, you can use the Navigator.push() method and pass in the context and the route for the new screen. To go back to the previous screen, you can use the Navigator.pop() method.

Here's an example:


// First screen (current screen) class FirstScreen extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('First Screen')), body: Center( child: RaisedButton( child: Text('Go to second screen'), onPressed: () { Navigator.push( context, MaterialPageRoute(builder: (context) => SecondScreen()), ); }, ), ), ); } } // Second screen class SecondScreen extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('Second Screen')), body: Center( child: RaisedButton( child: Text('Go back'), onPressed: () { Navigator.pop(context); }, ), ), ); } }

You can also pass arguments to the new screen using MaterialPageRoute and ModalRoute with settings property. And these arguments can be accessed via ModalRoute.of(context).settings.arguments in the new screen.

Navigator.push( context, MaterialPageRoute( builder: (context) => SecondScreen(argument: 'Hello'), settings: RouteSettings(arguments: 'Hello')), );



class SecondScreen extends StatelessWidget { SecondScreen({this.argument}); final String argument; @override Widget build(BuildContext context) { final String args = ModalRoute.of(context).settings.arguments; return Scaffold( appBar: AppBar(title: Text('Second Screen')), body: Center( child: Text(args), ), ); } }





Popular posts from this blog

create MVVM Architecture Pattern for my android app

Here is an example of how you could implement the MVVM (Model-View-ViewModel) architecture pattern in an Android app using Java: Create a View class, for example MainActivity that extends AppCompatActivity and is responsible for handling user interactions and displaying data to the user. public class MainActivity extends AppCompatActivity { private ActivityMainBinding binding; private MainViewModel viewModel; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); binding = DataBindingUtil.setContentView(this, R.layout.activity_main); viewModel = new ViewModelProvider(this).get(MainViewModel.class); binding.setViewModel(viewModel); binding.setLifecycleOwner(this); } } } } Create a ViewModel class, for example MainViewModel that extends AndroidViewModel and is responsible for holding and processing the data for the View , as well as handling any business logicy code public cla...

how to send user location in background android code

  To send a user's location in the background in an Android application, you can use the FusedLocationProviderClient class to request location updates and the Service class to run a background service that can perform the location updates and send the data to your server or another destination. Here is an example of how to set up a background service that requests location updates every 5 minutes: Create a new service class that extends Service , for example LocationUpdateService . In the onCreate() method of the service, initialize the FusedLocationProviderClient and request location updates using the requestLocationUpdates() method. FusedLocationProviderClient fusedLocationClient; @Override public void onCreate() {     super.onCreate();     fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);     fusedLocationClient.requestLocationUpdates(             getLocationRequest(),     ...

How to create google map with drag marker to get user location with auto correct location edit text ...

For drag and drop with user location You have to create a google map fragment activity below are the xml code of google map xml <? xml version ="1.0" encoding ="utf-8" ?> < androidx.constraintlayout.widget.ConstraintLayout xmlns: android ="http://schemas.android.com/apk/res/android" xmlns: app ="http://schemas.android.com/apk/res-auto" xmlns: tools ="http://schemas.android.com/tools" android :layout_width ="match_parent" android :layout_height ="match_parent" tools :context =".GetUserLocationActivity" > < fragment android :id ="@+id/mapuserloc" android :name ="com.google.android.gms.maps.SupportMapFragment" android :layout_width ="match_parent" android :layout_height ="522dp" app :layout_constraintEnd_toEndOf ="parent" app :layout_constraintStart_toStartOf ="p...