12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import 'package:flutter/material.dart';
- import 'package:gobang/pages/home_page.dart';
- import 'package:gobang/pages/mine_page.dart';
- /// Description: index page
- /// Time : 02/21/2024 Wednesday
- /// Author : liuyuqi.gov@msn.cn
- class IndexPage extends StatefulWidget {
- const IndexPage({Key? key}) : super(key: key);
- @override
- State<IndexPage> createState() => _IndexPageState();
- }
- class _IndexPageState extends State<IndexPage> {
- final List<BottomNavigationBarItem> bottomTabs = const [
- BottomNavigationBarItem(icon: Icon(Icons.home), label: '出行'),
- BottomNavigationBarItem(icon: Icon(Icons.business), label: '大厅'),
- BottomNavigationBarItem(icon: Icon(Icons.school), label: '消息'),
- BottomNavigationBarItem(icon: Icon(Icons.school), label: '我的'),
- ];
- final List<Widget> pages = [
- HomePage(),
- MinePage(),
- ];
- int currentIndex = 0;
- Size get size => MediaQuery.of(context).size;
- final pageController = PageController();
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- actions: [Icon(Icons.search)],
- title: Text("gobang"),
- ),
- // drawer: ,
- bottomNavigationBar: BottomNavigationBar(
- items: bottomTabs,
- currentIndex: currentIndex,
- type: BottomNavigationBarType.fixed,
- onTap: (index) {
- setState(() {
- currentIndex = index;
- pageController.jumpToPage(index);
- });
- },
- ),
- body: _getPageBody(context),
- );
- }
- _getPageBody(BuildContext context) {
- return PageView(
- controller: pageController,
- physics: const NeverScrollableScrollPhysics(),
- onPageChanged: (index) {
- setState(() {
- currentIndex = index;
- });
- },
- children: pages,
- );
- }
- }
|