import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_module/FindPage.dart';
import 'HomePage.dart';
/**
* 主页
*/
class MainPage extends StatefulWidget {
@override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
int currentIndex = 0;
var pages = [HomePage(), FindPage()];
List<BottomNavigationBarItem> bottomNavItems = [
BottomNavigationBarItem(
title: Text("首页"),
icon: Icon(Icons.home),
),
BottomNavigationBarItem(
title: Text("发现"),
icon: Icon(Icons.home),
),
];
@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: BottomNavigationBar(
items: bottomNavItems,
currentIndex: currentIndex,
onTap: (index) {
_changePage(index);
},
),
body: pages[currentIndex],
);
}
/*切换页面*/
void _changePage(int index) {
if (index != currentIndex) {
setState(() {
currentIndex = index;
});
}
}
}