Flutter: Drawerメニューのサンプル
トップ画面のメニューにポップアップメニューを追加したが、ドロワーメニューに変える。
import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import './google_sign_in.dart'; import './firestore_cloud_vision.dart'; import './firebase_auth.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, firebase_auth } class MyHomePageState extends State<MyHomePage>{ @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.message) ), drawer: Drawer( child: ListView( children: <Widget>[ DrawerHeader( child: Text('Drawer Header'), decoration: BoxDecoration( color: Colors.blue, ), ), ListTile( leading:Icon(Icons.account_box), title:Text("Google Sign In"), onTap: () => drawerMenuSelected(Menu.google_sign_in)), ListTile( leading:Icon(Icons.account_circle), title:Text("Firebase Auth"), onTap: () => drawerMenuSelected(Menu.firebase_auth)), ListTile( leading:Icon(Icons.crop_original), title:Text("Firestore,CloudVision"), onTap: () => drawerMenuSelected(Menu.firestore_cloud_vision)), ], ), ), ); } void drawerMenuSelected(Menu selectedMenu){ switch(selectedMenu) { case Menu.google_sign_in: _pushPage(context, GoogleSignInPage()); break; case Menu.firebase_auth: _pushPage(context, FirebaseAuthPage()); 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(); }