|
@@ -1,14 +1,38 @@
|
|
|
import 'package:flutter/material.dart';
|
|
|
+import 'package:flutter_google_map/pages/tabs/business_page.dart';
|
|
|
+import 'package:flutter_google_map/pages/tabs/home_page.dart';
|
|
|
+import 'package:flutter_google_map/pages/tabs/mine_page.dart';
|
|
|
+import 'package:flutter_google_map/pages/tabs/taxi_page.dart';
|
|
|
|
|
|
class IndexPage extends StatefulWidget {
|
|
|
- const IndexPage({super.key});
|
|
|
+ int pageIndex;
|
|
|
+ IndexPage({super.key, this.pageIndex = 0});
|
|
|
|
|
|
@override
|
|
|
State<IndexPage> createState() => _IndexPageState();
|
|
|
}
|
|
|
|
|
|
class _IndexPageState extends State<IndexPage> {
|
|
|
- int index = 0;
|
|
|
+ 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 = const [
|
|
|
+ HomePage(),
|
|
|
+ BusinessPage(),
|
|
|
+ TaxiPage(),
|
|
|
+ MinePage(),
|
|
|
+ ];
|
|
|
+
|
|
|
+ int currentIndex = 0;
|
|
|
+
|
|
|
+ Size get size => MediaQuery.of(context).size;
|
|
|
+
|
|
|
+ final pageController = PageController();
|
|
|
+
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
return Scaffold(
|
|
@@ -16,12 +40,17 @@ class _IndexPageState extends State<IndexPage> {
|
|
|
title: const Text('Maps Sample App'),
|
|
|
backgroundColor: Colors.green[700],
|
|
|
),
|
|
|
- bottomNavigationBar: BottomNavigationBar(items: [
|
|
|
- BottomNavigationBarItem(icon: Icon(Icons.home), label: '出行'),
|
|
|
- BottomNavigationBarItem(icon: Icon(Icons.business), label: '周边惠'),
|
|
|
- BottomNavigationBarItem(icon: Icon(Icons.school), label: '打车'),
|
|
|
- BottomNavigationBarItem(icon: Icon(Icons.school), label: '我的'),
|
|
|
- ]),
|
|
|
+ bottomNavigationBar: BottomNavigationBar(
|
|
|
+ items: bottomTabs,
|
|
|
+ currentIndex: currentIndex,
|
|
|
+ type: BottomNavigationBarType.fixed,
|
|
|
+ onTap: (index) {
|
|
|
+ setState(() {
|
|
|
+ currentIndex = index;
|
|
|
+ pageController.jumpToPage(index);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ ),
|
|
|
drawer: Drawer(
|
|
|
child: ListView(
|
|
|
padding: EdgeInsets.zero,
|
|
@@ -47,11 +76,23 @@ class _IndexPageState extends State<IndexPage> {
|
|
|
],
|
|
|
),
|
|
|
),
|
|
|
- body: buildContent(index),
|
|
|
+ body: _getPageBody(context),
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- buildContent(int index) {
|
|
|
- return Placeholder();
|
|
|
+ @override
|
|
|
+ bool get wantKeepAlive => true;
|
|
|
+
|
|
|
+ Widget _getPageBody(BuildContext context) {
|
|
|
+ return PageView(
|
|
|
+ controller: pageController,
|
|
|
+ physics: const NeverScrollableScrollPhysics(),
|
|
|
+ onPageChanged: (index) {
|
|
|
+ setState(() {
|
|
|
+ currentIndex = index;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ children: pages,
|
|
|
+ );
|
|
|
}
|
|
|
}
|