import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(primarySwatch: Colors.blue),
home: new FlutterDemo()));
}
class FlutterDemo extends StatelessWidget {
FlutterDemo({Key key}) : super(key: key);
void push(BuildContext context) {
Navigator.push(context,
new MaterialPageRoute(builder: (BuildContext context) {
return new OtherRoute();
}));
}
void pushSearch(BuildContext context) {
Navigator.push(context,
new MaterialPageRoute(builder: (BuildContext context) {
return new SearchScreen();
}));
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title: new Text("Demo"), actions: [
new IconButton(
icon: Icon(Icons.search), onPressed: () => pushSearch(context)),
new PopupMenuButton(onSelected: (String item) {
switch (item) {
case 'push':
push(context);
break;
case 'pushSearch':
pushSearch(context);
break;
}
//push(context);
}, itemBuilder: (BuildContext context) {
return [
new PopupMenuItem(value: "push", child: new Text("push route")),
new PopupMenuItem(value: "pushSearch", child: new Text("push search")),
];
})
]),
body: new Column(children: [
new RaisedButton(
child: new Text("push route"), onPressed: () => push(context)),
new PopupMenuButton(onSelected: (String item) {
if (item == "push") {
push(context);
} else {
pushSearch(context);
}
//push(context);
}, itemBuilder: (BuildContext context) {
return [
new PopupMenuItem(value: "push", child: new Text("push route")),
new PopupMenuItem(value: "pushSearch", child: new Text("push search")),
];
})
]));
}
}
class OtherRoute extends StatelessWidget {
OtherRoute({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title: new Text("other route")),
body: new Center(child: new Text("push route")));
}
}
class SearchScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
body: Center(
child: Text('Search Screen'),
),
);
}
}