import 'package:flutter/material.dart';
import 'package:app03/pages/home/HomePage.dart';
import 'package:app03/pages/category/CategoryPage.dart';
import 'package:app03/pages/settings/SettingsPage.dart';
class TabsPage extends StatefulWidget {
final int index;
TabsPage({Key key, this.index = 0}) : super(key: key);
@override
_TabsPageState createState() => _TabsPageState(this.index);
}
class _TabsPageState extends State<TabsPage> {
int currentIndex = 0;
_TabsPageState(index) {
this.currentIndex = index;
}
List listTabs = [
HomePage(),
CategoryPage(),
SettingsPage(),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('flutter 标题'),
centerTitle: true,
backgroundColor: Colors.pink,
leading: IconButton(
icon: Icon(Icons.menu),
onPressed: () {
print('menu');
},
),
actions: <Widget>[
IconButton(
icon: Icon(Icons.search),
onPressed: () {
print('search');
},
),
IconButton(
icon: Icon(Icons.settings),
onPressed: () {
print('settings');
},
)
],
),
body: this.listTabs[this.currentIndex],
bottomNavigationBar: BottomNavigationBar(
currentIndex: this.currentIndex,
iconSize: 30.0,
type: BottomNavigationBarType.fixed,
onTap: (index) {
setState(() {
this.currentIndex = index;
});
},
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('首页'),
),
BottomNavigationBarItem(
icon: Icon(Icons.category),
title: Text('分类'),
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
title: Text('设置'),
),
],
),
);
}
}
效果
网友评论