Flutter- Routing to a different .dart file

别说谁变了你拦得住时间么 提交于 2021-02-07 10:55:04

问题


I am trying to create a project where a user can click on a tab in the navigation drawer and it will take them to a page where they can play a quiz. I am having trouble having the user click on the tab and it redirecting them to another .dart file that I have that contains all the code necessary for the quiz. I am very new to Flutter so any information and advice helps. If you have any questions or need information from me please just ask.

import 'package:flutter/material.dart';

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
  return new MaterialApp(
    title: 'Flutter App',
    theme: new ThemeData(
      primarySwatch: Colors.blue,
     ),
      home: new HomePage(title: 'HomePage'),
      );
   }
 }

class HomePage extends StatefulWidget {
  @override
 _HomePageState createState() => new _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
    Widget build(BuildContext context) {
      return new Scaffold(
        appBar: new AppBar(title: new Text("Knowledge Burst"), 
 backgroundColor: Colors.redAccent,),
        drawer: new Drawer(
            child: new ListView(
                children: <Widget>[
                    new UserAccountsDrawerHeader(
                        accountName: new Text("Knowledge Burst"),
                        accountEmail: null,
                        decoration: new BoxDecoration(
                            image: new DecorationImage(
                                fit: BoxFit.fill,
                                image: new NetworkImage("")
                            )
                        ),
                    ),
                    new ListTile(
                        title: new Text("History of FBLA"),
                        trailing: new Icon(Icons.arrow_upward),

                    ),
                    new ListTile(
                        title: new Text("FBLA Sponsered"),
                        trailing: new Icon(Icons.arrow_upward),
                    ),
                    new ListTile(
                        title: new Text("FBLA National Office Holders"),
                        trailing: new Icon(Icons.arrow_upward),
                    ),
                    new Divider(),
                    new ListTile(
                        title: new Text("Economics"),
                        trailing: new Icon(Icons.arrow_upward),
                    ),
                    new ListTile(
                        title: new Text("Entrepreneurship"),
                        trailing: new Icon(Icons.arrow_upward),
                    ),
                    new Divider(),
                    new ListTile(
                        title: new Text("License and Terms of Use"),
                        trailing: new Icon(Icons.arrow_upward),
                    ),
                    new Divider(),
                    new ListTile(
                        title: new Text("Close"),
                        trailing: new Icon(Icons.cancel),
                        onTap: () => Navigator.of(context).pop(),
                    ),
                ],
            ),
        ),
        body: new Center(
            child: new Text("HomePage", style: new TextStyle(fontSize: 
 35.0),),
        ),
    );
}
}

回答1:


You can utilize the onTap method here on ListTile to navigate

  new ListTile(
        title: new Text("Economics"),
        trailing: new Icon(Icons.arrow_upward),
        onTap: (){
          Navigator.push(
            context,
            MaterialPageRoute(builder: (context) => NewScreen()),
          );
        },
      ),


来源:https://stackoverflow.com/questions/53576925/flutter-routing-to-a-different-dart-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!