class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { return new MaterialApp( title: 'Flutter Demo', theme: new ThemeData( primarySwatch: themeColor(), ), home: new MyHomePage(title: 'Flutter Demo Home Page'), ); }}
class _MyHomePageState extends State<MyHomePage> { PageController pageController; int page = 0; @override Widget build(BuildContext context) { return new Scaffold( backgroundColor: Colors.grey, body: new PageView( children: [ new Index(), new Classify(), new Shopping(), new Myself() ], controller: pageController, onPageChanged: onPageChanged ), bottomNavigationBar: new BottomNavigationBar(items: [ new BottomNavigationBarItem( icon: new Icon(Icons.laptop_chromebook), title: new Text("主页"), backgroundColor: Colors.grey ), new BottomNavigationBarItem( icon: new Icon(Icons.list), title: new Text("分类"),backgroundColor: Colors.grey), new BottomNavigationBarItem( icon: new Icon(Icons.local_grocery_store), title: new Text("购物车")), new BottomNavigationBarItem(icon: new Icon(Icons.person), title: new Text("我的")) ], onTap: onTap, currentIndex: page ), ); } @override void initState() { super.initState(); pageController = new PageController(initialPage: this.page); } void onTap(int index) { pageController.animateToPage( index, duration: const Duration(milliseconds: 300), curve: Curves.ease); } void onPageChanged(int page) { setState(() { this.page = page; }); }}
import 'package:flutter/material.dart';class Classify extends StatelessWidget { @override Widget build(BuildContext context) { // TODO: implement build return new Scaffold( body: new Center( child: new Text("分类"), ), ); }}