Flutter : PopupMenuから画面遷移。AndroidとiPhone
Popupメニューからの画面遷移を試す。
- 以下のimportは遷移先画面
- ListTile を使って、アイコンとテキストを表示
- Icon https://api.flutter.dev/flutter/material/Icons-class.html
lib/main.dart
import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import './google_sign_in.dart'; import './firestore_cloud_vision.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { final message = "Initial Message."; @override Widget build(BuildContext context) { return new MaterialApp( title: 'Flutter Sample', home: MyHomePage(message:this.message), ); } } enum Menu { google_sign_in, firestore_cloud_vision } class MyHomePageState extends State<MyHomePage>{ @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.message) ), body: PopupMenuButton( onSelected: popupMenuSelected, itemBuilder: (BuildContext context) => <PopupMenuEntry<Menu>>[ const PopupMenuItem( child: const ListTile( leading:Icon(Icons.supervisor_account), title:Text("Google Sign In")), value: Menu.google_sign_in), const PopupMenuItem( child: const ListTile( leading:Icon(Icons.crop_original), title:Text("Firestore,CloudVision")), value: Menu.firestore_cloud_vision,), ], ), ); } void popupMenuSelected(Menu selectedMenu){ switch(selectedMenu) { case Menu.google_sign_in: _pushPage(context, GoogleSignInPage()); break; case Menu.firestore_cloud_vision: _pushPage(context, FirestoreCloudVisionPage()); break; default: break; } } void _pushPage(BuildContext context, Widget page) { Navigator.of(context).push( MaterialPageRoute<void>(builder: (_) => page) ); } } class MyHomePage extends StatefulWidget { final String message; MyHomePage({this.message}):super() {} @override State<StatefulWidget> createState() => new MyHomePageState(); }