Flutter-路由到其他.dart文件 [英] Flutter- Routing to a different .dart file
本文介绍了Flutter-路由到其他.dart文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个项目,用户可以在其中单击导航抽屉中的选项卡,并将其带到可以进行测验的页面.我无法让用户单击选项卡,并将其重定向到我拥有的另一个.dart文件,该文件包含测验所需的所有代码.我是Flutter的新手,因此任何信息和建议都对您有所帮助.如果您有任何疑问或需要我的信息,请问一下.
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),),
),
);
}
}
推荐答案
您可以在此处使用 ListTile
上的onTap方法进行导航
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()),
);
},
),
这篇关于Flutter-路由到其他.dart文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文