我想直接在应用程序栏上打开iconButton的onTap来打开新页面,但导航器不起作用。我在应用程序栏上尝试了FlatBitton.Icon而不是图标按钮,但它使页面崩溃了。
答案 0 :(得分:0)
这是一个例子:
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: 'Navigation Basics',
home: FirstRoute(),
));
}
class FirstRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First Route'),
actions: [
IconButton(
icon: Icon(Icons.add_box),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),
);
},
),
],
),
body: Center(
child: Text('First route'),
),
);
}
}
class SecondRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Second Route"),
),
body: Center(
child: RaisedButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('Go back!'),
),
),
);
}
}