Can I use onTap from ListTile to go to new screen?

In order to use Navigator to go to different pages, you need the BuildContext of your app. Here is an example of how you can get it:

import 'package:flutter/material.dart';
import 'package:rate_your_professor/screens/firstScreen.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Some App',
      home: SomeApp(),
    );
  }
}

class SomeApp extends StatelessWidget {
  Widget getListView(BuildContext context) {
    var listView = ListView(
      children: <Widget>[
        Text(
          "XXXXXXXXXXXXXXX",
          textDirection: TextDirection.rtl,
          textAlign: TextAlign.center,
        ),
        ListTile(
          leading: Icon(Icons.location_city),
          title: Text("XXXXX ", textDirection: TextDirection.rtl),
          subtitle: Text(
            "XXXXXXXXXX",
            textDirection: TextDirection.rtl,
          ),
          onTap: () {
            Navigator.push(
              context,
              MaterialPageRoute(
                  builder: (context) => YourNewPage(),
                  ),
            );
          },
        ),
      ],
    );
    return listView;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(body: getListView(context));
  }
}

You can navigate to the next screen using a Navigator

Here you need to use the Navigator.push if you want to go to the new screen and back.

Navigator.push(
    context,
    MaterialPageRoute(builder: (context) => SecondScreen()),
  );

Meanwhile, check the official documentation for more information on the navigation.

Tags:

Dart

Flutter