Flutter Example Drawer

Flutter Example Drawer_第1张图片
import 'package:flutter/material.dart';
import 'package:drawer/screens/home.dart';
import 'package:drawer/screens/account.dart';
import 'package:drawer/screens/settings.dart';

void main() {
  runApp(new MaterialApp(
    home: HomeScreen(),
    routes: {
      // define the routes
      SettingsScreen.routename: (BuildContext context) => new SettingsScreen(),
      AccountScreen.routename: (BuildContext context) => new AccountScreen(),
    },
  ));
}

import 'package:flutter/material.dart';
import 'account.dart';
import 'settings.dart';

class HomeScreen extends StatefulWidget {
  @override
  State createState() => HomeScreenState();
}

class HomeScreenState extends State {
  Drawer getNavDrawer(BuildContext context) {
    var headerChild = new DrawerHeader(
      child: new Text("Header"),
    );
    var aboutChild = new AboutListTile(
        child: new Text("About"),
        applicationName: "Application Name",
        applicationVersion: "v1.0.0",
        applicationIcon: new Icon(Icons.adb),
        icon: new Icon(Icons.info));
    ListTile getNavItem(var icon, String s, String routeName) {
      return new ListTile(
        leading: new Icon(icon),
        title: new Text(s),
        onTap: () {
          setState(() {
            Navigator.of(context).pop();
            Navigator.of(context).pushNamed(routeName);
          });
        },
      );
    }

    var myNavChildren = [
      headerChild,
      getNavItem(Icons.settings, "Settings", SettingsScreen.routename),
      getNavItem(Icons.home, "Home", "/"),
      getNavItem(Icons.account_box, "Account", AccountScreen.routename),
      aboutChild
    ];
    ListView listView = new ListView(children: myNavChildren);
    return new Drawer(child: listView);
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
          title: new Center(
        child: new Text("Navigation Drawer Example"),
      )),
      body: new Container(
        child: new Center(
          child: new Text("Home Screen"),
        ),
      ),
      drawer: getNavDrawer(context),
    );
  }
}

import 'package:flutter/material.dart';

class AccountScreen extends StatelessWidget {
  static const String routename = "/account";
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Center(
          child: new Text("Account"),
        ),
      ),
      body: new Container(
        child: new Center(
          child: new Text("Account Screen"),
        ),
      ),
    );
  }
}

import 'package:flutter/material.dart';

class SettingsScreen extends StatelessWidget {
  static const String routename = "/settings";
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Center(
          child: new Text("Settings"),
        ),
      ),
      body: new Container(
        child: new Center(
          child: new Text("Settings Screen"),
        ),
      ),
    );
  }
}

你可能感兴趣的:(Flutter Example Drawer)